Skip to content

Commit

Permalink
remove name from tool response (#1263)
Browse files Browse the repository at this point in the history
* remove name from tool response

* fix tool response tests

* fix output string
  • Loading branch information
yenif authored Jan 16, 2024
1 parent bde2fc9 commit d1c1548
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
12 changes: 7 additions & 5 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,12 @@ def _print_received_message(self, message: Union[Dict, str], sender: Agent):
return # If role is tool, then content is just a concatenation of all tool_responses

if message.get("role") in ["function", "tool"]:
func_print = f"***** Response from calling {message['role']} \"{message['name']}\" *****"
if message["role"] == "function":
id_key = "name"
else:
id_key = "tool_call_id"

func_print = f"***** Response from calling {message['role']} \"{message[id_key]}\" *****"
print(colored(func_print, "green"), flush=True)
print(message["content"], flush=True)
print(colored("*" * len(func_print), "green"), flush=True)
Expand Down Expand Up @@ -884,10 +889,9 @@ async def a_generate_function_call_reply(
return False, None

def _str_for_tool_response(self, tool_response):
func_name = tool_response.get("name", "")
func_id = tool_response.get("tool_call_id", "")
response = tool_response.get("content", "")
return f"Tool call: {func_name}\nId: {func_id}\n{response}"
return f"Tool Call Id: {func_id}\n{response}"

def generate_tool_calls_reply(
self,
Expand All @@ -913,7 +917,6 @@ def generate_tool_calls_reply(
{
"tool_call_id": id,
"role": "tool",
"name": func_return.get("name", ""),
"content": func_return.get("content", ""),
}
)
Expand All @@ -932,7 +935,6 @@ async def _a_execute_tool_call(self, tool_call):
return {
"tool_call_id": id,
"role": "tool",
"name": func_return.get("name", ""),
"content": func_return.get("content", ""),
}

Expand Down
26 changes: 8 additions & 18 deletions test/agentchat/test_tool_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,32 +245,27 @@ def receive(
{
"role": "tool",
"tool_responses": [
{"tool_call_id": "tool_1", "role": "tool", "name": "echo", "content": "hello world"},
{"tool_call_id": "tool_1", "role": "tool", "content": "hello world"},
{
"tool_call_id": "tool_2",
"role": "tool",
"name": "echo",
"content": "goodbye and thanks for all the fish",
},
{
"tool_call_id": "tool_3",
"role": "tool",
"name": "multi_tool_call_echo",
"content": "Error: Function multi_tool_call_echo not found.",
},
],
"content": inspect.cleandoc(
"""
Tool call: echo
Id: tool_1
Tool Call Id: tool_1
hello world
Tool call: echo
Id: tool_2
Tool Call Id: tool_2
goodbye and thanks for all the fish
Tool call: multi_tool_call_echo
Id: tool_3
Tool Call Id: tool_3
Error: Function multi_tool_call_echo not found.
"""
),
Expand Down Expand Up @@ -348,32 +343,27 @@ async def a_echo(str):
{
"role": "tool",
"tool_responses": [
{"tool_call_id": "tool_1", "role": "tool", "name": "a_echo", "content": "hello world"},
{"tool_call_id": "tool_1", "role": "tool", "content": "hello world"},
{
"tool_call_id": "tool_2",
"role": "tool",
"name": "echo",
"content": "goodbye and thanks for all the fish",
},
{
"tool_call_id": "tool_3",
"role": "tool",
"name": "multi_tool_call_echo",
"content": "Error: Function multi_tool_call_echo not found.",
},
],
"content": inspect.cleandoc(
"""
Tool call: a_echo
Id: tool_1
Tool Call Id: tool_1
hello world
Tool call: echo
Id: tool_2
Tool Call Id: tool_2
goodbye and thanks for all the fish
Tool call: multi_tool_call_echo
Id: tool_3
Tool Call Id: tool_3
Error: Function multi_tool_call_echo not found.
"""
),
Expand Down

0 comments on commit d1c1548

Please sign in to comment.