agno 2.3.8__py3-none-any.whl → 2.3.10__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 (66) hide show
  1. agno/agent/agent.py +134 -94
  2. agno/db/mysql/__init__.py +2 -1
  3. agno/db/mysql/async_mysql.py +2888 -0
  4. agno/db/mysql/mysql.py +17 -8
  5. agno/db/mysql/utils.py +139 -6
  6. agno/db/postgres/async_postgres.py +10 -5
  7. agno/db/postgres/postgres.py +7 -2
  8. agno/db/schemas/evals.py +1 -0
  9. agno/db/singlestore/singlestore.py +5 -1
  10. agno/db/sqlite/async_sqlite.py +3 -3
  11. agno/eval/__init__.py +10 -0
  12. agno/eval/accuracy.py +11 -8
  13. agno/eval/agent_as_judge.py +861 -0
  14. agno/eval/base.py +29 -0
  15. agno/eval/utils.py +2 -1
  16. agno/exceptions.py +7 -0
  17. agno/knowledge/embedder/openai.py +8 -8
  18. agno/knowledge/knowledge.py +1142 -176
  19. agno/media.py +22 -6
  20. agno/models/aws/claude.py +8 -7
  21. agno/models/base.py +61 -2
  22. agno/models/deepseek/deepseek.py +67 -0
  23. agno/models/google/gemini.py +134 -51
  24. agno/models/google/utils.py +22 -0
  25. agno/models/message.py +5 -0
  26. agno/models/openai/chat.py +4 -0
  27. agno/os/app.py +64 -74
  28. agno/os/interfaces/a2a/router.py +3 -4
  29. agno/os/interfaces/agui/router.py +2 -0
  30. agno/os/router.py +3 -1607
  31. agno/os/routers/agents/__init__.py +3 -0
  32. agno/os/routers/agents/router.py +581 -0
  33. agno/os/routers/agents/schema.py +261 -0
  34. agno/os/routers/evals/evals.py +26 -6
  35. agno/os/routers/evals/schemas.py +34 -2
  36. agno/os/routers/evals/utils.py +77 -18
  37. agno/os/routers/knowledge/knowledge.py +1 -1
  38. agno/os/routers/teams/__init__.py +3 -0
  39. agno/os/routers/teams/router.py +496 -0
  40. agno/os/routers/teams/schema.py +257 -0
  41. agno/os/routers/workflows/__init__.py +3 -0
  42. agno/os/routers/workflows/router.py +545 -0
  43. agno/os/routers/workflows/schema.py +75 -0
  44. agno/os/schema.py +1 -559
  45. agno/os/utils.py +139 -2
  46. agno/team/team.py +87 -24
  47. agno/tools/file_generation.py +12 -6
  48. agno/tools/firecrawl.py +15 -7
  49. agno/tools/function.py +37 -23
  50. agno/tools/shopify.py +1519 -0
  51. agno/tools/spotify.py +2 -5
  52. agno/utils/hooks.py +64 -5
  53. agno/utils/http.py +2 -2
  54. agno/utils/media.py +11 -1
  55. agno/utils/print_response/agent.py +8 -0
  56. agno/utils/print_response/team.py +8 -0
  57. agno/vectordb/pgvector/pgvector.py +88 -51
  58. agno/workflow/parallel.py +5 -3
  59. agno/workflow/step.py +14 -2
  60. agno/workflow/types.py +38 -2
  61. agno/workflow/workflow.py +12 -4
  62. {agno-2.3.8.dist-info → agno-2.3.10.dist-info}/METADATA +7 -2
  63. {agno-2.3.8.dist-info → agno-2.3.10.dist-info}/RECORD +66 -52
  64. {agno-2.3.8.dist-info → agno-2.3.10.dist-info}/WHEEL +0 -0
  65. {agno-2.3.8.dist-info → agno-2.3.10.dist-info}/licenses/LICENSE +0 -0
  66. {agno-2.3.8.dist-info → agno-2.3.10.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,496 @@
1
+ from typing import TYPE_CHECKING, Any, AsyncGenerator, List, Optional
2
+ from uuid import uuid4
3
+
4
+ from fastapi import (
5
+ APIRouter,
6
+ BackgroundTasks,
7
+ Depends,
8
+ File,
9
+ Form,
10
+ HTTPException,
11
+ Request,
12
+ UploadFile,
13
+ )
14
+ from fastapi.responses import JSONResponse, StreamingResponse
15
+
16
+ from agno.exceptions import InputCheckError, OutputCheckError
17
+ from agno.media import Audio, Image, Video
18
+ from agno.media import File as FileMedia
19
+ from agno.os.auth import get_authentication_dependency
20
+ from agno.os.routers.teams.schema import TeamResponse
21
+ from agno.os.schema import (
22
+ BadRequestResponse,
23
+ InternalServerErrorResponse,
24
+ NotFoundResponse,
25
+ UnauthenticatedResponse,
26
+ ValidationErrorResponse,
27
+ )
28
+ from agno.os.settings import AgnoAPISettings
29
+ from agno.os.utils import (
30
+ format_sse_event,
31
+ get_request_kwargs,
32
+ get_team_by_id,
33
+ process_audio,
34
+ process_document,
35
+ process_image,
36
+ process_video,
37
+ )
38
+ from agno.run.team import RunErrorEvent as TeamRunErrorEvent
39
+ from agno.team.team import Team
40
+ from agno.utils.log import log_warning, logger
41
+
42
+ if TYPE_CHECKING:
43
+ from agno.os.app import AgentOS
44
+
45
+
46
+ async def team_response_streamer(
47
+ team: Team,
48
+ message: str,
49
+ session_id: Optional[str] = None,
50
+ user_id: Optional[str] = None,
51
+ images: Optional[List[Image]] = None,
52
+ audio: Optional[List[Audio]] = None,
53
+ videos: Optional[List[Video]] = None,
54
+ files: Optional[List[FileMedia]] = None,
55
+ background_tasks: Optional[BackgroundTasks] = None,
56
+ **kwargs: Any,
57
+ ) -> AsyncGenerator:
58
+ """Run the given team asynchronously and yield its response"""
59
+ try:
60
+ # Pass background_tasks if provided
61
+ if background_tasks is not None:
62
+ kwargs["background_tasks"] = background_tasks
63
+
64
+ run_response = team.arun(
65
+ input=message,
66
+ session_id=session_id,
67
+ user_id=user_id,
68
+ images=images,
69
+ audio=audio,
70
+ videos=videos,
71
+ files=files,
72
+ stream=True,
73
+ stream_events=True,
74
+ **kwargs,
75
+ )
76
+ async for run_response_chunk in run_response:
77
+ yield format_sse_event(run_response_chunk) # type: ignore
78
+ except (InputCheckError, OutputCheckError) as e:
79
+ error_response = TeamRunErrorEvent(
80
+ content=str(e),
81
+ error_type=e.type,
82
+ error_id=e.error_id,
83
+ additional_data=e.additional_data,
84
+ )
85
+ yield format_sse_event(error_response)
86
+
87
+ except Exception as e:
88
+ import traceback
89
+
90
+ traceback.print_exc()
91
+ error_response = TeamRunErrorEvent(
92
+ content=str(e),
93
+ error_type=e.type if hasattr(e, "type") else None,
94
+ error_id=e.error_id if hasattr(e, "error_id") else None,
95
+ )
96
+ yield format_sse_event(error_response)
97
+ return
98
+
99
+
100
+ def get_team_router(
101
+ os: "AgentOS",
102
+ settings: AgnoAPISettings = AgnoAPISettings(),
103
+ ) -> APIRouter:
104
+ """Create the team router with comprehensive OpenAPI documentation."""
105
+ router = APIRouter(
106
+ dependencies=[Depends(get_authentication_dependency(settings))],
107
+ responses={
108
+ 400: {"description": "Bad Request", "model": BadRequestResponse},
109
+ 401: {"description": "Unauthorized", "model": UnauthenticatedResponse},
110
+ 404: {"description": "Not Found", "model": NotFoundResponse},
111
+ 422: {"description": "Validation Error", "model": ValidationErrorResponse},
112
+ 500: {"description": "Internal Server Error", "model": InternalServerErrorResponse},
113
+ },
114
+ )
115
+
116
+ @router.post(
117
+ "/teams/{team_id}/runs",
118
+ tags=["Teams"],
119
+ operation_id="create_team_run",
120
+ response_model_exclude_none=True,
121
+ summary="Create Team Run",
122
+ description=(
123
+ "Execute a team collaboration with multiple agents working together on a task.\n\n"
124
+ "**Features:**\n"
125
+ "- Text message input with optional session management\n"
126
+ "- Multi-media support: images (PNG, JPEG, WebP), audio (WAV, MP3), video (MP4, WebM, etc.)\n"
127
+ "- Document processing: PDF, CSV, DOCX, TXT, JSON\n"
128
+ "- Real-time streaming responses with Server-Sent Events (SSE)\n"
129
+ "- User and session context preservation\n\n"
130
+ "**Streaming Response:**\n"
131
+ "When `stream=true`, returns SSE events with `event` and `data` fields."
132
+ ),
133
+ responses={
134
+ 200: {
135
+ "description": "Team run executed successfully",
136
+ "content": {
137
+ "text/event-stream": {
138
+ "example": 'event: RunStarted\ndata: {"content": "Hello!", "run_id": "123..."}\n\n'
139
+ },
140
+ },
141
+ },
142
+ 400: {"description": "Invalid request or unsupported file type", "model": BadRequestResponse},
143
+ 404: {"description": "Team not found", "model": NotFoundResponse},
144
+ },
145
+ )
146
+ async def create_team_run(
147
+ team_id: str,
148
+ request: Request,
149
+ background_tasks: BackgroundTasks,
150
+ message: str = Form(...),
151
+ stream: bool = Form(True),
152
+ monitor: bool = Form(True),
153
+ session_id: Optional[str] = Form(None),
154
+ user_id: Optional[str] = Form(None),
155
+ files: Optional[List[UploadFile]] = File(None),
156
+ ):
157
+ kwargs = await get_request_kwargs(request, create_team_run)
158
+
159
+ if hasattr(request.state, "user_id"):
160
+ if user_id:
161
+ log_warning("User ID parameter passed in both request state and kwargs, using request state")
162
+ user_id = request.state.user_id
163
+ if hasattr(request.state, "session_id"):
164
+ if session_id:
165
+ log_warning("Session ID parameter passed in both request state and kwargs, using request state")
166
+ session_id = request.state.session_id
167
+ if hasattr(request.state, "session_state"):
168
+ session_state = request.state.session_state
169
+ if "session_state" in kwargs:
170
+ log_warning("Session state parameter passed in both request state and kwargs, using request state")
171
+ kwargs["session_state"] = session_state
172
+ if hasattr(request.state, "dependencies"):
173
+ dependencies = request.state.dependencies
174
+ if "dependencies" in kwargs:
175
+ log_warning("Dependencies parameter passed in both request state and kwargs, using request state")
176
+ kwargs["dependencies"] = dependencies
177
+ if hasattr(request.state, "metadata"):
178
+ metadata = request.state.metadata
179
+ if "metadata" in kwargs:
180
+ log_warning("Metadata parameter passed in both request state and kwargs, using request state")
181
+ kwargs["metadata"] = metadata
182
+
183
+ logger.debug(f"Creating team run: {message=} {session_id=} {monitor=} {user_id=} {team_id=} {files=} {kwargs=}")
184
+
185
+ team = get_team_by_id(team_id, os.teams)
186
+ if team is None:
187
+ raise HTTPException(status_code=404, detail="Team not found")
188
+
189
+ if session_id is not None and session_id != "":
190
+ logger.debug(f"Continuing session: {session_id}")
191
+ else:
192
+ logger.debug("Creating new session")
193
+ session_id = str(uuid4())
194
+
195
+ base64_images: List[Image] = []
196
+ base64_audios: List[Audio] = []
197
+ base64_videos: List[Video] = []
198
+ document_files: List[FileMedia] = []
199
+
200
+ if files:
201
+ for file in files:
202
+ if file.content_type in ["image/png", "image/jpeg", "image/jpg", "image/webp"]:
203
+ try:
204
+ base64_image = process_image(file)
205
+ base64_images.append(base64_image)
206
+ except Exception as e:
207
+ logger.error(f"Error processing image {file.filename}: {e}")
208
+ continue
209
+ elif file.content_type in ["audio/wav", "audio/mp3", "audio/mpeg"]:
210
+ try:
211
+ base64_audio = process_audio(file)
212
+ base64_audios.append(base64_audio)
213
+ except Exception as e:
214
+ logger.error(f"Error processing audio {file.filename}: {e}")
215
+ continue
216
+ elif file.content_type in [
217
+ "video/x-flv",
218
+ "video/quicktime",
219
+ "video/mpeg",
220
+ "video/mpegs",
221
+ "video/mpgs",
222
+ "video/mpg",
223
+ "video/mpg",
224
+ "video/mp4",
225
+ "video/webm",
226
+ "video/wmv",
227
+ "video/3gpp",
228
+ ]:
229
+ try:
230
+ base64_video = process_video(file)
231
+ base64_videos.append(base64_video)
232
+ except Exception as e:
233
+ logger.error(f"Error processing video {file.filename}: {e}")
234
+ continue
235
+ elif file.content_type in [
236
+ "application/pdf",
237
+ "text/csv",
238
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
239
+ "text/plain",
240
+ "application/json",
241
+ ]:
242
+ document_file = process_document(file)
243
+ if document_file is not None:
244
+ document_files.append(document_file)
245
+ else:
246
+ raise HTTPException(status_code=400, detail="Unsupported file type")
247
+
248
+ if stream:
249
+ return StreamingResponse(
250
+ team_response_streamer(
251
+ team,
252
+ message,
253
+ session_id=session_id,
254
+ user_id=user_id,
255
+ images=base64_images if base64_images else None,
256
+ audio=base64_audios if base64_audios else None,
257
+ videos=base64_videos if base64_videos else None,
258
+ files=document_files if document_files else None,
259
+ background_tasks=background_tasks,
260
+ **kwargs,
261
+ ),
262
+ media_type="text/event-stream",
263
+ )
264
+ else:
265
+ try:
266
+ run_response = await team.arun(
267
+ input=message,
268
+ session_id=session_id,
269
+ user_id=user_id,
270
+ images=base64_images if base64_images else None,
271
+ audio=base64_audios if base64_audios else None,
272
+ videos=base64_videos if base64_videos else None,
273
+ files=document_files if document_files else None,
274
+ stream=False,
275
+ background_tasks=background_tasks,
276
+ **kwargs,
277
+ )
278
+ return run_response.to_dict()
279
+
280
+ except InputCheckError as e:
281
+ raise HTTPException(status_code=400, detail=str(e))
282
+
283
+ @router.post(
284
+ "/teams/{team_id}/runs/{run_id}/cancel",
285
+ tags=["Teams"],
286
+ operation_id="cancel_team_run",
287
+ response_model_exclude_none=True,
288
+ summary="Cancel Team Run",
289
+ description=(
290
+ "Cancel a currently executing team run. This will attempt to stop the team's execution gracefully.\n\n"
291
+ "**Note:** Cancellation may not be immediate for all operations."
292
+ ),
293
+ responses={
294
+ 200: {},
295
+ 404: {"description": "Team not found", "model": NotFoundResponse},
296
+ 500: {"description": "Failed to cancel team run", "model": InternalServerErrorResponse},
297
+ },
298
+ )
299
+ async def cancel_team_run(
300
+ team_id: str,
301
+ run_id: str,
302
+ ):
303
+ team = get_team_by_id(team_id, os.teams)
304
+ if team is None:
305
+ raise HTTPException(status_code=404, detail="Team not found")
306
+
307
+ if not team.cancel_run(run_id=run_id):
308
+ raise HTTPException(status_code=500, detail="Failed to cancel run")
309
+
310
+ return JSONResponse(content={}, status_code=200)
311
+
312
+ @router.get(
313
+ "/teams",
314
+ response_model=List[TeamResponse],
315
+ response_model_exclude_none=True,
316
+ tags=["Teams"],
317
+ operation_id="get_teams",
318
+ summary="List All Teams",
319
+ description=(
320
+ "Retrieve a comprehensive list of all teams configured in this OS instance.\n\n"
321
+ "**Returns team information including:**\n"
322
+ "- Team metadata (ID, name, description, execution mode)\n"
323
+ "- Model configuration for team coordination\n"
324
+ "- Team member roster with roles and capabilities\n"
325
+ "- Knowledge sharing and memory configurations"
326
+ ),
327
+ responses={
328
+ 200: {
329
+ "description": "List of teams retrieved successfully",
330
+ "content": {
331
+ "application/json": {
332
+ "example": [
333
+ {
334
+ "team_id": "basic-team",
335
+ "name": "Basic Team",
336
+ "mode": "coordinate",
337
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
338
+ "tools": [
339
+ {
340
+ "name": "transfer_task_to_member",
341
+ "description": "Use this function to transfer a task to the selected team member.\nYou must provide a clear and concise description of the task the member should achieve AND the expected output.",
342
+ "parameters": {
343
+ "type": "object",
344
+ "properties": {
345
+ "member_id": {
346
+ "type": "string",
347
+ "description": "(str) The ID of the member to transfer the task to. Use only the ID of the member, not the ID of the team followed by the ID of the member.",
348
+ },
349
+ "task_description": {
350
+ "type": "string",
351
+ "description": "(str) A clear and concise description of the task the member should achieve.",
352
+ },
353
+ "expected_output": {
354
+ "type": "string",
355
+ "description": "(str) The expected output from the member (optional).",
356
+ },
357
+ },
358
+ "additionalProperties": False,
359
+ "required": ["member_id", "task_description"],
360
+ },
361
+ }
362
+ ],
363
+ "members": [
364
+ {
365
+ "agent_id": "basic-agent",
366
+ "name": "Basic Agent",
367
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI gpt-4o"},
368
+ "memory": {
369
+ "app_name": "Memory",
370
+ "app_url": None,
371
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
372
+ },
373
+ "session_table": "agno_sessions",
374
+ "memory_table": "agno_memories",
375
+ }
376
+ ],
377
+ "enable_agentic_context": False,
378
+ "memory": {
379
+ "app_name": "agno_memories",
380
+ "app_url": "/memory/1",
381
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
382
+ },
383
+ "async_mode": False,
384
+ "session_table": "agno_sessions",
385
+ "memory_table": "agno_memories",
386
+ }
387
+ ]
388
+ }
389
+ },
390
+ }
391
+ },
392
+ )
393
+ async def get_teams() -> List[TeamResponse]:
394
+ """Return the list of all Teams present in the contextual OS"""
395
+ if os.teams is None:
396
+ return []
397
+
398
+ teams = []
399
+ for team in os.teams:
400
+ team_response = await TeamResponse.from_team(team=team)
401
+ teams.append(team_response)
402
+
403
+ return teams
404
+
405
+ @router.get(
406
+ "/teams/{team_id}",
407
+ response_model=TeamResponse,
408
+ response_model_exclude_none=True,
409
+ tags=["Teams"],
410
+ operation_id="get_team",
411
+ summary="Get Team Details",
412
+ description=("Retrieve detailed configuration and member information for a specific team."),
413
+ responses={
414
+ 200: {
415
+ "description": "Team details retrieved successfully",
416
+ "content": {
417
+ "application/json": {
418
+ "example": {
419
+ "team_id": "basic-team",
420
+ "name": "Basic Team",
421
+ "description": None,
422
+ "mode": "coordinate",
423
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
424
+ "tools": [
425
+ {
426
+ "name": "transfer_task_to_member",
427
+ "description": "Use this function to transfer a task to the selected team member.\nYou must provide a clear and concise description of the task the member should achieve AND the expected output.",
428
+ "parameters": {
429
+ "type": "object",
430
+ "properties": {
431
+ "member_id": {
432
+ "type": "string",
433
+ "description": "(str) The ID of the member to transfer the task to. Use only the ID of the member, not the ID of the team followed by the ID of the member.",
434
+ },
435
+ "task_description": {
436
+ "type": "string",
437
+ "description": "(str) A clear and concise description of the task the member should achieve.",
438
+ },
439
+ "expected_output": {
440
+ "type": "string",
441
+ "description": "(str) The expected output from the member (optional).",
442
+ },
443
+ },
444
+ "additionalProperties": False,
445
+ "required": ["member_id", "task_description"],
446
+ },
447
+ }
448
+ ],
449
+ "instructions": None,
450
+ "members": [
451
+ {
452
+ "agent_id": "basic-agent",
453
+ "name": "Basic Agent",
454
+ "description": None,
455
+ "instructions": None,
456
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI gpt-4o"},
457
+ "tools": None,
458
+ "memory": {
459
+ "app_name": "Memory",
460
+ "app_url": None,
461
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
462
+ },
463
+ "knowledge": None,
464
+ "session_table": "agno_sessions",
465
+ "memory_table": "agno_memories",
466
+ "knowledge_table": None,
467
+ }
468
+ ],
469
+ "expected_output": None,
470
+ "dependencies": None,
471
+ "enable_agentic_context": False,
472
+ "memory": {
473
+ "app_name": "Memory",
474
+ "app_url": None,
475
+ "model": {"name": "OpenAIChat", "model": "gpt-4o", "provider": "OpenAI"},
476
+ },
477
+ "knowledge": None,
478
+ "async_mode": False,
479
+ "session_table": "agno_sessions",
480
+ "memory_table": "agno_memories",
481
+ "knowledge_table": None,
482
+ }
483
+ }
484
+ },
485
+ },
486
+ 404: {"description": "Team not found", "model": NotFoundResponse},
487
+ },
488
+ )
489
+ async def get_team(team_id: str) -> TeamResponse:
490
+ team = get_team_by_id(team_id, os.teams)
491
+ if team is None:
492
+ raise HTTPException(status_code=404, detail="Team not found")
493
+
494
+ return await TeamResponse.from_team(team)
495
+
496
+ return router