retry.py
"""Example demonstrating how to set up retries with Azure AI Foundry."""
from agno.agent import Agent
from agno.models.azure import AzureAIFoundry
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# We will use a deliberately wrong model ID, to trigger retries.
wrong_model_id = "azure-wrong-id"
agent = Agent(
model=AzureAIFoundry(
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
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno aiohttp azure-ai-inference
3
Export environment variables
export AZURE_API_KEY="your_azure_api_key_here"
export AZURE_ENDPOINT="your_azure_endpoint_here"
$Env:AZURE_API_KEY="your_azure_api_key_here"
$Env:AZURE_ENDPOINT="your_azure_endpoint_here"
4
Run the example
Save the code above as
retry.py, then run:python retry.py