crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[Reopen] AgentExecutor async path still routes through LLM.call

Open suqinghen opened this issue 2 months ago • 4 comments

Summary

Issue #6683 was previously closed by inactivity, but the behavior is still present and impacts async pipelines.

In AgentExecutor.ainvoke()/run_async flow, LLM calls are routed through the shared synchronous path (get_llm_response()), even when the provider implements an async path (LLM.acall() / aget_llm_response()).

As a result, async workloads can be constrained by thread-pool capacity and lose the expected async execution benefits.

Current behavior

  • AgentExecutor methods call_llm_and_parse and call_llm_native_tools call get_llm_response().
  • get_llm_response() invokes LLM.call().
  • LLM.call() uses sync execution path, requiring threadpool offload for providers that are actually async-capable.

Expected behavior

  • Async execution paths should use aget_llm_response() and LLM.acall() when available.
  • Preserve compatibility for custom LLMs that only implement sync behavior by falling back to asyncio.to_thread(...) only on NotImplementedError.

Suggested fix

  1. Convert the two router methods to async and await aget_llm_response().
  2. In aget_llm_response(), implement narrow fallback:
    • try async path first
    • on NotImplementedError, delegate to asyncio.to_thread(llm.call, ...) (or equivalent)
  3. Keep sync behavior unchanged for non-async contexts.

Repro (minimal)

  1. Create a custom LLM double that records calls for both call() and acall().
  2. Attach it to an Agent and invoke await agent.kickoff_async("probe").
  3. Validate that acall() is invoked when available.

If needed, I can provide a tiny regression test draft.

Context

This is a re-open-style report derived from #6683 and current source inspection.

suqinghen avatar Sep 08 '26 10:09 suqinghen

Hi, I'd like to work on this. Happy to take it if unassigned.

stud925 avatar Sep 08 '26 12:09 stud925

Sounds good, @stud925 assigning this to you.

Vidit-Ostwal avatar Sep 08 '26 14:09 Vidit-Ostwal

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 25 '26 12:10 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Oct 31 '26 12:10 github-actions[bot]