autogen icon indicating copy to clipboard operation
autogen copied to clipboard

[Feature Request]: Dynamically removing tools during agent conversation when the tools are not needed or not useful.

Open WebsheetPlugin opened this issue 1 year ago • 6 comments

Is your feature request related to a problem? Please describe.

To save tokens or improve GPT responses, it makes sense to remove certain tools when they are no longer needed.

Describe the solution you'd like

autogen.agentchat.unregister_function( hello_world, caller=picker, executor=picker )

Additional context

No response

WebsheetPlugin avatar May 11 '24 22:05 WebsheetPlugin

Can you please provide an example scenario where this will be useful?

Gr3atWh173 avatar May 12 '24 16:05 Gr3atWh173

Sure, I use this in my other chatbot all the time. Let's say you have diferent tools available for the Agent to choose from, but when a tool fails, because it's impossible to execute, you might want to remove it, save tokens, and let the Agent use other tools instead to complete the job.

Another example is simply removing tools to save tokens. Very often you can assume that certain tools will not be needed when other tools have been already picked. For example, if the Agent picked a weather_info tool, then you can assume that the stock_info tool might be not needed. So you remove it.

WebsheetPlugin avatar May 12 '24 17:05 WebsheetPlugin

Some observations:

  1. there is method update_tool_signature which even has "is_remove" flag. But it seems removing the function only from llm_config["tools"] but from function_map

I am not sure this is an issue for execution..

I was able to acomplish this feature myself with this code:

def remove_tool(agent, tool_name):
    """Remove tool from the tool list"""
    tools = agent.llm_config.get("tools")
    tools = [tool for tool in tools if tool.get("function", {}).get("name") != tool_name]
    agent.llm_config["tools"] = tools
    map_ =  agent._function_map
    del map_[tool_name]

WebsheetPlugin avatar May 25 '24 15:05 WebsheetPlugin

+1 for this feature request

In my use case, each function correspond to an action that the agent could perform.

As the agent interact with the world,

  • new actions become available -> register_function
  • old actions could be no longer possible -> unregister_function (but no such thing in autogen)

Example: LLM agent was put to play a text based adventure game

Agent is first at the pub: functions it can call:

  • walk
  • talk
  • drink

Agent now walks to forest: functions it can call:

  • walk
  • ~talk~
  • ~drink~
  • chop

ylchan87 avatar Jun 09 '24 06:06 ylchan87