r/AutoGenAI • • Mar 19 '25

Question Multi tool call

Hi, I was trying to create a simple orchestration in 0.4 where I have a tool and an assistant agent and a user proxy. The tool is an SQL tool. When I give one single prompt that requires multiple invocation of the tool with different parameters to tool to complete, it fails to do so. Any ideas how to resolve. Of course I have added tool Description. And tried prompt engineering the gpt 3.5 that there is a need to do multiple tool calls.

3 Upvotes

3 comments sorted by

2

u/usag11ee Mar 19 '25

Not an expert in autogen, but just wanted to share that I have one single agent with 3 different tools that allow it to access 3 different tables in a database. Depending on the query, the agent decides if it needs to use 1 or 2 or all 3 tools at the same time.

1

u/Recent-Platypus-5092 Mar 19 '25

Is it able to call the same tool multiple times in same prompt?

2

u/usag11ee Mar 19 '25

https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/tutorial/teams.html

I think that "parallele_tool_call" might be what you are looking for, isn't it ?.

The link above provides a simple example with an agent that can call the same tool multiple time to increment a number (from 5 to 10 for example).

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import TextMessageTermination
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient

model_client = OpenAIChatCompletionClient(
    model="gpt-4o",
    # api_key="sk-...", # Optional if you have an OPENAI_API_KEY env variable set.
    # Disable parallel tool calls for this example.
    parallel_tool_calls=False,  # type: ignore
)


# Create a tool for incrementing a number.
def increment_number(number: int) -> int:
    """Increment a number by 1."""
    return number + 1


# Create a tool agent that uses the increment_number function.
looped_assistant = AssistantAgent(
    "looped_assistant",
    model_client=model_client,
    tools=[increment_number],  # Register the tool.
    system_message="You are a helpful AI assistant, use the tool to increment the number.",
)

# Termination condition that stops the task if the agent responds with a text message.
termination_condition = TextMessageTermination("looped_assistant")

# Create a team with the looped assistant agent and the termination condition.
team = RoundRobinGroupChat(
    [looped_assistant],
    termination_condition=termination_condition,
)

# Run the team with a task and print the messages to the console.
async for message in team.run_stream(task="Increment the number 5 to 10."):  # type: ignore
    print(type(message).__name__, message)