Skip to content

Commit

Permalink
cleaner definition of tool_responses fixes #1174 (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenif authored Jan 9, 2024
1 parent 2ca8aae commit c103699
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,24 +855,23 @@ def generate_tool_calls_reply(
if messages is None:
messages = self._oai_messages[sender]
message = messages[-1]
if "tool_calls" in message and message["tool_calls"]:
tool_calls = message["tool_calls"]
tool_returns = []
for tool_call in tool_calls:
id = tool_call["id"]
function_call = tool_call.get("function", {})
func = self._function_map.get(function_call.get("name", None), None)
if asyncio.coroutines.iscoroutinefunction(func):
continue
_, func_return = self.execute_function(function_call)
tool_returns.append(
{
"tool_call_id": id,
"role": "tool",
"name": func_return.get("name", ""),
"content": func_return.get("content", ""),
}
)
tool_returns = []
for tool_call in message.get("tool_calls", []):
id = tool_call["id"]
function_call = tool_call.get("function", {})
func = self._function_map.get(function_call.get("name", None), None)
if asyncio.coroutines.iscoroutinefunction(func):
continue
_, func_return = self.execute_function(function_call)
tool_returns.append(
{
"tool_call_id": id,
"role": "tool",
"name": func_return.get("name", ""),
"content": func_return.get("content", ""),
}
)
if len(tool_returns) > 0:
return True, {
"role": "tool",
"tool_responses": tool_returns,
Expand Down

0 comments on commit c103699

Please sign in to comment.