agno 2.3.2__py3-none-any.whl → 2.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agno/agent/agent.py +513 -185
- agno/compression/__init__.py +3 -0
- agno/compression/manager.py +176 -0
- agno/db/dynamo/dynamo.py +11 -0
- agno/db/firestore/firestore.py +5 -1
- agno/db/gcs_json/gcs_json_db.py +5 -2
- agno/db/in_memory/in_memory_db.py +5 -2
- agno/db/json/json_db.py +5 -1
- agno/db/migrations/manager.py +4 -4
- agno/db/mongo/async_mongo.py +158 -34
- agno/db/mongo/mongo.py +6 -2
- agno/db/mysql/mysql.py +48 -54
- agno/db/postgres/async_postgres.py +61 -51
- agno/db/postgres/postgres.py +42 -50
- agno/db/redis/redis.py +5 -0
- agno/db/redis/utils.py +5 -5
- agno/db/singlestore/singlestore.py +99 -108
- agno/db/sqlite/async_sqlite.py +29 -27
- agno/db/sqlite/sqlite.py +30 -26
- agno/knowledge/reader/pdf_reader.py +2 -2
- agno/knowledge/reader/tavily_reader.py +0 -1
- agno/memory/__init__.py +14 -1
- agno/memory/manager.py +217 -4
- agno/memory/strategies/__init__.py +15 -0
- agno/memory/strategies/base.py +67 -0
- agno/memory/strategies/summarize.py +196 -0
- agno/memory/strategies/types.py +37 -0
- agno/models/anthropic/claude.py +84 -80
- agno/models/aws/bedrock.py +38 -16
- agno/models/aws/claude.py +97 -277
- agno/models/azure/ai_foundry.py +8 -4
- agno/models/base.py +101 -14
- agno/models/cerebras/cerebras.py +18 -7
- agno/models/cerebras/cerebras_openai.py +4 -2
- agno/models/cohere/chat.py +8 -4
- agno/models/google/gemini.py +578 -20
- agno/models/groq/groq.py +18 -5
- agno/models/huggingface/huggingface.py +17 -6
- agno/models/ibm/watsonx.py +16 -6
- agno/models/litellm/chat.py +17 -7
- agno/models/message.py +19 -5
- agno/models/meta/llama.py +20 -4
- agno/models/mistral/mistral.py +8 -4
- agno/models/ollama/chat.py +17 -6
- agno/models/openai/chat.py +17 -6
- agno/models/openai/responses.py +23 -9
- agno/models/vertexai/claude.py +99 -5
- agno/os/interfaces/agui/router.py +1 -0
- agno/os/interfaces/agui/utils.py +97 -57
- agno/os/router.py +16 -0
- agno/os/routers/memory/memory.py +143 -0
- agno/os/routers/memory/schemas.py +26 -0
- agno/os/schema.py +21 -6
- agno/os/utils.py +134 -10
- agno/run/base.py +2 -1
- agno/run/workflow.py +1 -1
- agno/team/team.py +565 -219
- agno/tools/mcp/mcp.py +1 -1
- agno/utils/agent.py +119 -1
- agno/utils/models/ai_foundry.py +9 -2
- agno/utils/models/claude.py +12 -5
- agno/utils/models/cohere.py +9 -2
- agno/utils/models/llama.py +9 -2
- agno/utils/models/mistral.py +4 -2
- agno/utils/print_response/agent.py +37 -2
- agno/utils/print_response/team.py +52 -0
- agno/utils/tokens.py +41 -0
- agno/workflow/types.py +2 -2
- {agno-2.3.2.dist-info → agno-2.3.3.dist-info}/METADATA +45 -40
- {agno-2.3.2.dist-info → agno-2.3.3.dist-info}/RECORD +73 -66
- {agno-2.3.2.dist-info → agno-2.3.3.dist-info}/WHEEL +0 -0
- {agno-2.3.2.dist-info → agno-2.3.3.dist-info}/licenses/LICENSE +0 -0
- {agno-2.3.2.dist-info → agno-2.3.3.dist-info}/top_level.txt +0 -0
agno/models/anthropic/claude.py
CHANGED
|
@@ -183,7 +183,7 @@ class Claude(Model):
|
|
|
183
183
|
)
|
|
184
184
|
return False
|
|
185
185
|
|
|
186
|
-
# Check for legacy model patterns
|
|
186
|
+
# Check for legacy model patterns which don't support structured outputs
|
|
187
187
|
if self.id.startswith("claude-3-"):
|
|
188
188
|
return False
|
|
189
189
|
if self.id.startswith("claude-sonnet-4-") and not self.id.startswith("claude-sonnet-4-5"):
|
|
@@ -222,64 +222,6 @@ class Claude(Model):
|
|
|
222
222
|
|
|
223
223
|
return False
|
|
224
224
|
|
|
225
|
-
def _has_beta_features(
|
|
226
|
-
self,
|
|
227
|
-
response_format: Optional[Union[Dict, Type[BaseModel]]] = None,
|
|
228
|
-
tools: Optional[List[Dict[str, Any]]] = None,
|
|
229
|
-
) -> bool:
|
|
230
|
-
"""Check if the model has any Anthropic beta features enabled."""
|
|
231
|
-
return (
|
|
232
|
-
self.mcp_servers is not None
|
|
233
|
-
or self.context_management is not None
|
|
234
|
-
or self.skills is not None
|
|
235
|
-
or self.betas is not None
|
|
236
|
-
or self._using_structured_outputs(response_format, tools)
|
|
237
|
-
)
|
|
238
|
-
|
|
239
|
-
def get_client(self) -> AnthropicClient:
|
|
240
|
-
"""
|
|
241
|
-
Returns an instance of the Anthropic client.
|
|
242
|
-
"""
|
|
243
|
-
if self.client and not self.client.is_closed():
|
|
244
|
-
return self.client
|
|
245
|
-
|
|
246
|
-
_client_params = self._get_client_params()
|
|
247
|
-
if self.http_client:
|
|
248
|
-
if isinstance(self.http_client, httpx.Client):
|
|
249
|
-
_client_params["http_client"] = self.http_client
|
|
250
|
-
else:
|
|
251
|
-
log_warning("http_client is not an instance of httpx.Client. Using default global httpx.Client.")
|
|
252
|
-
# Use global sync client when user http_client is invalid
|
|
253
|
-
_client_params["http_client"] = get_default_sync_client()
|
|
254
|
-
else:
|
|
255
|
-
# Use global sync client when no custom http_client is provided
|
|
256
|
-
_client_params["http_client"] = get_default_sync_client()
|
|
257
|
-
self.client = AnthropicClient(**_client_params)
|
|
258
|
-
return self.client
|
|
259
|
-
|
|
260
|
-
def get_async_client(self) -> AsyncAnthropicClient:
|
|
261
|
-
"""
|
|
262
|
-
Returns an instance of the async Anthropic client.
|
|
263
|
-
"""
|
|
264
|
-
if self.async_client and not self.async_client.is_closed():
|
|
265
|
-
return self.async_client
|
|
266
|
-
|
|
267
|
-
_client_params = self._get_client_params()
|
|
268
|
-
if self.http_client:
|
|
269
|
-
if isinstance(self.http_client, httpx.AsyncClient):
|
|
270
|
-
_client_params["http_client"] = self.http_client
|
|
271
|
-
else:
|
|
272
|
-
log_warning(
|
|
273
|
-
"http_client is not an instance of httpx.AsyncClient. Using default global httpx.AsyncClient."
|
|
274
|
-
)
|
|
275
|
-
# Use global async client when user http_client is invalid
|
|
276
|
-
_client_params["http_client"] = get_default_async_client()
|
|
277
|
-
else:
|
|
278
|
-
# Use global async client when no custom http_client is provided
|
|
279
|
-
_client_params["http_client"] = get_default_async_client()
|
|
280
|
-
self.async_client = AsyncAnthropicClient(**_client_params)
|
|
281
|
-
return self.async_client
|
|
282
|
-
|
|
283
225
|
def _validate_thinking_support(self) -> None:
|
|
284
226
|
"""
|
|
285
227
|
Validate that the current model supports extended thinking.
|
|
@@ -375,6 +317,81 @@ class Claude(Model):
|
|
|
375
317
|
|
|
376
318
|
return None
|
|
377
319
|
|
|
320
|
+
def _validate_structured_outputs_usage(
|
|
321
|
+
self,
|
|
322
|
+
response_format: Optional[Union[Dict, Type[BaseModel]]] = None,
|
|
323
|
+
tools: Optional[List[Dict[str, Any]]] = None,
|
|
324
|
+
) -> None:
|
|
325
|
+
"""
|
|
326
|
+
Validate that structured outputs are only used with supported models.
|
|
327
|
+
|
|
328
|
+
Raises:
|
|
329
|
+
ValueError: If structured outputs are used with unsupported model
|
|
330
|
+
"""
|
|
331
|
+
if not self._using_structured_outputs(response_format, tools):
|
|
332
|
+
return
|
|
333
|
+
|
|
334
|
+
if not self._supports_structured_outputs():
|
|
335
|
+
raise ValueError(f"Model '{self.id}' does not support structured outputs.\n\n")
|
|
336
|
+
|
|
337
|
+
def _has_beta_features(
|
|
338
|
+
self,
|
|
339
|
+
response_format: Optional[Union[Dict, Type[BaseModel]]] = None,
|
|
340
|
+
tools: Optional[List[Dict[str, Any]]] = None,
|
|
341
|
+
) -> bool:
|
|
342
|
+
"""Check if the model has any Anthropic beta features enabled."""
|
|
343
|
+
return (
|
|
344
|
+
self.mcp_servers is not None
|
|
345
|
+
or self.context_management is not None
|
|
346
|
+
or self.skills is not None
|
|
347
|
+
or self.betas is not None
|
|
348
|
+
or self._using_structured_outputs(response_format, tools)
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
def get_client(self) -> AnthropicClient:
|
|
352
|
+
"""
|
|
353
|
+
Returns an instance of the Anthropic client.
|
|
354
|
+
"""
|
|
355
|
+
if self.client and not self.client.is_closed():
|
|
356
|
+
return self.client
|
|
357
|
+
|
|
358
|
+
_client_params = self._get_client_params()
|
|
359
|
+
if self.http_client:
|
|
360
|
+
if isinstance(self.http_client, httpx.Client):
|
|
361
|
+
_client_params["http_client"] = self.http_client
|
|
362
|
+
else:
|
|
363
|
+
log_warning("http_client is not an instance of httpx.Client. Using default global httpx.Client.")
|
|
364
|
+
# Use global sync client when user http_client is invalid
|
|
365
|
+
_client_params["http_client"] = get_default_sync_client()
|
|
366
|
+
else:
|
|
367
|
+
# Use global sync client when no custom http_client is provided
|
|
368
|
+
_client_params["http_client"] = get_default_sync_client()
|
|
369
|
+
self.client = AnthropicClient(**_client_params)
|
|
370
|
+
return self.client
|
|
371
|
+
|
|
372
|
+
def get_async_client(self) -> AsyncAnthropicClient:
|
|
373
|
+
"""
|
|
374
|
+
Returns an instance of the async Anthropic client.
|
|
375
|
+
"""
|
|
376
|
+
if self.async_client and not self.async_client.is_closed():
|
|
377
|
+
return self.async_client
|
|
378
|
+
|
|
379
|
+
_client_params = self._get_client_params()
|
|
380
|
+
if self.http_client:
|
|
381
|
+
if isinstance(self.http_client, httpx.AsyncClient):
|
|
382
|
+
_client_params["http_client"] = self.http_client
|
|
383
|
+
else:
|
|
384
|
+
log_warning(
|
|
385
|
+
"http_client is not an instance of httpx.AsyncClient. Using default global httpx.AsyncClient."
|
|
386
|
+
)
|
|
387
|
+
# Use global async client when user http_client is invalid
|
|
388
|
+
_client_params["http_client"] = get_default_async_client()
|
|
389
|
+
else:
|
|
390
|
+
# Use global async client when no custom http_client is provided
|
|
391
|
+
_client_params["http_client"] = get_default_async_client()
|
|
392
|
+
self.async_client = AsyncAnthropicClient(**_client_params)
|
|
393
|
+
return self.async_client
|
|
394
|
+
|
|
378
395
|
def get_request_params(
|
|
379
396
|
self,
|
|
380
397
|
response_format: Optional[Union[Dict, Type[BaseModel]]] = None,
|
|
@@ -427,23 +444,6 @@ class Claude(Model):
|
|
|
427
444
|
|
|
428
445
|
return _request_params
|
|
429
446
|
|
|
430
|
-
def _validate_structured_outputs_usage(
|
|
431
|
-
self,
|
|
432
|
-
response_format: Optional[Union[Dict, Type[BaseModel]]] = None,
|
|
433
|
-
tools: Optional[List[Dict[str, Any]]] = None,
|
|
434
|
-
) -> None:
|
|
435
|
-
"""
|
|
436
|
-
Validate that structured outputs are only used with supported models.
|
|
437
|
-
|
|
438
|
-
Raises:
|
|
439
|
-
ValueError: If structured outputs are used with unsupported model
|
|
440
|
-
"""
|
|
441
|
-
if not self._using_structured_outputs(response_format, tools):
|
|
442
|
-
return
|
|
443
|
-
|
|
444
|
-
if not self._supports_structured_outputs():
|
|
445
|
-
raise ValueError(f"Model '{self.id}' does not support structured outputs.\n\n")
|
|
446
|
-
|
|
447
447
|
def _prepare_request_kwargs(
|
|
448
448
|
self,
|
|
449
449
|
system_message: str,
|
|
@@ -507,6 +507,7 @@ class Claude(Model):
|
|
|
507
507
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
508
508
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
509
509
|
run_response: Optional[RunOutput] = None,
|
|
510
|
+
compress_tool_results: bool = False,
|
|
510
511
|
) -> ModelResponse:
|
|
511
512
|
"""
|
|
512
513
|
Send a request to the Anthropic API to generate a response.
|
|
@@ -515,7 +516,7 @@ class Claude(Model):
|
|
|
515
516
|
if run_response and run_response.metrics:
|
|
516
517
|
run_response.metrics.set_time_to_first_token()
|
|
517
518
|
|
|
518
|
-
chat_messages, system_message = format_messages(messages)
|
|
519
|
+
chat_messages, system_message = format_messages(messages, compress_tool_results=compress_tool_results)
|
|
519
520
|
request_kwargs = self._prepare_request_kwargs(system_message, tools=tools, response_format=response_format)
|
|
520
521
|
|
|
521
522
|
if self._has_beta_features(response_format=response_format, tools=tools):
|
|
@@ -563,6 +564,7 @@ class Claude(Model):
|
|
|
563
564
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
564
565
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
565
566
|
run_response: Optional[RunOutput] = None,
|
|
567
|
+
compress_tool_results: bool = False,
|
|
566
568
|
) -> Any:
|
|
567
569
|
"""
|
|
568
570
|
Stream a response from the Anthropic API.
|
|
@@ -578,7 +580,7 @@ class Claude(Model):
|
|
|
578
580
|
RateLimitError: If the API rate limit is exceeded
|
|
579
581
|
APIStatusError: For other API-related errors
|
|
580
582
|
"""
|
|
581
|
-
chat_messages, system_message = format_messages(messages)
|
|
583
|
+
chat_messages, system_message = format_messages(messages, compress_tool_results=compress_tool_results)
|
|
582
584
|
request_kwargs = self._prepare_request_kwargs(system_message, tools=tools, response_format=response_format)
|
|
583
585
|
|
|
584
586
|
try:
|
|
@@ -630,6 +632,7 @@ class Claude(Model):
|
|
|
630
632
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
631
633
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
632
634
|
run_response: Optional[RunOutput] = None,
|
|
635
|
+
compress_tool_results: bool = False,
|
|
633
636
|
) -> ModelResponse:
|
|
634
637
|
"""
|
|
635
638
|
Send an asynchronous request to the Anthropic API to generate a response.
|
|
@@ -638,7 +641,7 @@ class Claude(Model):
|
|
|
638
641
|
if run_response and run_response.metrics:
|
|
639
642
|
run_response.metrics.set_time_to_first_token()
|
|
640
643
|
|
|
641
|
-
chat_messages, system_message = format_messages(messages)
|
|
644
|
+
chat_messages, system_message = format_messages(messages, compress_tool_results=compress_tool_results)
|
|
642
645
|
request_kwargs = self._prepare_request_kwargs(system_message, tools=tools, response_format=response_format)
|
|
643
646
|
|
|
644
647
|
# Beta features
|
|
@@ -687,6 +690,7 @@ class Claude(Model):
|
|
|
687
690
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
688
691
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
689
692
|
run_response: Optional[RunOutput] = None,
|
|
693
|
+
compress_tool_results: bool = False,
|
|
690
694
|
) -> AsyncIterator[ModelResponse]:
|
|
691
695
|
"""
|
|
692
696
|
Stream an asynchronous response from the Anthropic API.
|
|
@@ -703,7 +707,7 @@ class Claude(Model):
|
|
|
703
707
|
if run_response and run_response.metrics:
|
|
704
708
|
run_response.metrics.set_time_to_first_token()
|
|
705
709
|
|
|
706
|
-
chat_messages, system_message = format_messages(messages)
|
|
710
|
+
chat_messages, system_message = format_messages(messages, compress_tool_results=compress_tool_results)
|
|
707
711
|
request_kwargs = self._prepare_request_kwargs(system_message, tools=tools, response_format=response_format)
|
|
708
712
|
|
|
709
713
|
if self._has_beta_features(response_format=response_format, tools=tools):
|
agno/models/aws/bedrock.py
CHANGED
|
@@ -219,21 +219,35 @@ class AwsBedrock(Model):
|
|
|
219
219
|
|
|
220
220
|
return {k: v for k, v in request_kwargs.items() if v is not None}
|
|
221
221
|
|
|
222
|
-
def _format_messages(
|
|
222
|
+
def _format_messages(
|
|
223
|
+
self, messages: List[Message], compress_tool_results: bool = False
|
|
224
|
+
) -> Tuple[List[Dict[str, Any]], Optional[List[Dict[str, Any]]]]:
|
|
223
225
|
"""
|
|
224
226
|
Format the messages for the request.
|
|
225
227
|
|
|
228
|
+
Args:
|
|
229
|
+
messages: List of messages to format
|
|
230
|
+
compress_tool_results: Whether to compress tool results
|
|
231
|
+
|
|
226
232
|
Returns:
|
|
227
233
|
Tuple[List[Dict[str, Any]], Optional[List[Dict[str, Any]]]]: The formatted messages.
|
|
228
234
|
"""
|
|
235
|
+
|
|
229
236
|
formatted_messages: List[Dict[str, Any]] = []
|
|
230
237
|
system_message = None
|
|
231
238
|
for message in messages:
|
|
232
239
|
if message.role == "system":
|
|
233
240
|
system_message = [{"text": message.content}]
|
|
241
|
+
elif message.role == "tool":
|
|
242
|
+
content = message.get_content(use_compressed_content=compress_tool_results)
|
|
243
|
+
tool_result = {
|
|
244
|
+
"toolUseId": message.tool_call_id,
|
|
245
|
+
"content": [{"json": {"result": content}}],
|
|
246
|
+
}
|
|
247
|
+
formatted_message: Dict[str, Any] = {"role": "user", "content": [{"toolResult": tool_result}]}
|
|
248
|
+
formatted_messages.append(formatted_message)
|
|
234
249
|
else:
|
|
235
|
-
formatted_message
|
|
236
|
-
# Handle tool results
|
|
250
|
+
formatted_message = {"role": message.role, "content": []}
|
|
237
251
|
if isinstance(message.content, list):
|
|
238
252
|
formatted_message["content"].extend(message.content)
|
|
239
253
|
elif message.tool_calls:
|
|
@@ -352,12 +366,13 @@ class AwsBedrock(Model):
|
|
|
352
366
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
353
367
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
354
368
|
run_response: Optional[RunOutput] = None,
|
|
369
|
+
compress_tool_results: bool = False,
|
|
355
370
|
) -> ModelResponse:
|
|
356
371
|
"""
|
|
357
372
|
Invoke the Bedrock API.
|
|
358
373
|
"""
|
|
359
374
|
try:
|
|
360
|
-
formatted_messages, system_message = self._format_messages(messages)
|
|
375
|
+
formatted_messages, system_message = self._format_messages(messages, compress_tool_results)
|
|
361
376
|
|
|
362
377
|
tool_config = None
|
|
363
378
|
if tools:
|
|
@@ -400,12 +415,13 @@ class AwsBedrock(Model):
|
|
|
400
415
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
401
416
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
402
417
|
run_response: Optional[RunOutput] = None,
|
|
418
|
+
compress_tool_results: bool = False,
|
|
403
419
|
) -> Iterator[ModelResponse]:
|
|
404
420
|
"""
|
|
405
421
|
Invoke the Bedrock API with streaming.
|
|
406
422
|
"""
|
|
407
423
|
try:
|
|
408
|
-
formatted_messages, system_message = self._format_messages(messages)
|
|
424
|
+
formatted_messages, system_message = self._format_messages(messages, compress_tool_results)
|
|
409
425
|
|
|
410
426
|
tool_config = None
|
|
411
427
|
if tools:
|
|
@@ -452,12 +468,13 @@ class AwsBedrock(Model):
|
|
|
452
468
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
453
469
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
454
470
|
run_response: Optional[RunOutput] = None,
|
|
471
|
+
compress_tool_results: bool = False,
|
|
455
472
|
) -> ModelResponse:
|
|
456
473
|
"""
|
|
457
474
|
Async invoke the Bedrock API.
|
|
458
475
|
"""
|
|
459
476
|
try:
|
|
460
|
-
formatted_messages, system_message = self._format_messages(messages)
|
|
477
|
+
formatted_messages, system_message = self._format_messages(messages, compress_tool_results)
|
|
461
478
|
|
|
462
479
|
tool_config = None
|
|
463
480
|
if tools:
|
|
@@ -503,12 +520,13 @@ class AwsBedrock(Model):
|
|
|
503
520
|
tools: Optional[List[Dict[str, Any]]] = None,
|
|
504
521
|
tool_choice: Optional[Union[str, Dict[str, Any]]] = None,
|
|
505
522
|
run_response: Optional[RunOutput] = None,
|
|
523
|
+
compress_tool_results: bool = False,
|
|
506
524
|
) -> AsyncIterator[ModelResponse]:
|
|
507
525
|
"""
|
|
508
526
|
Async invoke the Bedrock API with streaming.
|
|
509
527
|
"""
|
|
510
528
|
try:
|
|
511
|
-
formatted_messages, system_message = self._format_messages(messages)
|
|
529
|
+
formatted_messages, system_message = self._format_messages(messages, compress_tool_results)
|
|
512
530
|
|
|
513
531
|
tool_config = None
|
|
514
532
|
if tools:
|
|
@@ -549,30 +567,34 @@ class AwsBedrock(Model):
|
|
|
549
567
|
|
|
550
568
|
# Overwrite the default from the base model
|
|
551
569
|
def format_function_call_results(
|
|
552
|
-
self,
|
|
570
|
+
self,
|
|
571
|
+
messages: List[Message],
|
|
572
|
+
function_call_results: List[Message],
|
|
573
|
+
compress_tool_results: bool = False,
|
|
574
|
+
**kwargs,
|
|
553
575
|
) -> None:
|
|
554
576
|
"""
|
|
555
|
-
Handle the results of function calls.
|
|
577
|
+
Handle the results of function calls for Bedrock.
|
|
578
|
+
Uses compressed_content if compress_tool_results is True.
|
|
556
579
|
|
|
557
580
|
Args:
|
|
558
581
|
messages (List[Message]): The list of conversation messages.
|
|
559
582
|
function_call_results (List[Message]): The results of the function calls.
|
|
583
|
+
compress_tool_results: Whether to compress tool results.
|
|
560
584
|
**kwargs: Additional arguments including tool_ids.
|
|
561
585
|
"""
|
|
586
|
+
|
|
562
587
|
if function_call_results:
|
|
563
588
|
tool_ids = kwargs.get("tool_ids", [])
|
|
564
|
-
tool_result_content: List = []
|
|
565
589
|
|
|
566
590
|
for _fc_message_index, _fc_message in enumerate(function_call_results):
|
|
567
591
|
# Use tool_call_id from message if tool_ids list is insufficient
|
|
568
592
|
tool_id = tool_ids[_fc_message_index] if _fc_message_index < len(tool_ids) else _fc_message.tool_call_id
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
"content": [{"json": {"result": _fc_message.content}}],
|
|
572
|
-
}
|
|
573
|
-
tool_result_content.append({"toolResult": tool_result})
|
|
593
|
+
if not _fc_message.tool_call_id:
|
|
594
|
+
_fc_message.tool_call_id = tool_id
|
|
574
595
|
|
|
575
|
-
|
|
596
|
+
# Append as standard role="tool" message
|
|
597
|
+
messages.append(_fc_message)
|
|
576
598
|
|
|
577
599
|
def _parse_provider_response(self, response: Dict[str, Any], **kwargs) -> ModelResponse:
|
|
578
600
|
"""
|