Skip to content

Commit c103699

Browse files
authored
cleaner definition of tool_responses fixes #1174 (#1182)
1 parent 2ca8aae commit c103699

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

autogen/agentchat/conversable_agent.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -855,24 +855,23 @@ def generate_tool_calls_reply(
855855
if messages is None:
856856
messages = self._oai_messages[sender]
857857
message = messages[-1]
858-
if "tool_calls" in message and message["tool_calls"]:
859-
tool_calls = message["tool_calls"]
860-
tool_returns = []
861-
for tool_call in tool_calls:
862-
id = tool_call["id"]
863-
function_call = tool_call.get("function", {})
864-
func = self._function_map.get(function_call.get("name", None), None)
865-
if asyncio.coroutines.iscoroutinefunction(func):
866-
continue
867-
_, func_return = self.execute_function(function_call)
868-
tool_returns.append(
869-
{
870-
"tool_call_id": id,
871-
"role": "tool",
872-
"name": func_return.get("name", ""),
873-
"content": func_return.get("content", ""),
874-
}
875-
)
858+
tool_returns = []
859+
for tool_call in message.get("tool_calls", []):
860+
id = tool_call["id"]
861+
function_call = tool_call.get("function", {})
862+
func = self._function_map.get(function_call.get("name", None), None)
863+
if asyncio.coroutines.iscoroutinefunction(func):
864+
continue
865+
_, func_return = self.execute_function(function_call)
866+
tool_returns.append(
867+
{
868+
"tool_call_id": id,
869+
"role": "tool",
870+
"name": func_return.get("name", ""),
871+
"content": func_return.get("content", ""),
872+
}
873+
)
874+
if len(tool_returns) > 0:
876875
return True, {
877876
"role": "tool",
878877
"tool_responses": tool_returns,

0 commit comments

Comments
 (0)