How to Fix 'timeout error' in AutoGen (Python)
If you’re seeing timeout error in AutoGen, it usually means one of the agent calls, tool calls, or model requests took longer than the configured timeout window. In practice, this shows up when an LLM response is slow, a tool hangs, or your agent loop keeps waiting for a reply that never arrives.
The key thing: this is usually not an AutoGen bug. It’s almost always a timeout mismatch between your code, the model provider, and any external tools you attached.
The Most Common Cause
The #1 cause is a timeout that’s too short for the work your agent is doing. This happens a lot when using AssistantAgent, UserProxyAgent, or GroupChatManager with slow tools, long prompts, or models that take time to respond.
Here’s the broken pattern versus the fixed pattern:
| Broken | Fixed |
|---|---|
| Timeout left at default or set too low | Timeout increased to match real latency |
| Tool call can block indefinitely | Tool call has explicit timeout handling |
| No retry/backoff | Retry on transient provider latency |
# Broken
from autogen import AssistantAgent, UserProxyAgent
assistant = AssistantAgent(
name="assistant",
llm_config={
"config_list": [{"model": "gpt-4o-mini", "api_key": "YOUR_KEY"}],
"timeout": 10, # too aggressive for real workloads
},
)
user_proxy = UserProxyAgent(
name="user",
human_input_mode="NEVER",
)
user_proxy.initiate_chat(assistant, message="Summarize this 20-page contract.")
# Fixed
from autogen import AssistantAgent, UserProxyAgent
assistant = AssistantAgent(
name="assistant",
llm_config={
"config_list": [{"model": "gpt-4o-mini", "api_key": "YOUR_KEY"}],
"timeout": 120,
"temperature": 0,
},
)
user_proxy = UserProxyAgent(
name="user",
human_input_mode="NEVER",
)
user_proxy.initiate_chat(assistant, message="Summarize this 20-page contract.")
If you’re using AutoGen with tool execution, also check the tool itself. A Python function that waits on a database query or HTTP request can trigger errors like:
- •
TimeoutError - •
openai.APITimeoutError - •
autogen.exceptions.TimeoutError - •
Request timed out
That means the failure may be in your tool code, not the agent framework.
Other Possible Causes
1. Your tool function blocks too long
A common pattern is wrapping slow I/O inside a registered function without any timeout guard.
def fetch_policy_data(policy_id: str):
import requests
return requests.get(f"https://api.internal/policies/{policy_id}").json()
Fix it with an explicit request timeout:
def fetch_policy_data(policy_id: str):
import requests
resp = requests.get(
f"https://api.internal/policies/{policy_id}",
timeout=15,
)
resp.raise_for_status()
return resp.json()
2. Your conversation loop is too large
If you keep appending messages forever in GroupChat, token growth slows every request and increases latency.
from autogen import GroupChat
groupchat = GroupChat(
agents=[...],
messages=[],
max_round=50, # can get expensive fast
)
Reduce rounds and trim context:
groupchat = GroupChat(
agents=[...],
messages=[],
max_round=10,
)
Also consider summarizing history before continuing.
3. Model/provider latency is higher than expected
Some models are slower under load. If your config points to a high-latency deployment, AutoGen will wait until the request times out.
llm_config = {
"config_list": [{
"model": "gpt-4o",
"api_key": "YOUR_KEY"
}],
"timeout": 30,
}
Try a faster model or increase timeout:
llm_config = {
"config_list": [{
"model": "gpt-4o-mini",
"api_key": "YOUR_KEY"
}],
"timeout": 120,
}
4. Network/proxy issues are delaying requests
In enterprise setups, proxies and TLS inspection often add delay. You’ll see timeouts even though your code looks fine.
Check environment variables like these:
HTTPS_PROXY=http://proxy.internal:8080
HTTP_PROXY=http://proxy.internal:8080
NO_PROXY=localhost,127.0.0.1
If proxy routing is broken, the request may hang until AutoGen gives up.
How to Debug It
- •
Reproduce with the smallest possible prompt
- •Use a one-line message.
- •Remove tools.
- •Remove group chat.
- •If it works there, the issue is in your tool chain or prompt size.
- •
Print timing around every agent call
import time start = time.time() user_proxy.initiate_chat(assistant, message="Ping") print("elapsed:", time.time() - start)If the call always dies around the same second mark, it’s your configured timeout.
- •
Test tools outside AutoGen
- •Run the function directly.
- •Add logging before and after each network call.
- •If
requests.get(..., timeout=15)still hangs, fix the downstream service first.
- •
Inspect exception type and stack trace Look for:
- •
TimeoutError - •
openai.APITimeoutError - •
requests.exceptions.Timeout - •
asyncio.TimeoutError
The exception tells you whether this is model latency, HTTP I/O, or async scheduling.
- •
Prevention
- •Set explicit timeouts everywhere:
- •LLM config timeout
- •HTTP client timeout
- •DB query timeout
- •Keep agent context small:
- •summarize old turns
- •cap group chat rounds
- •avoid dumping huge documents into every prompt
- •Add retries for transient failures:
- •retry model calls on timeout once or twice
- •don’t retry endlessly on deterministic failures
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit