如何在LangGraph中配置Anthropic模型禁用并行工具调用
在LangGraph中禁用Anthropic模型的并行工具调用
直接在bind_tools方法中添加disable_parallel_tool_use=True参数即可,该参数会传递给底层的Anthropic Messages API,实现每次仅调用一个工具的效果。
修改后的核心代码如下:
model = ChatAnthropic(model="claude-3-5-sonnet-20241022") tools = [search_word_forms, search_dictionaries, WordDetermination] # 新增参数禁用并行工具调用 model_with_tools = model.bind_tools(tools, tool_choice="any", disable_parallel_tool_use=True) response = model_with_tools.invoke(state["messages"])
这个配置和你直接调用Anthropic Messages API时设置disable_parallel_tool_use=true的作用完全一致,LangChain会将该参数直接注入到API请求中,强制模型每次仅选择一个工具执行。
内容的提问来源于stack exchange,提问作者Laizer
相关产品推荐
相关产品推荐

