Retry

Review retry settings and why invalid model IDs cannot reliably exercise the retry path.

This example assumes an invalid model ID triggers the configured retries. Invalid-model responses commonly use terminal 400 or 404 statuses, which Agno does not retry. Do not run this source as a retry test. The current adapter also has a default URL ending in chat/completions; the inherited SDK appends the same suffix again. Use the explicit API root below.

retry.py
"""Example demonstrating how to set up retries with InternLM."""

from agno.agent import Agent
from agno.models.internlm import InternLM

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "internlm-wrong-id"

agent = Agent(
    model=InternLM(
        id=wrong_model_id,
        retries=3,  # Number of times to retry the request.
        delay_between_retries=1,  # Delay between retries in seconds.
        exponential_backoff=True,  # If True, the delay between retries is doubled each time.
    ),
)

agent.print_response("What is the capital of France?")

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Current Alternative

Install agno openai in a virtual environment and export INTERNLM_API_KEY with your provider token. Use the root URL and model from the current InternLM Chat API guide:

from agno.agent import Agent
from agno.models.internlm import InternLM

agent = Agent(
    model=InternLM(
        id="intern-latest",
        base_url="https://chat.intern-ai.org.cn/api/v1/",
        retries=2,
        delay_between_retries=1,
        exponential_backoff=True,
    )
)
agent.print_response("What is the capital of France?")

Save this alternative as internlm_retry.py and run python internlm_retry.py. Test recovery with a controlled transient failure, using a valid token and model.

Full source: cookbook/90_models/internlm/retry.py