Skip to content

fix(langgraph): forward *args/**kwargs through node wrappers to preserve config kwarg#1316

Open
IgnazioDS wants to merge 1 commit intoAgentOps-AI:mainfrom
IgnazioDS:fix/langgraph-node-config-kwarg
Open

fix(langgraph): forward *args/**kwargs through node wrappers to preserve config kwarg#1316
IgnazioDS wants to merge 1 commit intoAgentOps-AI:mainfrom
IgnazioDS:fix/langgraph-node-config-kwarg

Conversation

@IgnazioDS
Copy link
Copy Markdown

Problem

LangGraph node functions may accept a second argument config: RunnableConfig:

from langchain_core.runnables import RunnableConfig

def agent_node(state: AgentState, config: RunnableConfig):
    response = model.invoke(state["messages"], config=config)
    return {"messages": [response]}

When AgentOps instruments the graph via _wrap_add_node, both wrapped_node_async and wrapped_node_sync use a hard-coded (state) signature:

async def wrapped_node_async(state):      # ← only accepts state
    ...
    result = await original_func(state)   # ← drops config

LangGraph calls the node with config=... as a keyword argument, but the wrapper doesn't accept it, raising:

TypeError: agent_node() got an unexpected keyword argument 'config'

Fix

Change both wrapped_node_async and wrapped_node_sync to (*args, **kwargs) and forward them to the original function:

async def wrapped_node_async(*args, **kwargs):
    state = args[0] if args else kwargs.get("state")
    ...
    result = await original_func(*args, **kwargs)  # forwards config and anything else

This is transparent — nodes that only accept state continue to work exactly as before. Nodes that also accept config (or any future LangGraph-injected arguments) now work correctly.

Fixes #1295

Test plan

  • Node function with def agent_node(state, config: RunnableConfig) no longer raises TypeError when AgentOps is active
  • Standard def agent_node(state) nodes continue to work normally
  • Async node variants work the same way

…rve config kwarg

LangGraph node functions may accept a second argument: config: RunnableConfig.
The node wrappers in _wrap_add_node used fixed (state,) signatures, which caused
LangGraph to call the wrapped function with config= and receive:

  TypeError: agent_node() got an unexpected keyword argument 'config'

Fix: change both wrapped_node_async and wrapped_node_sync to use *args, **kwargs
so any additional arguments passed by the LangGraph runtime are transparently
forwarded to the original node function.

Fixes AgentOps-AI#1295
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.

[Bug]:The error "unexpected keyword argument 'config'" occurred when integrating langgraph

1 participant