agno 2.2.13__py3-none-any.whl → 2.3.1__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.
Files changed (92) hide show
  1. agno/agent/agent.py +197 -110
  2. agno/api/api.py +2 -0
  3. agno/db/base.py +26 -0
  4. agno/db/dynamo/dynamo.py +8 -0
  5. agno/db/dynamo/schemas.py +1 -0
  6. agno/db/firestore/firestore.py +8 -0
  7. agno/db/firestore/schemas.py +1 -0
  8. agno/db/gcs_json/gcs_json_db.py +8 -0
  9. agno/db/in_memory/in_memory_db.py +8 -1
  10. agno/db/json/json_db.py +8 -0
  11. agno/db/migrations/manager.py +199 -0
  12. agno/db/migrations/versions/__init__.py +0 -0
  13. agno/db/migrations/versions/v2_3_0.py +938 -0
  14. agno/db/mongo/async_mongo.py +16 -6
  15. agno/db/mongo/mongo.py +11 -0
  16. agno/db/mongo/schemas.py +3 -0
  17. agno/db/mongo/utils.py +17 -0
  18. agno/db/mysql/mysql.py +76 -3
  19. agno/db/mysql/schemas.py +20 -10
  20. agno/db/postgres/async_postgres.py +99 -25
  21. agno/db/postgres/postgres.py +75 -6
  22. agno/db/postgres/schemas.py +30 -20
  23. agno/db/redis/redis.py +15 -2
  24. agno/db/redis/schemas.py +4 -0
  25. agno/db/schemas/memory.py +13 -0
  26. agno/db/singlestore/schemas.py +11 -0
  27. agno/db/singlestore/singlestore.py +79 -5
  28. agno/db/sqlite/async_sqlite.py +97 -19
  29. agno/db/sqlite/schemas.py +10 -0
  30. agno/db/sqlite/sqlite.py +79 -2
  31. agno/db/surrealdb/surrealdb.py +8 -0
  32. agno/knowledge/chunking/semantic.py +7 -2
  33. agno/knowledge/embedder/nebius.py +1 -1
  34. agno/knowledge/knowledge.py +57 -86
  35. agno/knowledge/reader/csv_reader.py +7 -9
  36. agno/knowledge/reader/docx_reader.py +5 -5
  37. agno/knowledge/reader/field_labeled_csv_reader.py +16 -18
  38. agno/knowledge/reader/json_reader.py +5 -4
  39. agno/knowledge/reader/markdown_reader.py +8 -8
  40. agno/knowledge/reader/pdf_reader.py +11 -11
  41. agno/knowledge/reader/pptx_reader.py +5 -5
  42. agno/knowledge/reader/s3_reader.py +3 -3
  43. agno/knowledge/reader/text_reader.py +8 -8
  44. agno/knowledge/reader/web_search_reader.py +1 -48
  45. agno/knowledge/reader/website_reader.py +10 -10
  46. agno/models/anthropic/claude.py +319 -28
  47. agno/models/aws/claude.py +32 -0
  48. agno/models/azure/openai_chat.py +19 -10
  49. agno/models/base.py +612 -545
  50. agno/models/cerebras/cerebras.py +8 -11
  51. agno/models/cohere/chat.py +27 -1
  52. agno/models/google/gemini.py +39 -7
  53. agno/models/groq/groq.py +25 -11
  54. agno/models/meta/llama.py +20 -9
  55. agno/models/meta/llama_openai.py +3 -19
  56. agno/models/nebius/nebius.py +4 -4
  57. agno/models/openai/chat.py +30 -14
  58. agno/models/openai/responses.py +10 -13
  59. agno/models/response.py +1 -0
  60. agno/models/vertexai/claude.py +26 -0
  61. agno/os/app.py +8 -19
  62. agno/os/router.py +54 -0
  63. agno/os/routers/knowledge/knowledge.py +2 -2
  64. agno/os/schema.py +2 -2
  65. agno/session/agent.py +57 -92
  66. agno/session/summary.py +1 -1
  67. agno/session/team.py +62 -112
  68. agno/session/workflow.py +353 -57
  69. agno/team/team.py +227 -125
  70. agno/tools/models/nebius.py +5 -5
  71. agno/tools/models_labs.py +20 -10
  72. agno/tools/nano_banana.py +151 -0
  73. agno/tools/yfinance.py +12 -11
  74. agno/utils/http.py +111 -0
  75. agno/utils/media.py +11 -0
  76. agno/utils/models/claude.py +8 -0
  77. agno/utils/print_response/agent.py +33 -12
  78. agno/utils/print_response/team.py +22 -12
  79. agno/vectordb/couchbase/couchbase.py +6 -2
  80. agno/workflow/condition.py +13 -0
  81. agno/workflow/loop.py +13 -0
  82. agno/workflow/parallel.py +13 -0
  83. agno/workflow/router.py +13 -0
  84. agno/workflow/step.py +120 -20
  85. agno/workflow/steps.py +13 -0
  86. agno/workflow/workflow.py +76 -63
  87. {agno-2.2.13.dist-info → agno-2.3.1.dist-info}/METADATA +6 -2
  88. {agno-2.2.13.dist-info → agno-2.3.1.dist-info}/RECORD +91 -88
  89. agno/tools/googlesearch.py +0 -98
  90. {agno-2.2.13.dist-info → agno-2.3.1.dist-info}/WHEEL +0 -0
  91. {agno-2.2.13.dist-info → agno-2.3.1.dist-info}/licenses/LICENSE +0 -0
  92. {agno-2.2.13.dist-info → agno-2.3.1.dist-info}/top_level.txt +0 -0
agno/session/workflow.py CHANGED
@@ -2,10 +2,16 @@ from __future__ import annotations
2
2
 
3
3
  import time
4
4
  from dataclasses import dataclass
5
- from typing import Any, Dict, List, Mapping, Optional, Tuple
5
+ from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
6
6
 
7
+ from pydantic import BaseModel
8
+
9
+ from agno.models.message import Message
10
+ from agno.run.agent import RunOutput
11
+ from agno.run.base import RunStatus
12
+ from agno.run.team import TeamRunOutput
7
13
  from agno.run.workflow import WorkflowRunOutput
8
- from agno.utils.log import logger
14
+ from agno.utils.log import log_debug, logger
9
15
 
10
16
 
11
17
  @dataclass
@@ -37,6 +43,67 @@ class WorkflowSession:
37
43
  # The unix timestamp when this session was last updated
38
44
  updated_at: Optional[int] = None
39
45
 
46
+ def to_dict(self) -> Dict[str, Any]:
47
+ """Convert to dictionary for storage, serializing runs to dicts"""
48
+
49
+ runs_data = None
50
+ if self.runs:
51
+ runs_data = []
52
+ for run in self.runs:
53
+ try:
54
+ runs_data.append(run.to_dict())
55
+ except Exception as e:
56
+ raise ValueError(f"Serialization failed: {str(e)}")
57
+
58
+ return {
59
+ "session_id": self.session_id,
60
+ "user_id": self.user_id,
61
+ "workflow_id": self.workflow_id,
62
+ "workflow_name": self.workflow_name,
63
+ "runs": runs_data,
64
+ "session_data": self.session_data,
65
+ "workflow_data": self.workflow_data,
66
+ "metadata": self.metadata,
67
+ "created_at": self.created_at,
68
+ "updated_at": self.updated_at,
69
+ }
70
+
71
+ @classmethod
72
+ def from_dict(cls, data: Mapping[str, Any]) -> Optional[WorkflowSession]:
73
+ """Create WorkflowSession from dictionary, deserializing runs from dicts"""
74
+ if data is None or data.get("session_id") is None:
75
+ logger.warning("WorkflowSession is missing session_id")
76
+ return None
77
+
78
+ # Deserialize runs from dictionaries back to WorkflowRunOutput objects
79
+ runs_data = data.get("runs")
80
+ runs: Optional[List[WorkflowRunOutput]] = None
81
+
82
+ if runs_data is not None:
83
+ runs = []
84
+ for run_item in runs_data:
85
+ if isinstance(run_item, WorkflowRunOutput):
86
+ # Already a WorkflowRunOutput object (from deserialize_session_json_fields)
87
+ runs.append(run_item)
88
+ elif isinstance(run_item, dict):
89
+ # Still a dictionary, needs to be converted
90
+ runs.append(WorkflowRunOutput.from_dict(run_item))
91
+ else:
92
+ logger.warning(f"Unexpected run item type: {type(run_item)}")
93
+
94
+ return cls(
95
+ session_id=data.get("session_id"), # type: ignore
96
+ user_id=data.get("user_id"),
97
+ workflow_id=data.get("workflow_id"),
98
+ workflow_name=data.get("workflow_name"),
99
+ runs=runs,
100
+ session_data=data.get("session_data"),
101
+ workflow_data=data.get("workflow_data"),
102
+ metadata=data.get("metadata"),
103
+ created_at=data.get("created_at"),
104
+ updated_at=data.get("updated_at"),
105
+ )
106
+
40
107
  def __post_init__(self):
41
108
  if self.runs is None:
42
109
  self.runs = []
@@ -84,8 +151,6 @@ class WorkflowSession:
84
151
  if not self.runs:
85
152
  return []
86
153
 
87
- from agno.run.base import RunStatus
88
-
89
154
  # Get completed runs only (exclude current/pending run)
90
155
  completed_runs = [run for run in self.runs if run.status == RunStatus.completed]
91
156
 
@@ -143,63 +208,294 @@ class WorkflowSession:
143
208
 
144
209
  return "\n".join(context_parts)
145
210
 
146
- def to_dict(self) -> Dict[str, Any]:
147
- """Convert to dictionary for storage, serializing runs to dicts"""
211
+ def get_messages_from_agent_runs(
212
+ self,
213
+ runs: List[RunOutput],
214
+ last_n_runs: Optional[int] = None,
215
+ limit: Optional[int] = None,
216
+ skip_roles: Optional[List[str]] = None,
217
+ skip_statuses: Optional[List[RunStatus]] = None,
218
+ skip_history_messages: bool = True,
219
+ ) -> List[Message]:
220
+ """Return the messages belonging to the given agent runs that fit the given criteria.
148
221
 
149
- runs_data = None
150
- if self.runs:
151
- runs_data = []
222
+ Args:
223
+ runs: The list of agent runs to get the messages from.
224
+ last_n_runs: Number of recent runs to include. If None, all runs will be considered.
225
+ limit: Number of messages to include. If None, all messages will be included.
226
+ skip_roles: Roles to skip.
227
+ skip_statuses: Statuses to skip.
228
+ skip_history_messages: Whether to skip history messages.
229
+
230
+ Returns:
231
+ A list of messages from the given agent runs.
232
+ """
233
+
234
+ def _should_skip_message(
235
+ message: Message, skip_roles: Optional[List[str]] = None, skip_history_messages: bool = True
236
+ ) -> bool:
237
+ """Logic to determine if a message should be skipped"""
238
+ # Skip messages that were tagged as history in previous runs
239
+ if hasattr(message, "from_history") and message.from_history and skip_history_messages:
240
+ return True
241
+
242
+ # Skip messages with specified role
243
+ if skip_roles and message.role in skip_roles:
244
+ return True
245
+
246
+ return False
247
+
248
+ # Filter by status
249
+ if skip_statuses:
250
+ runs = [run for run in runs if hasattr(run, "status") and run.status not in skip_statuses] # type: ignore
251
+
252
+ messages_from_history = []
253
+ system_message = None
254
+
255
+ # Limit the number of messages returned if limit is set
256
+ if limit is not None:
257
+ for run_response in runs:
258
+ if not run_response or not run_response.messages:
259
+ continue
260
+
261
+ for message in run_response.messages or []:
262
+ if _should_skip_message(message, skip_roles, skip_history_messages):
263
+ continue
264
+
265
+ if message.role == "system":
266
+ # Only add the system message once
267
+ if system_message is None:
268
+ system_message = message
269
+ else:
270
+ messages_from_history.append(message)
271
+
272
+ if system_message:
273
+ messages_from_history = [system_message] + messages_from_history[
274
+ -(limit - 1) :
275
+ ] # Grab one less message then add the system message
276
+ else:
277
+ messages_from_history = messages_from_history[-limit:]
278
+
279
+ # Remove tool result messages that don't have an associated assistant message with tool calls
280
+ while len(messages_from_history) > 0 and messages_from_history[0].role == "tool":
281
+ messages_from_history.pop(0)
282
+
283
+ # If limit is not set, return all messages
284
+ else:
285
+ runs_to_process = runs[-last_n_runs:] if last_n_runs is not None else runs
286
+ for run_response in runs_to_process:
287
+ if not run_response or not run_response.messages:
288
+ continue
289
+
290
+ for message in run_response.messages or []:
291
+ if _should_skip_message(message, skip_roles, skip_history_messages):
292
+ continue
293
+
294
+ if message.role == "system":
295
+ # Only add the system message once
296
+ if system_message is None:
297
+ system_message = message
298
+ messages_from_history.append(system_message)
299
+ else:
300
+ messages_from_history.append(message)
301
+
302
+ log_debug(f"Getting messages from previous runs: {len(messages_from_history)}")
303
+ return messages_from_history
304
+
305
+ def get_messages_from_team_runs(
306
+ self,
307
+ team_id: str,
308
+ runs: List[TeamRunOutput],
309
+ last_n_runs: Optional[int] = None,
310
+ limit: Optional[int] = None,
311
+ skip_roles: Optional[List[str]] = None,
312
+ skip_statuses: Optional[List[RunStatus]] = None,
313
+ skip_history_messages: bool = True,
314
+ skip_member_messages: bool = True,
315
+ ) -> List[Message]:
316
+ """Return the messages in the given team runs that fit the given criteria.
317
+
318
+ Args:
319
+ team_id: The ID of the contextual team.
320
+ runs: The list of team runs to get the messages from.
321
+ last_n_runs: Number of recent runs to include. If None, all runs will be considered.
322
+ limit: Number of messages to include. If None, all messages will be included.
323
+ skip_roles: Roles to skip.
324
+ skip_statuses: Statuses to skip.
325
+ skip_history_messages: Whether to skip history messages.
326
+ skip_member_messages: Whether to skip messages from members of the team.
327
+
328
+ Returns:
329
+ A list of messages from the given team runs.
330
+ """
331
+
332
+ def _should_skip_message(
333
+ message: Message, skip_roles: Optional[List[str]] = None, skip_history_messages: bool = True
334
+ ) -> bool:
335
+ """Logic to determine if a message should be skipped"""
336
+ # Skip messages that were tagged as history in previous runs
337
+ if hasattr(message, "from_history") and message.from_history and skip_history_messages:
338
+ return True
339
+
340
+ # Skip messages with specified role
341
+ if skip_roles and message.role in skip_roles:
342
+ return True
343
+
344
+ return False
345
+
346
+ # Filter for top-level runs (main team runs or agent runs when sharing session)
347
+ if skip_member_messages:
348
+ session_runs = [run for run in runs if run.team_id == team_id]
349
+
350
+ # Filter runs by status
351
+ if skip_statuses:
352
+ session_runs = [run for run in session_runs if hasattr(run, "status") and run.status not in skip_statuses]
353
+
354
+ messages_from_history = []
355
+ system_message = None
356
+
357
+ # Limit the number of messages returned if limit is set
358
+ if limit is not None:
359
+ for run_response in session_runs:
360
+ if not run_response or not run_response.messages:
361
+ continue
362
+
363
+ for message in run_response.messages or []:
364
+ if _should_skip_message(message, skip_roles, skip_history_messages):
365
+ continue
366
+
367
+ if message.role == "system":
368
+ # Only add the system message once
369
+ if system_message is None:
370
+ system_message = message
371
+ else:
372
+ messages_from_history.append(message)
373
+
374
+ if system_message:
375
+ messages_from_history = [system_message] + messages_from_history[
376
+ -(limit - 1) :
377
+ ] # Grab one less message then add the system message
378
+ else:
379
+ messages_from_history = messages_from_history[-limit:]
380
+
381
+ # Remove tool result messages that don't have an associated assistant message with tool calls
382
+ while len(messages_from_history) > 0 and messages_from_history[0].role == "tool":
383
+ messages_from_history.pop(0)
384
+ else:
385
+ # Filter by last_n runs
386
+ runs_to_process = session_runs[-last_n_runs:] if last_n_runs is not None else session_runs
387
+
388
+ for run_response in runs_to_process:
389
+ if not (run_response and run_response.messages):
390
+ continue
391
+
392
+ for message in run_response.messages or []:
393
+ if _should_skip_message(message, skip_roles, skip_history_messages):
394
+ continue
395
+
396
+ if message.role == "system":
397
+ # Only add the system message once
398
+ if system_message is None:
399
+ system_message = message
400
+ messages_from_history.append(system_message)
401
+ else:
402
+ messages_from_history.append(message)
403
+
404
+ log_debug(f"Getting messages from previous runs: {len(messages_from_history)}")
405
+ return messages_from_history
406
+
407
+ def get_messages(
408
+ self,
409
+ agent_id: Optional[str] = None,
410
+ team_id: Optional[str] = None,
411
+ last_n_runs: Optional[int] = None,
412
+ limit: Optional[int] = None,
413
+ skip_roles: Optional[List[str]] = None,
414
+ skip_statuses: Optional[List[RunStatus]] = None,
415
+ skip_history_messages: bool = True,
416
+ skip_member_messages: bool = True,
417
+ ) -> List[Message]:
418
+ """Return the messages belonging to the session that fit the given criteria.
419
+
420
+ Args:
421
+ agent_id: The ID of the agent to get the messages for.
422
+ team_id: The ID of the team to get the messages for.
423
+ last_n_runs: Number of recent runs to include. If None, all runs will be considered.
424
+ limit: Number of messages to include. If None, all messages will be included.
425
+ skip_roles: Roles to skip.
426
+ skip_statuses: Statuses to skip.
427
+ skip_history_messages: Whether to skip history messages.
428
+ skip_member_messages: Whether to skip messages from members of the team.
429
+
430
+ Returns:
431
+ A list of messages from the session.
432
+ """
433
+ if agent_id and team_id:
434
+ raise ValueError("agent_id and team_id cannot be used together")
435
+
436
+ if not self.runs:
437
+ return []
438
+
439
+ if agent_id:
440
+ agent_runs: List[RunOutput] = []
152
441
  for run in self.runs:
153
- try:
154
- runs_data.append(run.to_dict())
155
- except Exception as e:
156
- raise ValueError(f"Serialization failed: {str(e)}")
442
+ if run.step_executor_runs:
443
+ for executor_run in run.step_executor_runs:
444
+ if isinstance(executor_run, RunOutput) and executor_run.agent_id == agent_id:
445
+ agent_runs.append(executor_run)
446
+ return self.get_messages_from_agent_runs(
447
+ runs=agent_runs,
448
+ last_n_runs=last_n_runs,
449
+ limit=limit,
450
+ skip_roles=skip_roles,
451
+ skip_statuses=skip_statuses,
452
+ skip_history_messages=skip_history_messages,
453
+ )
454
+
455
+ elif team_id:
456
+ team_runs: List[TeamRunOutput] = []
457
+ for run in self.runs:
458
+ if run.step_executor_runs:
459
+ for executor_run in run.step_executor_runs:
460
+ if isinstance(executor_run, TeamRunOutput) and executor_run.team_id == team_id:
461
+ team_runs.append(executor_run)
462
+ return self.get_messages_from_team_runs(
463
+ team_id=team_id,
464
+ runs=team_runs,
465
+ last_n_runs=last_n_runs,
466
+ limit=limit,
467
+ skip_roles=skip_roles,
468
+ skip_statuses=skip_statuses,
469
+ skip_history_messages=skip_history_messages,
470
+ skip_member_messages=skip_member_messages,
471
+ )
157
472
 
158
- return {
159
- "session_id": self.session_id,
160
- "user_id": self.user_id,
161
- "workflow_id": self.workflow_id,
162
- "workflow_name": self.workflow_name,
163
- "runs": runs_data,
164
- "session_data": self.session_data,
165
- "workflow_data": self.workflow_data,
166
- "metadata": self.metadata,
167
- "created_at": self.created_at,
168
- "updated_at": self.updated_at,
169
- }
473
+ else:
474
+ raise ValueError("agent_id or team_id must be provided")
170
475
 
171
- @classmethod
172
- def from_dict(cls, data: Mapping[str, Any]) -> Optional[WorkflowSession]:
173
- """Create WorkflowSession from dictionary, deserializing runs from dicts"""
174
- if data is None or data.get("session_id") is None:
175
- logger.warning("WorkflowSession is missing session_id")
176
- return None
476
+ def get_chat_history(self, last_n_runs: Optional[int] = None) -> List[WorkflowChatInteraction]:
477
+ """Return a list of dictionaries containing the input and output for each run in the session.
177
478
 
178
- # Deserialize runs from dictionaries back to WorkflowRunOutput objects
179
- runs_data = data.get("runs")
180
- runs: Optional[List[WorkflowRunOutput]] = None
479
+ Args:
480
+ last_n_runs: Number of recent runs to include. If None, all runs will be considered.
181
481
 
182
- if runs_data is not None:
183
- runs = []
184
- for run_item in runs_data:
185
- if isinstance(run_item, WorkflowRunOutput):
186
- # Already a WorkflowRunOutput object (from deserialize_session_json_fields)
187
- runs.append(run_item)
188
- elif isinstance(run_item, dict):
189
- # Still a dictionary, needs to be converted
190
- runs.append(WorkflowRunOutput.from_dict(run_item))
191
- else:
192
- logger.warning(f"Unexpected run item type: {type(run_item)}")
482
+ Returns:
483
+ A list of WorkflowChatInteraction objects.
484
+ """
485
+ if not self.runs:
486
+ return []
193
487
 
194
- return cls(
195
- session_id=data.get("session_id"), # type: ignore
196
- user_id=data.get("user_id"),
197
- workflow_id=data.get("workflow_id"),
198
- workflow_name=data.get("workflow_name"),
199
- runs=runs,
200
- session_data=data.get("session_data"),
201
- workflow_data=data.get("workflow_data"),
202
- metadata=data.get("metadata"),
203
- created_at=data.get("created_at"),
204
- updated_at=data.get("updated_at"),
205
- )
488
+ runs = self.runs
489
+
490
+ if last_n_runs is not None:
491
+ runs = self.runs[-last_n_runs:]
492
+
493
+ return [
494
+ WorkflowChatInteraction(input=run.input, output=run.content) for run in runs if run.input and run.content
495
+ ]
496
+
497
+
498
+ @dataclass
499
+ class WorkflowChatInteraction:
500
+ input: Union[str, Dict[str, Any], List[Any], BaseModel]
501
+ output: Any