microsoft / autogen

A programming framework for agentic AI šŸ¤–
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
31.45k stars 4.58k forks source link

Function to indicate whether to hide tools for client_utils #2966

Closed marklysze closed 3 months ago

marklysze commented 3 months ago

Primarily to support non-OpenAI client classes, this new function in the client_utils is used to determine whether tools should be hidden from a create request for client classes.

Called should_hide_tools, the function takes in the messages, tools, and a condition string (which can be 'if_all_run', 'if_any_run', and 'never'). The function returns True if the tools should be hidden based on the condition string and messages/tools, and False otherwise.

I have found that it's a useful function to have to help non-OpenAI models to avoid calling tools once they have already called them.

This will be used in the Together.AI PR, #2919. Anthropic, #2931, will likely be updated as well.

The upcoming blog post, #2965 will require this.

Related issue number

2919, #2931, #2965

Checks

Josephrp commented 3 months ago

interesting insight !

it might really be worthwhile to make a small notebook / notebook section in either together or anthropic to demonstrate this new and unique functionality šŸ‘šŸ»

marklysze commented 3 months ago

interesting insight !

it might really be worthwhile to make a small notebook / notebook section in either together or anthropic to demonstrate this new and unique functionality šŸ‘šŸ»

Yes, I've added it to the Together.AI notebook example and highlighted it :)... Just working on finalising that PR now to convert from draft. :)

scruffynerf commented 3 months ago

Interesting... I just did the opposite: to add tools support to models/apis that don't support them. I will see how you are doing this, and try to support it in how I finally implement.

workflow of toolless tools
marklysze commented 3 months ago

Interesting... I just did the opposite: to add tools support to models/apis that don't support them. I will see how you are doing this, and try to support it in how I finally implement.

Looks cool, great to have tools for non-tool setups.

I think we've chatted on Discord a bit (I'm msze_), so feel free to chat with me there on this... I can see you're very active there and what you need to do would benefit many people.

scruffynerf commented 3 months ago

Looks really good, but it's possible to have more than one tool call in a message.

if "tool_calls" in message:
                # Register the tool id and the name
                tool_call_ids[message["tool_calls"][0]["id"]] = message["tool_calls"][0]["function"]["name"]

could be a loop thru each, instead of using only the first.

marklysze commented 3 months ago

Looks really good, but it's possible to have more than one tool call in a message.

if "tool_calls" in message:
                # Register the tool id and the name
                tool_call_ids[message["tool_calls"][0]["id"]] = message["tool_calls"][0]["function"]["name"]

could be a loop thru each, instead of using only the first.

Good pickup, you're absolutely right. I'll update this code in the Together.AI or Mistral.AI PR. Thanks!

marklysze commented 3 months ago

Looks really good, but it's possible to have more than one tool call in a message.

if "tool_calls" in message:
                # Register the tool id and the name
                tool_call_ids[message["tool_calls"][0]["id"]] = message["tool_calls"][0]["function"]["name"]

could be a loop thru each, instead of using only the first.

Good pickup, you're absolutely right. I'll update this code in the Together.AI or Mistral.AI PR. Thanks!

Thanks @scruffynerf, I've updated the code in the Mistral.AI PR as I needed to also update the mistral.py to handle multiple tool call recommendations in messages as well. PR #2892.