create_react_agent lost configuration on casting for bind tools #606

Closed
opened 2026-02-20 17:40:56 -05:00 by yindo · 1 comment
Owner

Originally created by @ericmagalhaes on GitHub (Apr 29, 2025).

Originally assigned to: @vbarda on GitHub.

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

llm = ChatOpenAI(model="").configurable_fields(
    model_name=ConfigurableField(id="app_model"),
    openai_api_base=ConfigurableField(id="app_base_url"),
    openai_api_key=ConfigurableField(id="app_key"))


graph = create_react_agent(
    llm, 
    tools=tools,
    prompt=system_prompt,
    checkpointer=checkpointer)

** chat_agent_executor.py **
line: 690
if _should_bind_tools(model, tool_classes) and tool_calling_enabled:
        model = cast(BaseChatModel, model).bind_tools(tool_classes)

Error Message and Stack Trace (if applicable)

after model cast() configurable fields are lost

data: {"error": "Error code: 400 - {'error': {'message': {'error': '/chat/completions: Invalid model name passed in model=gpt-3.5-turbo'}, 'type': 'None', 'param': 'None', 'code': '400'}}"}

Description

  • Using langgraph 0.3.31

...
async for msg, metadata in graph.astream(
{"messages": [("user", request.input.query)], "app_id": request.input.app_id},
config={
"configurable": {
"thread_id": request.config.thread_id,
"app_model": model_name,
"app_base_url": base_api,
"app_key": app_key,
}
},
stream_mode="messages"
):
...

System Info

wsl-ubuntu

Originally created by @ericmagalhaes on GitHub (Apr 29, 2025). Originally assigned to: @vbarda on GitHub. ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python llm = ChatOpenAI(model="").configurable_fields( model_name=ConfigurableField(id="app_model"), openai_api_base=ConfigurableField(id="app_base_url"), openai_api_key=ConfigurableField(id="app_key")) graph = create_react_agent( llm, tools=tools, prompt=system_prompt, checkpointer=checkpointer) ** chat_agent_executor.py ** line: 690 if _should_bind_tools(model, tool_classes) and tool_calling_enabled: model = cast(BaseChatModel, model).bind_tools(tool_classes) ``` ### Error Message and Stack Trace (if applicable) ```shell after model cast() configurable fields are lost data: {"error": "Error code: 400 - {'error': {'message': {'error': '/chat/completions: Invalid model name passed in model=gpt-3.5-turbo'}, 'type': 'None', 'param': 'None', 'code': '400'}}"} ``` ### Description * Using langgraph 0.3.31 ... async for msg, metadata in graph.astream( {"messages": [("user", request.input.query)], "app_id": request.input.app_id}, config={ "configurable": { "thread_id": request.config.thread_id, "app_model": model_name, "app_base_url": base_api, "app_key": app_key, } }, stream_mode="messages" ): ... ### System Info wsl-ubuntu
yindo closed this issue 2026-02-20 17:40:56 -05:00
Author
Owner

@vbarda commented on GitHub (Apr 30, 2025):

Unfortunately this is a limitation of ChatModel interface and is not related to the langgraph implementation specifically.
You can work around this by using init_chat_model. Note that you will need to use the actual parameter names in configurable_fields, not aliases. Here is a small example:

from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

llm = init_chat_model("openai:gpt-4.1-nano", configurable_fields=("model",))
agent = create_react_agent(llm, [add])
agent.invoke({"messages": "what's 2 + 3?"}, config={"configurable": {"model": "gpt-4.1-mini"}})

https://python.langchain.com/docs/how_to/configure/#configuring-fields-on-a-chat-model

@vbarda commented on GitHub (Apr 30, 2025): Unfortunately this is a limitation of ChatModel interface and is not related to the langgraph implementation specifically. You can work around this by using `init_chat_model`. Note that you will need to use the actual parameter names in `configurable_fields`, not aliases. Here is a small example: ```python from langchain.chat_models import init_chat_model from langgraph.prebuilt import create_react_agent llm = init_chat_model("openai:gpt-4.1-nano", configurable_fields=("model",)) agent = create_react_agent(llm, [add]) agent.invoke({"messages": "what's 2 + 3?"}, config={"configurable": {"model": "gpt-4.1-mini"}}) ``` https://python.langchain.com/docs/how_to/configure/#configuring-fields-on-a-chat-model
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#606