microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
30.69k stars 4.47k forks source link

[Issue]: How to force implementing a tool function registered for an agent? #3354

Open nancycsecon opened 3 weeks ago

nancycsecon commented 3 weeks ago

Describe the issue

I registered a tool function to an agent which searches from a database. Now I want the tool function be called every time the agent speaks. Now the agent sometimes bypass calling the tool and would hallucinate answers. Is there any workaround to fix this?

Steps to reproduce

No response

Screenshots and logs

No response

Additional Information

No response

spullara commented 3 weeks ago

Right now this isn't supported in the OAI client but it looks like it might be supported for Anthropic and Mistral. You would need to modify this: https://github.com/microsoft/autogen/blob/08fa1b6d080a99daccaebd0390fc3c7cd91f05e6/autogen/oai/client.py#L294

So that it adds a "tool_choice" parameter.

marklysze commented 3 weeks ago

Hey @nancycsecon, in relation to @spullara's point, can you let us know what provider/model you are using?

If you had an example that may help, it could possibly also help to do further prompt tweaking.

imjimmeh commented 3 weeks ago

Can you add a new hook to process_last_received_message, or process_all_messages_before_reply?

Or register a new reply function that calls the database and then returns the result of generate_oai_reply?

It seems like there's little point trying to keep it as a tool at this point, and the above would be more appropriate for your use case