Force to call a tool #5274
TaQuangTu
started this conversation in
Discussions
Replies: 1 comment 2 replies
-
See this section in the docs: https://langchain-ai.github.io/langgraph/how-tos/tool-calling/#force-tool-use from langchain_core.tools import tool
# highlight-next-line
@tool(return_direct=True)
def greet(user_name: str) -> int:
"""Greet user."""
return f"Hello {user_name}!"
tools = [greet]
agent = create_react_agent(
# highlight-next-line
model=model.bind_tools(tools, tool_choice={"type": "tool", "name": "greet"}),
tools=tools
)
agent.invoke(
{"messages": [{"role": "user", "content": "Hi, I am Bob"}]}
) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Lang-graph developers, you are doing a great project!
I want to discuss about how to force a graph to always call a tool before invoking any other tool based on the context.
In our current implementation, when creating an agent with
create_react_agent
function, I'm noticed that there is no option for us to specifytool_choice
parameter, hence cannot achieve that expected behavior. Is there any reason preventing us from implementing it or is there another way to achieve it?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions