magentic icon indicating copy to clipboard operation
magentic copied to clipboard

Forcing specific tool use

Open mnicstruwig opened this issue 1 year ago • 1 comments

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!

mnicstruwig avatar Jan 10 '25 08:01 mnicstruwig

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

https://github.com/jackmpcollins/magentic/blob/fd0d03edad0b2b9b685c084f933256bfaba3828e/src/magentic/chat_model/openai_chat_model.py#L423-L434

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.

jackmpcollins avatar Jan 10 '25 18:01 jackmpcollins