-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to force use tool and send the result to llm? #281
Comments
HI, this new part of the documentation may help you. It explains how to deal with it. Moreover, there's also an example. |
I wrote the code with reference to this example. If I set tool_choise='required' and use the custom custom_tool_use_behavior, async def custom_tool_use_behavior(
context: RunContextWrapper[Any], results: list[FunctionToolResult]
) -> ToolsToFinalOutputResult:
data: str = results[0].output
# print(f"data:{data}")
return ToolsToFinalOutputResult(
is_final_output=True,final_output="Hello"
)
book_agent = Agent(
name="Book Agent",
instructions="""
You are a professional book content consultant. Your tasks are:
1. You must use the search_book_content tool to search for relevant content
2. Answer the user's question based on the search results
3. If the search results are not sufficient to answer the question, make it clear
""",
tools=[search_book_content],
model=OpenAIChatCompletionsModel(
model="gpt-4o-mini-2024-07-18",
openai_client=openai_client,
),
tool_use_behavior=custom_tool_use_behavior,
model_settings=ModelSettings(temperature=0.7,max_tokens=8192, tool_choice='required'),
hooks=CustomAgentHooks(display_name="Book Agent")
) |
question
I hope that when calling the book agent, the tool of this agent must be called and the result of the tool must be sent to the LLM. The code below to execute. Sometimes the book agent does not execute the tool. If the tool_choise is set to 'required', it will fall into an infinite loop. If it is set to None, the tool may not be executed. How can I solve this problem?
The text was updated successfully, but these errors were encountered: