agno 2.1.4__py3-none-any.whl → 2.1.6__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 (95) hide show
  1. agno/agent/agent.py +1775 -538
  2. agno/db/async_postgres/__init__.py +3 -0
  3. agno/db/async_postgres/async_postgres.py +1668 -0
  4. agno/db/async_postgres/schemas.py +124 -0
  5. agno/db/async_postgres/utils.py +289 -0
  6. agno/db/base.py +237 -2
  7. agno/db/dynamo/dynamo.py +2 -2
  8. agno/db/firestore/firestore.py +2 -2
  9. agno/db/firestore/utils.py +4 -2
  10. agno/db/gcs_json/gcs_json_db.py +2 -2
  11. agno/db/in_memory/in_memory_db.py +2 -2
  12. agno/db/json/json_db.py +2 -2
  13. agno/db/migrations/v1_to_v2.py +43 -13
  14. agno/db/mongo/mongo.py +14 -6
  15. agno/db/mongo/utils.py +0 -4
  16. agno/db/mysql/mysql.py +23 -13
  17. agno/db/postgres/postgres.py +17 -6
  18. agno/db/redis/redis.py +2 -2
  19. agno/db/singlestore/singlestore.py +19 -10
  20. agno/db/sqlite/sqlite.py +22 -12
  21. agno/db/sqlite/utils.py +8 -3
  22. agno/db/surrealdb/__init__.py +3 -0
  23. agno/db/surrealdb/metrics.py +292 -0
  24. agno/db/surrealdb/models.py +259 -0
  25. agno/db/surrealdb/queries.py +71 -0
  26. agno/db/surrealdb/surrealdb.py +1193 -0
  27. agno/db/surrealdb/utils.py +87 -0
  28. agno/eval/accuracy.py +50 -43
  29. agno/eval/performance.py +6 -3
  30. agno/eval/reliability.py +6 -3
  31. agno/eval/utils.py +33 -16
  32. agno/exceptions.py +8 -2
  33. agno/knowledge/knowledge.py +260 -46
  34. agno/knowledge/reader/pdf_reader.py +4 -6
  35. agno/knowledge/reader/reader_factory.py +2 -3
  36. agno/memory/manager.py +254 -46
  37. agno/models/anthropic/claude.py +37 -0
  38. agno/os/app.py +8 -7
  39. agno/os/interfaces/a2a/router.py +3 -5
  40. agno/os/interfaces/agui/router.py +4 -1
  41. agno/os/interfaces/agui/utils.py +27 -6
  42. agno/os/interfaces/slack/router.py +2 -4
  43. agno/os/mcp.py +98 -41
  44. agno/os/router.py +23 -0
  45. agno/os/routers/evals/evals.py +52 -20
  46. agno/os/routers/evals/utils.py +14 -14
  47. agno/os/routers/knowledge/knowledge.py +130 -9
  48. agno/os/routers/knowledge/schemas.py +57 -0
  49. agno/os/routers/memory/memory.py +116 -44
  50. agno/os/routers/metrics/metrics.py +16 -6
  51. agno/os/routers/session/session.py +65 -22
  52. agno/os/schema.py +36 -0
  53. agno/os/utils.py +64 -11
  54. agno/reasoning/anthropic.py +80 -0
  55. agno/reasoning/gemini.py +73 -0
  56. agno/reasoning/openai.py +5 -0
  57. agno/reasoning/vertexai.py +76 -0
  58. agno/session/workflow.py +3 -3
  59. agno/team/team.py +968 -179
  60. agno/tools/googlesheets.py +20 -5
  61. agno/tools/mcp_toolbox.py +3 -3
  62. agno/tools/scrapegraph.py +1 -1
  63. agno/utils/models/claude.py +3 -1
  64. agno/utils/streamlit.py +1 -1
  65. agno/vectordb/base.py +22 -1
  66. agno/vectordb/cassandra/cassandra.py +9 -0
  67. agno/vectordb/chroma/chromadb.py +26 -6
  68. agno/vectordb/clickhouse/clickhousedb.py +9 -1
  69. agno/vectordb/couchbase/couchbase.py +11 -0
  70. agno/vectordb/lancedb/lance_db.py +20 -0
  71. agno/vectordb/langchaindb/langchaindb.py +11 -0
  72. agno/vectordb/lightrag/lightrag.py +9 -0
  73. agno/vectordb/llamaindex/llamaindexdb.py +15 -1
  74. agno/vectordb/milvus/milvus.py +23 -0
  75. agno/vectordb/mongodb/mongodb.py +22 -0
  76. agno/vectordb/pgvector/pgvector.py +19 -0
  77. agno/vectordb/pineconedb/pineconedb.py +35 -4
  78. agno/vectordb/qdrant/qdrant.py +24 -0
  79. agno/vectordb/singlestore/singlestore.py +25 -17
  80. agno/vectordb/surrealdb/surrealdb.py +18 -2
  81. agno/vectordb/upstashdb/upstashdb.py +26 -1
  82. agno/vectordb/weaviate/weaviate.py +18 -0
  83. agno/workflow/condition.py +4 -0
  84. agno/workflow/loop.py +4 -0
  85. agno/workflow/parallel.py +4 -0
  86. agno/workflow/router.py +4 -0
  87. agno/workflow/step.py +30 -14
  88. agno/workflow/steps.py +4 -0
  89. agno/workflow/types.py +2 -2
  90. agno/workflow/workflow.py +328 -61
  91. {agno-2.1.4.dist-info → agno-2.1.6.dist-info}/METADATA +100 -41
  92. {agno-2.1.4.dist-info → agno-2.1.6.dist-info}/RECORD +95 -82
  93. {agno-2.1.4.dist-info → agno-2.1.6.dist-info}/WHEEL +0 -0
  94. {agno-2.1.4.dist-info → agno-2.1.6.dist-info}/licenses/LICENSE +0 -0
  95. {agno-2.1.4.dist-info → agno-2.1.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,259 @@
1
+ from dataclasses import asdict
2
+ from datetime import date, datetime, timezone
3
+ from textwrap import dedent
4
+ from typing import List, Literal, Optional, Sequence
5
+
6
+ from surrealdb import RecordID
7
+
8
+ from agno.db.base import SessionType
9
+ from agno.db.schemas.evals import EvalRunRecord
10
+ from agno.db.schemas.knowledge import KnowledgeRow
11
+ from agno.db.schemas.memory import UserMemory
12
+ from agno.session import Session
13
+ from agno.session.agent import AgentSession
14
+ from agno.session.team import TeamSession
15
+ from agno.session.workflow import WorkflowSession
16
+
17
+ TableType = Literal[
18
+ "agents",
19
+ "evals",
20
+ "knowledge",
21
+ "memories",
22
+ "metrics",
23
+ "sessions",
24
+ "teams",
25
+ "users",
26
+ "workflows",
27
+ ]
28
+
29
+
30
+ def deserialize_record_id(record: dict, agno_field: str, surreal_field: Optional[str] = None) -> dict:
31
+ if surreal_field is None:
32
+ surreal_field = agno_field
33
+ x = record.get(surreal_field)
34
+ if isinstance(x, RecordID):
35
+ record[agno_field] = x.id
36
+ if agno_field != surreal_field:
37
+ del record[surreal_field]
38
+ return record
39
+
40
+
41
+ def surrealize_dates(record: dict) -> dict:
42
+ copy = record.copy()
43
+ for key, value in copy.items():
44
+ if isinstance(value, date):
45
+ copy[key] = datetime.combine(value, datetime.min.time()).replace(tzinfo=timezone.utc)
46
+ elif key in ["created_at", "updated_at"] and isinstance(value, (int, float)):
47
+ copy[key] = datetime.fromtimestamp(value).replace(tzinfo=timezone.utc)
48
+ elif key in ["created_at", "updated_at"] and isinstance(value, str):
49
+ # Handle ISO string format - convert back to datetime object for SurrealDB
50
+ try:
51
+ dt = datetime.fromisoformat(value)
52
+ if dt.tzinfo is None:
53
+ dt = dt.replace(tzinfo=timezone.utc)
54
+ copy[key] = dt
55
+ except ValueError:
56
+ # If it's not a valid ISO format, leave it as is
57
+ pass
58
+ elif key in ["created_at", "updated_at"] and value is None:
59
+ # Set current time for None datetime fields
60
+ copy[key] = datetime.now(timezone.utc)
61
+ elif isinstance(value, datetime):
62
+ copy[key] = value.replace(tzinfo=timezone.utc)
63
+ return copy
64
+
65
+
66
+ def desurrealize_dates(record: dict) -> dict:
67
+ copy = record.copy()
68
+ for key, value in copy.items():
69
+ if isinstance(value, datetime):
70
+ copy[key] = int(value.timestamp())
71
+ return copy
72
+
73
+
74
+ def serialize_session(session: Session, table_names: dict[TableType, str]) -> dict:
75
+ _dict = session.to_dict()
76
+
77
+ if session.session_id is not None:
78
+ _dict["id"] = RecordID(table_names["sessions"], session.session_id)
79
+ del _dict["session_id"]
80
+
81
+ if isinstance(session, AgentSession):
82
+ _dict["agent"] = RecordID(table_names["agents"], session.agent_id)
83
+ del _dict["agent_id"]
84
+ elif isinstance(session, TeamSession):
85
+ _dict["team"] = RecordID(table_names["teams"], session.team_id)
86
+ del _dict["team_id"]
87
+ elif isinstance(session, WorkflowSession):
88
+ _dict["workflow"] = RecordID(table_names["workflows"], session.workflow_id)
89
+ del _dict["workflow_id"]
90
+
91
+ # surrealize dates
92
+ _dict = surrealize_dates(_dict)
93
+
94
+ return _dict
95
+
96
+
97
+ def desurrealize_session(session_raw: dict, session_type: Optional[SessionType] = None) -> dict:
98
+ session_raw = deserialize_record_id(session_raw, "session_id", "id")
99
+ if session_type == SessionType.AGENT:
100
+ session_raw = deserialize_record_id(session_raw, "agent_id", "agent")
101
+ elif session_type == SessionType.TEAM:
102
+ session_raw = deserialize_record_id(session_raw, "team_id", "team")
103
+ elif session_type == SessionType.WORKFLOW:
104
+ session_raw = deserialize_record_id(session_raw, "workflow_id", "workflow")
105
+
106
+ session_raw = desurrealize_dates(session_raw)
107
+
108
+ if session_raw.get("agent_id"):
109
+ session_raw["session_type"] = SessionType.AGENT
110
+ elif session_raw.get("team_id"):
111
+ session_raw["session_type"] = SessionType.TEAM
112
+ elif session_raw.get("workflow_id"):
113
+ session_raw["session_type"] = SessionType.WORKFLOW
114
+
115
+ return session_raw
116
+
117
+
118
+ def deserialize_session(session_type: SessionType, session_raw: dict) -> Optional[Session]:
119
+ session_raw = desurrealize_session(session_raw, session_type)
120
+
121
+ if session_type == SessionType.AGENT:
122
+ return AgentSession.from_dict(session_raw)
123
+ elif session_type == SessionType.TEAM:
124
+ return TeamSession.from_dict(session_raw)
125
+ elif session_type == SessionType.WORKFLOW:
126
+ return WorkflowSession.from_dict(session_raw)
127
+ else:
128
+ raise ValueError(f"Invalid session type: {session_type}")
129
+
130
+
131
+ def deserialize_sessions(session_type: SessionType, sessions_raw: List[dict]) -> List[Session]:
132
+ return [x for x in [deserialize_session(session_type, x) for x in sessions_raw] if x is not None]
133
+
134
+
135
+ def get_session_type(session: Session) -> SessionType:
136
+ if isinstance(session, AgentSession):
137
+ return SessionType.AGENT
138
+ elif isinstance(session, TeamSession):
139
+ return SessionType.TEAM
140
+ elif isinstance(session, WorkflowSession):
141
+ return SessionType.WORKFLOW
142
+ else:
143
+ raise ValueError(f"Invalid session instance: {type(session)}")
144
+
145
+
146
+ def desurrealize_user_memory(memory_raw: dict) -> dict:
147
+ copy = memory_raw.copy()
148
+
149
+ copy = deserialize_record_id(copy, "memory_id", "id")
150
+ copy = deserialize_record_id(copy, "user_id", "user")
151
+ copy = deserialize_record_id(copy, "agent_id", "agent")
152
+ copy = deserialize_record_id(copy, "team_id", "team")
153
+ copy = deserialize_record_id(copy, "workflow_id", "workflow")
154
+
155
+ # TODO: is this ok? or should we cast datetimes to int? Like in desurrealize_session
156
+ # copy = desurrealize_dates(copy)
157
+ updated_at = copy.get("updated_at")
158
+ if not isinstance(updated_at, str):
159
+ copy["updated_at"] = str(updated_at)
160
+
161
+ return copy
162
+
163
+
164
+ def deserialize_user_memory(memory_raw: dict) -> UserMemory:
165
+ return UserMemory.from_dict(desurrealize_user_memory(memory_raw))
166
+
167
+
168
+ def deserialize_user_memories(memories_raw: Sequence[dict]) -> List[UserMemory]:
169
+ return [deserialize_user_memory(x) for x in memories_raw]
170
+
171
+
172
+ def serialize_user_memory(memory: UserMemory, memory_table_name: str, user_table_name: str) -> dict:
173
+ dict_ = asdict(memory)
174
+ if memory.memory_id is not None:
175
+ dict_["id"] = RecordID(memory_table_name, memory.memory_id)
176
+ del dict_["memory_id"]
177
+ if memory.user_id is not None:
178
+ dict_["user"] = RecordID(user_table_name, memory.user_id)
179
+ del dict_["user_id"]
180
+
181
+ # surrealize dates
182
+ dict_ = surrealize_dates(dict_)
183
+
184
+ return dict_
185
+
186
+
187
+ def deserialize_knowledge_row(knowledge_row_raw: dict) -> KnowledgeRow:
188
+ copy = knowledge_row_raw.copy()
189
+
190
+ copy = deserialize_record_id(copy, "id")
191
+ copy = desurrealize_dates(copy)
192
+
193
+ return KnowledgeRow.model_validate(copy)
194
+
195
+
196
+ def serialize_knowledge_row(knowledge_row: KnowledgeRow, knowledge_table_name: str) -> dict:
197
+ dict_ = knowledge_row.model_dump()
198
+ if knowledge_row.id is not None:
199
+ dict_["id"] = RecordID(knowledge_table_name, knowledge_row.id)
200
+
201
+ # surrealize dates
202
+ dict_ = surrealize_dates(dict_)
203
+
204
+ return dict_
205
+
206
+
207
+ def desurrealize_eval_run_record(eval_run_record_raw: dict) -> dict:
208
+ copy = eval_run_record_raw.copy()
209
+
210
+ copy = deserialize_record_id(copy, "run_id", "id")
211
+ copy = deserialize_record_id(copy, "agent_id", "agent")
212
+ copy = deserialize_record_id(copy, "team_id", "team")
213
+ copy = deserialize_record_id(copy, "workflow_id", "workflow")
214
+
215
+ return copy
216
+
217
+
218
+ def deserialize_eval_run_record(eval_run_record_raw: dict) -> EvalRunRecord:
219
+ return EvalRunRecord.model_validate(desurrealize_eval_run_record(eval_run_record_raw))
220
+
221
+
222
+ def serialize_eval_run_record(eval_run_record: EvalRunRecord, table_names: dict[TableType, str]) -> dict:
223
+ dict_ = eval_run_record.model_dump()
224
+ if eval_run_record.run_id is not None:
225
+ dict_["id"] = RecordID(table_names["evals"], eval_run_record.run_id)
226
+ del dict_["run_id"]
227
+ if eval_run_record.agent_id is not None:
228
+ dict_["agent"] = RecordID(table_names["agents"], eval_run_record.agent_id)
229
+ del dict_["agent_id"]
230
+ if eval_run_record.team_id is not None:
231
+ dict_["team"] = RecordID(table_names["teams"], eval_run_record.team_id)
232
+ del dict_["team_id"]
233
+ if eval_run_record.workflow_id is not None:
234
+ dict_["workflow"] = RecordID(table_names["workflows"], eval_run_record.workflow_id)
235
+ del dict_["workflow_id"]
236
+ return dict_
237
+
238
+
239
+ def get_schema(table_type: TableType, table_name: str) -> str:
240
+ define_table = f"DEFINE TABLE {table_name} SCHEMALESS;"
241
+ if table_type == "memories":
242
+ return dedent(f"""
243
+ {define_table}
244
+ DEFINE FIELD OVERWRITE updated_at ON {table_name} TYPE datetime VALUE time::now();
245
+ """)
246
+ elif table_type == "knowledge":
247
+ return dedent(f"""
248
+ {define_table}
249
+ DEFINE FIELD OVERWRITE created_at ON {table_name} TYPE datetime VALUE time::now();
250
+ DEFINE FIELD OVERWRITE updated_at ON {table_name} TYPE datetime VALUE time::now();
251
+ """)
252
+ elif table_type == "sessions":
253
+ return dedent(f"""
254
+ {define_table}
255
+ DEFINE FIELD OVERWRITE created_at ON {table_name} TYPE datetime VALUE time::now();
256
+ DEFINE FIELD OVERWRITE updated_at ON {table_name} TYPE datetime VALUE time::now();
257
+ """)
258
+ else:
259
+ return define_table
@@ -0,0 +1,71 @@
1
+ from textwrap import dedent
2
+ from typing import Any, Final, Literal, Optional
3
+
4
+ OPERATOR = Literal["=", "!=", "<=", ">=", "~", "IN", "CONTAINSANY"]
5
+
6
+ COUNT_QUERY: Final[str] = dedent("""
7
+ RETURN (
8
+ SELECT count(id) AS count
9
+ {group_fields}
10
+ FROM {table}
11
+ {where_clause}
12
+ {group_clause}
13
+ )[0] OR {{count: 0}}
14
+ """)
15
+
16
+
17
+ class WhereClause:
18
+ def __init__(self):
19
+ self._conditions = []
20
+ self._params = {}
21
+ self._param_count = 0
22
+
23
+ def _add_filter(self, field: str, operator: str, value: Any):
24
+ param_name = f"p{self._param_count}"
25
+ self._params[param_name] = value
26
+ self._param_count += 1
27
+
28
+ condition = f"{field} {operator} ${param_name}"
29
+ if not self._conditions:
30
+ self._conditions.append(condition)
31
+ else:
32
+ self._conditions.append("AND")
33
+ self._conditions.append(condition)
34
+ return self
35
+
36
+ def and_(self, field: str, value: Any, operator: OPERATOR = "="):
37
+ return self._add_filter(field, operator, value)
38
+
39
+ def build(self) -> tuple[str, dict[str, Any]]:
40
+ if not self._conditions:
41
+ return "", {}
42
+ return "WHERE " + " ".join(self._conditions), self._params
43
+
44
+
45
+ def order_limit_start(
46
+ sort_by: Optional[str] = None,
47
+ sort_order: Optional[str] = None,
48
+ limit: Optional[int] = None,
49
+ page: Optional[int] = None,
50
+ ) -> str:
51
+ if sort_order is not None:
52
+ if "desc" in sort_order.lower():
53
+ sort_order = "DESC"
54
+ else:
55
+ sort_order = "ASC"
56
+
57
+ order_clause = f"ORDER BY {sort_by} {sort_order or ''}" if sort_by is not None else ""
58
+
59
+ if limit is not None:
60
+ limit_clause = f"LIMIT {limit}"
61
+ if page is not None:
62
+ offset = (page - 1) * limit
63
+ start_clause = f"START {offset}"
64
+ else:
65
+ start_clause = ""
66
+ else:
67
+ limit_clause = ""
68
+ start_clause = ""
69
+
70
+ clauses = [order_clause, limit_clause, start_clause]
71
+ return " ".join(clause for clause in clauses if clause)