Skip to content
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

Tool Call Improvements #71

Merged
merged 12 commits into from
Feb 17, 2025
Merged

Tool Call Improvements #71

merged 12 commits into from
Feb 17, 2025

Conversation

wendy-aw
Copy link
Contributor

Changes

1. tool_choice schema

Removed pydantic schema for tool_choice. OpenAI and Anthropic have very different inputs for this parameter.

Feature OpenAI Anthropic
Zero or more tools called auto {"type": "auto"}
At least one tool must be called required {"type": "any"}
Specific tool called {"type": "function", "function": {"name": function_name}} {"type": "tool", "name": function_name}

We hence simplify things by allowing the input to the chat functions to be simple strings like "auto", "required", "function_name". convert_tool_choice function will then map these to the right formats above for the different models. Also if tools are listed but tool_choice is not set, we default to "auto".

2. Avoid looping with required tool_choice

Previously if tool_choice was set to required, tool chaining would force the model to use a tool in each round. This will continue indefinitely and would not end with a message. We fix this by setting tool_choice to be auto after the first tool call.

3. tool_outputs in LLMResponse

We output the intermediate tool outputs during tool chaining so that we can inspect the steps the model has taken.

4. New tests

We port the tests for tool calls from defog_utils. However, we retain get_weather tests and do away with the web_search tests so that we do not require a defog API key. Other tests have also been added to cases where tool_choice is required or a forced function. Anthropic tests now also use sonnet instead of haiku as it's more reliable.

@wendy-aw wendy-aw requested a review from rishsriv February 17, 2025 09:47
Copy link
Member

@rishsriv rishsriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Thank you for documenting this so thoroughly, and for the added tests. Returning results from tool use is super helpful!

@rishsriv rishsriv merged commit 3800e53 into main Feb 17, 2025
2 checks passed
@rishsriv rishsriv deleted the wendy/move_tools branch February 17, 2025 09:51
Copy link
Collaborator

@wongjingping wongjingping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very neat, thanks for adding the rigorous battery of tests!

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.

3 participants