Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More async tool fixes #1204

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def generate_tool_calls_reply(
"content": func_return.get("content", ""),
}
)
if len(tool_returns) > 0:
if tool_returns:
return True, {
"role": "tool",
"tool_responses": tool_returns,
Expand Down Expand Up @@ -907,14 +907,12 @@ async def a_generate_tool_calls_reply(
func = self._function_map.get(tool_call.get("function", {}).get("name", None), None)
if func and asyncio.coroutines.iscoroutinefunction(func):
async_tool_calls.append(self._a_execute_tool_call(tool_call))
if len(async_tool_calls) > 0:
if async_tool_calls:
tool_returns = await asyncio.gather(*async_tool_calls)
return True, {
"role": "tool",
"tool_responses": tool_returns,
"content": "\n\n".join(
[self._str_for_tool_response(tool_return["content"]) for tool_return in tool_returns]
),
"content": "\n\n".join([self._str_for_tool_response(tool_return) for tool_return in tool_returns]),
}

return False, None
Expand Down Expand Up @@ -1128,7 +1126,10 @@ async def a_check_termination_and_human_reply(
]
)

response = {"role": "user", "content": reply, "tool_responses": tool_returns}
response = {"role": "user", "content": reply}
if tool_returns:
response["tool_responses"] = tool_returns

return True, response

# increment the consecutive_auto_reply_counter
Expand Down
Loading