Skip to content

Commit fd92645

Browse files
committed
Fix tool handling in streaming
1 parent 6b35ff1 commit fd92645

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

llmstack/play/actors/agent.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ def __init__(
9393
api_key=openai_provider_config.api_key,
9494
base_url=openai_provider_config.base_url,
9595
)
96-
self._stream = self._config.get(
97-
"stream",
98-
self._config.get("model", "gpt-3.5-turbo") in list(map(lambda x: str(x.value), AgentModel)),
99-
)
96+
self._stream = self._config.get("stream")
97+
if self._stream is None:
98+
self._stream = (
99+
True
100+
if self._config.get("model", "gpt-3.5-turbo") in list(map(lambda x: str(x.value), AgentModel))
101+
else False
102+
)
100103

101104
self._agent_messages = []
102105
self._tool_calls = []
@@ -290,8 +293,11 @@ def on_receive(self, message: Message) -> Any:
290293
),
291294
)
292295
elif tool_calls_chunk and len(tool_calls_chunk) > 0:
296+
tool_call_index = 0
293297
for tool_call in tool_calls_chunk:
294-
tool_call_index = tool_call.index if hasattr(tool_call, "index") else 0
298+
if hasattr(tool_call, "index"):
299+
tool_call_index = tool_call.index
300+
295301
if len(self._tool_calls) < tool_call_index + 1:
296302
# Insert at the index
297303
self._tool_calls.insert(
@@ -313,6 +319,9 @@ def on_receive(self, message: Message) -> Any:
313319
type="step",
314320
),
315321
)
322+
323+
if not hasattr(tool_call, "index"):
324+
tool_call_index += 1
316325
else:
317326
# Update at the index
318327
self._tool_calls[tool_call_index]["arguments"] += tool_call.function.arguments

0 commit comments

Comments
 (0)