Skip to content

Commit 3ff3a18

Browse files
fix: Fix tool attribute access
1 parent e09edef commit 3ff3a18

File tree

1 file changed

+20
-5
lines changed
  • agents-api/agents_api/routers/utils

1 file changed

+20
-5
lines changed

agents-api/agents_api/routers/utils/tools.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
from beartype import beartype
88
from fastapi.background import BackgroundTasks
9-
from litellm.utils import CustomStreamWrapper, ModelResponse, ModelResponseStream
9+
from litellm.utils import (
10+
ChatCompletionMessageToolCall,
11+
CustomStreamWrapper,
12+
ModelResponse,
13+
ModelResponseStream,
14+
)
1015

1116
from ...app import app
1217
from ...autogen.openapi_model import (
@@ -295,7 +300,7 @@ async def completion(
295300
response: ModelResponse | CustomStreamWrapper | None = None
296301
stream: bool = kwargs.get("stream", False)
297302
while True:
298-
tool_calls = []
303+
tool_calls: list[ChatCompletionMessageToolCall | dict] = []
299304

300305
if not stream:
301306
response: ModelResponse = await self._completion_func(**kwargs)
@@ -339,13 +344,23 @@ async def completion(
339344

340345
for tool in tool_calls:
341346
# call a tool
342-
tool_name = tool.function.name
343-
tool_args = json.loads(tool.function.arguments)
347+
tool_name = (
348+
tool.function.name
349+
if isinstance(tool, ChatCompletionMessageToolCall)
350+
else tool["function"]["name"]
351+
)
352+
tool_args = json.loads(
353+
tool.function.arguments
354+
if isinstance(tool, ChatCompletionMessageToolCall)
355+
else tool["function"]["arguments"]
356+
)
344357
tool_response = await self._call_tool(developer_id, tool_name, tool_args)
345358

346359
# append result to messages from previous step
347360
kwargs["messages"].append({
348-
"tool_call_id": tool.id,
361+
"tool_call_id": tool.id
362+
if isinstance(tool, ChatCompletionMessageToolCall)
363+
else tool["id"],
349364
"role": "tool",
350365
"name": tool_name,
351366
"content": tool_response,

0 commit comments

Comments
 (0)