microsoft/autogen · error · ValueError
Run failed: {run.last_error}
Error message
Run failed: {run.last_error} What it means
While polling a run on the Assistants API thread, OpenAIAssistantAgent checks run.status each iteration; a terminal status of 'failed' (server-side failure: expired run, model error, rate/quota issues, bad tool definitions) triggers this ValueError carrying run.last_error from OpenAI. The agent surfaces the API's own error detail rather than retrying.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/agents/openai/_openai_assistant_agent.py:438
thread_id=self._thread_id,
assistant_id=self._get_assistant_id,
)
)
)
# Wait for run completion by polling
while True:
run = await cancellation_token.link_future(
asyncio.ensure_future(
self._client.beta.threads.runs.retrieve( # type: ignore[reportDeprecated]
thread_id=self._thread_id,
run_id=run.id,
)
)
)
if run.status == "failed":
raise ValueError(f"Run failed: {run.last_error}")
# If the run requires action (function calls), execute tools and continue
if run.status == "requires_action" and run.required_action is not None:
tool_calls: List[FunctionCall] = []
for required_tool_call in run.required_action.submit_tool_outputs.tool_calls:
if required_tool_call.type == "function":
tool_calls.append(
FunctionCall(
id=required_tool_call.id,
name=required_tool_call.function.name,
arguments=required_tool_call.function.arguments,
)
)
# Add tool call message to inner messages
tool_call_msg = ToolCallRequestEvent(source=self.name, content=tool_calls)
inner_messages.append(tool_call_msg)
event_logger.debug(tool_call_msg)View on GitHub (pinned to 027ecf0a37)
Solutions
- Read run.last_error in the message — it contains OpenAI's error code/message (e.g. rate_limit_exceeded, invalid_model) and points at the true cause.
- For quota/rate errors: wait and retry the on_messages call (the thread is preserved; new input starts a new run).
- For invalid_model: update the assistant to a current model via client.beta.assistants.update.
- For expired runs: shorten tool execution time or raise the run's expiration when creating it.
Example fix
# before
resp = await agent.on_messages([TextMessage(source="user", content="hi")], ct)
# after
try:
resp = await agent.on_messages([TextMessage(source="user", content="hi")], ct)
except ValueError as e:
if "Run failed" in str(e):
print("OpenAI run error:", e) # inspect run.last_error detail
await asyncio.sleep(30)
resp = await agent.on_messages([TextMessage(source="user", content="hi")], ct) Defensive patterns
Strategy: retry
Try / catch
try:
resp = await agent.on_messages(msgs, ct)
except ValueError as e:
if "Run failed" not in str(e):
raise
detail = str(e)
if "rate" in detail.lower() or "quota" in detail.lower():
await asyncio.sleep(30)
resp = await agent.on_messages(msgs, ct)
else:
raise Prevention
- Always surface run.last_error — it carries OpenAI's real failure code.
- Keep the assistant's model current and billing/quota healthy.
- Bound tool execution time to avoid run expiry.
When it happens
Trigger: Any assistant run whose status becomes 'failed': invalid/inaccessible model, insufficient quota, run timeout/expiry (runs have a server-side time limit), malformed tool definitions, or content-policy failures.
Common situations: Using a deprecated model name on the assistant; hitting OpenAI rate limits or zero billing quota; long tool executions causing run expiry; stale vector stores or file references used by file_search.
Related errors
- Incorrect client passed to OpenAIAssistantAgent. Please use
- Unsupported tool type: {type(tool)}
- Assistant not initialized
- No tools are available.
- The tool '{tool_call.name}' is not available.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/9976c8c6ec12c66a.
Report an issue: GitHub.