AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Agent Model Nodes In Factory.Py Fail To Propagate RunnableConfig To Model_.Ainvoke, Breaking Callback Propagation

In langchain/agents/factory.py, async model nodes do not receive or forward the RunnableConfig (including callbacks) to the underlying model_.ainvoke, causing callback handlers attached via config to be silently dropped during agent LLM calls. This breaks tracing, observability, and custom middleware.

highConfidence 95%LangchainAgentsVector StoresAffected V0.3.x

Origin Analysis

Model node functions `_execute_model_async` and `amodel_node` do not declare a `config` parameter and do not pass it to `model_.ainvoke`. In LangGraph, node functions can accept a second argument `config: RunnableConfig`, but the current implementation only passes `**kwargs`, so callback handlers stored in config are never propagated to the model invocation.
1. Define a mock model with an async `ainvoke` method that checks if `config` is passed. 2. Create a ReAct agent using `create_react_agent` with this model. 3. Create a `TestCallbackHandler` instance and pass it via `config={'callbacks': [handler]}`. 4. Invoke the agent asynchronously with `agent.ainvoke(input, config=config)`. 5. Observe that the model's `ainvoke` is called without `config`, and the callback handler's `on_llm_start` is never triggered.

Fixing Code Block

Edge Case Audit

Border audit: The proposed change assumes that `model_.ainvoke` accepts a `config` keyword argument. If a custom model wrapper does not support `config`, this fix may raise a TypeError. Ensure compatibility by checking model signature or using `model_.ainvoke(messages, config=config, **kwargs)` only if config is not None. Additionally, other internal call sites of `_execute_model_async` or `amodel_node` may rely on positional arguments; verify all callers are updated accordingly. In concurrent or multi-threaded environments, ensure that the config object is not mutated or shared improperly (callbacks should be thread-safe). Before rolling back, revert both the signature changes and any call sites to avoid inconsistent state. Cross-version compatibility: LangGraph versions <0.2.23 may not pass config to nodes with `**kwargs`; upgrade LangGraph to a version that supports config injection in nodes.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state