Skip to content

Add async fallback support for missing LLM attributes in LlamaIndex #282

Open
shuningc wants to merge 3 commits intomainfrom
HYBIM-620-async-fallbacks
Open

Add async fallback support for missing LLM attributes in LlamaIndex #282
shuningc wants to merge 3 commits intomainfrom
HYBIM-620-async-fallbacks

Conversation

@shuningc
Copy link
Copy Markdown
Contributor

In async agent flows (ReActAgent using astream_chat), LlamaIndex stores tool definitions on the Agent object rather than in the LLM callback payload. The ContextVar tracking the current agent may not propagate across asyncio.Task boundaries, so multiple fallback strategies are needed.

Changes:

  • Extract tool_definitions from agent context with fallback chain: serialized payload -> parent agent ContextVar -> find_agent_with_tools()
  • Extract response_model from raw response with fallback to request model
  • Extract finish_reasons from raw response choices
  • Add max_tokens fallback chain (serialized -> metadata -> Settings.llm)
  • Detect provider from LLM class name
  • Register agent + tools in wrap_agent_run() before wrapped() is called
  • Add find_agent_with_tools() to search shared dict when ContextVar fails

Parent PR #274

…gent flows

In async agent flows (ReActAgent using astream_chat), LlamaIndex stores tool
definitions on the Agent object rather than in the LLM callback payload. The
ContextVar tracking the current agent may not propagate across asyncio.Task
boundaries, so multiple fallback strategies are needed.

Changes:
- Extract tool_definitions from agent context with fallback chain:
  serialized payload -> parent agent ContextVar -> find_agent_with_tools()
- Extract response_model from raw response with fallback to request model
- Extract finish_reasons from raw response choices
- Add max_tokens fallback chain (serialized -> metadata -> Settings.llm)
- Detect provider from LLM class name
- Register agent + tools in wrap_agent_run() before wrapped() is called
- Add find_agent_with_tools() to search shared dict when ContextVar fails

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shuningc shuningc requested review from a team as code owners April 20, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants