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

Forcing specific tool use #400

Open
mnicstruwig opened this issue Jan 10, 2025 · 1 comment
Open

Forcing specific tool use #400

mnicstruwig opened this issue Jan 10, 2025 · 1 comment

Comments

@mnicstruwig
Copy link
Contributor

Hi @jackmpcollins, happy new year!

I had a look through the documentation, but couldn't find if there's a way to force the use of a specific tool, eg. using the tool_choice param like here for OpenAI and here for Anthropic.

Is this something that's currently possible with magentic? It's possible I missed it.

Thanks!

@jackmpcollins
Copy link
Owner

Hi @mnicstruwig , currently the tool_choice forces a specific tool if only one function / output type is specified.

@staticmethod
def _get_tool_choice(
*,
tool_schemas: Sequence[BaseFunctionToolSchema[Any]],
output_types: Iterable[type],
) -> ChatCompletionToolChoiceOptionParam | openai.NotGiven:
"""Create the tool choice argument."""
if contains_string_type(output_types):
return openai.NOT_GIVEN
if len(tool_schemas) == 1:
return tool_schemas[0].as_tool_choice()
return "required"

Is your use case to provide multiple tools but still force a specific one to be used? To do this I think the tool_choice param would need to be exposed in the ChatModel.complete method and to Chat.submit and @prompt/@chatprompt.

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

No branches or pull requests

2 participants