agno 2.1.2__py3-none-any.whl → 2.3.13__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 +5540 -2273
- agno/api/api.py +2 -0
- agno/api/os.py +1 -1
- agno/compression/__init__.py +3 -0
- agno/compression/manager.py +247 -0
- agno/culture/__init__.py +3 -0
- agno/culture/manager.py +956 -0
- agno/db/async_postgres/__init__.py +3 -0
- agno/db/base.py +689 -6
- agno/db/dynamo/dynamo.py +933 -37
- agno/db/dynamo/schemas.py +174 -10
- agno/db/dynamo/utils.py +63 -4
- agno/db/firestore/firestore.py +831 -9
- agno/db/firestore/schemas.py +51 -0
- agno/db/firestore/utils.py +102 -4
- agno/db/gcs_json/gcs_json_db.py +660 -12
- agno/db/gcs_json/utils.py +60 -26
- agno/db/in_memory/in_memory_db.py +287 -14
- agno/db/in_memory/utils.py +60 -2
- agno/db/json/json_db.py +590 -14
- agno/db/json/utils.py +60 -26
- agno/db/migrations/manager.py +199 -0
- agno/db/migrations/v1_to_v2.py +43 -13
- agno/db/migrations/versions/__init__.py +0 -0
- agno/db/migrations/versions/v2_3_0.py +938 -0
- agno/db/mongo/__init__.py +15 -1
- agno/db/mongo/async_mongo.py +2760 -0
- agno/db/mongo/mongo.py +879 -11
- agno/db/mongo/schemas.py +42 -0
- agno/db/mongo/utils.py +80 -8
- agno/db/mysql/__init__.py +2 -1
- agno/db/mysql/async_mysql.py +2912 -0
- agno/db/mysql/mysql.py +946 -68
- agno/db/mysql/schemas.py +72 -10
- agno/db/mysql/utils.py +198 -7
- agno/db/postgres/__init__.py +2 -1
- agno/db/postgres/async_postgres.py +2579 -0
- agno/db/postgres/postgres.py +942 -57
- agno/db/postgres/schemas.py +81 -18
- agno/db/postgres/utils.py +164 -2
- agno/db/redis/redis.py +671 -7
- agno/db/redis/schemas.py +50 -0
- agno/db/redis/utils.py +65 -7
- agno/db/schemas/__init__.py +2 -1
- agno/db/schemas/culture.py +120 -0
- agno/db/schemas/evals.py +1 -0
- agno/db/schemas/memory.py +17 -2
- agno/db/singlestore/schemas.py +63 -0
- agno/db/singlestore/singlestore.py +949 -83
- agno/db/singlestore/utils.py +60 -2
- agno/db/sqlite/__init__.py +2 -1
- agno/db/sqlite/async_sqlite.py +2911 -0
- agno/db/sqlite/schemas.py +62 -0
- agno/db/sqlite/sqlite.py +965 -46
- agno/db/sqlite/utils.py +169 -8
- agno/db/surrealdb/__init__.py +3 -0
- agno/db/surrealdb/metrics.py +292 -0
- agno/db/surrealdb/models.py +334 -0
- agno/db/surrealdb/queries.py +71 -0
- agno/db/surrealdb/surrealdb.py +1908 -0
- agno/db/surrealdb/utils.py +147 -0
- agno/db/utils.py +2 -0
- agno/eval/__init__.py +10 -0
- agno/eval/accuracy.py +75 -55
- agno/eval/agent_as_judge.py +861 -0
- agno/eval/base.py +29 -0
- agno/eval/performance.py +16 -7
- agno/eval/reliability.py +28 -16
- agno/eval/utils.py +35 -17
- agno/exceptions.py +27 -2
- agno/filters.py +354 -0
- agno/guardrails/prompt_injection.py +1 -0
- agno/hooks/__init__.py +3 -0
- agno/hooks/decorator.py +164 -0
- agno/integrations/discord/client.py +1 -1
- agno/knowledge/chunking/agentic.py +13 -10
- agno/knowledge/chunking/fixed.py +4 -1
- agno/knowledge/chunking/semantic.py +9 -4
- agno/knowledge/chunking/strategy.py +59 -15
- agno/knowledge/embedder/fastembed.py +1 -1
- agno/knowledge/embedder/nebius.py +1 -1
- agno/knowledge/embedder/ollama.py +8 -0
- agno/knowledge/embedder/openai.py +8 -8
- agno/knowledge/embedder/sentence_transformer.py +6 -2
- agno/knowledge/embedder/vllm.py +262 -0
- agno/knowledge/knowledge.py +1618 -318
- agno/knowledge/reader/base.py +6 -2
- agno/knowledge/reader/csv_reader.py +8 -10
- agno/knowledge/reader/docx_reader.py +5 -6
- agno/knowledge/reader/field_labeled_csv_reader.py +16 -20
- agno/knowledge/reader/json_reader.py +5 -4
- agno/knowledge/reader/markdown_reader.py +8 -8
- agno/knowledge/reader/pdf_reader.py +17 -19
- agno/knowledge/reader/pptx_reader.py +101 -0
- agno/knowledge/reader/reader_factory.py +32 -3
- agno/knowledge/reader/s3_reader.py +3 -3
- agno/knowledge/reader/tavily_reader.py +193 -0
- agno/knowledge/reader/text_reader.py +22 -10
- agno/knowledge/reader/web_search_reader.py +1 -48
- agno/knowledge/reader/website_reader.py +10 -10
- agno/knowledge/reader/wikipedia_reader.py +33 -1
- agno/knowledge/types.py +1 -0
- agno/knowledge/utils.py +72 -7
- agno/media.py +22 -6
- agno/memory/__init__.py +14 -1
- agno/memory/manager.py +544 -83
- agno/memory/strategies/__init__.py +15 -0
- agno/memory/strategies/base.py +66 -0
- agno/memory/strategies/summarize.py +196 -0
- agno/memory/strategies/types.py +37 -0
- agno/models/aimlapi/aimlapi.py +17 -0
- agno/models/anthropic/claude.py +515 -40
- agno/models/aws/bedrock.py +102 -21
- agno/models/aws/claude.py +131 -274
- agno/models/azure/ai_foundry.py +41 -19
- agno/models/azure/openai_chat.py +39 -8
- agno/models/base.py +1249 -525
- agno/models/cerebras/cerebras.py +91 -21
- agno/models/cerebras/cerebras_openai.py +21 -2
- agno/models/cohere/chat.py +40 -6
- agno/models/cometapi/cometapi.py +18 -1
- agno/models/dashscope/dashscope.py +2 -3
- agno/models/deepinfra/deepinfra.py +18 -1
- agno/models/deepseek/deepseek.py +69 -3
- agno/models/fireworks/fireworks.py +18 -1
- agno/models/google/gemini.py +877 -80
- agno/models/google/utils.py +22 -0
- agno/models/groq/groq.py +51 -18
- agno/models/huggingface/huggingface.py +17 -6
- agno/models/ibm/watsonx.py +16 -6
- agno/models/internlm/internlm.py +18 -1
- agno/models/langdb/langdb.py +13 -1
- agno/models/litellm/chat.py +44 -9
- agno/models/litellm/litellm_openai.py +18 -1
- agno/models/message.py +28 -5
- agno/models/meta/llama.py +47 -14
- agno/models/meta/llama_openai.py +22 -17
- agno/models/mistral/mistral.py +8 -4
- agno/models/nebius/nebius.py +6 -7
- agno/models/nvidia/nvidia.py +20 -3
- agno/models/ollama/chat.py +24 -8
- agno/models/openai/chat.py +104 -29
- agno/models/openai/responses.py +101 -81
- agno/models/openrouter/openrouter.py +60 -3
- agno/models/perplexity/perplexity.py +17 -1
- agno/models/portkey/portkey.py +7 -6
- agno/models/requesty/requesty.py +24 -4
- agno/models/response.py +73 -2
- agno/models/sambanova/sambanova.py +20 -3
- agno/models/siliconflow/siliconflow.py +19 -2
- agno/models/together/together.py +20 -3
- agno/models/utils.py +254 -8
- agno/models/vercel/v0.py +20 -3
- agno/models/vertexai/__init__.py +0 -0
- agno/models/vertexai/claude.py +190 -0
- agno/models/vllm/vllm.py +19 -14
- agno/models/xai/xai.py +19 -2
- agno/os/app.py +549 -152
- agno/os/auth.py +190 -3
- agno/os/config.py +23 -0
- agno/os/interfaces/a2a/router.py +8 -11
- agno/os/interfaces/a2a/utils.py +1 -1
- agno/os/interfaces/agui/router.py +18 -3
- agno/os/interfaces/agui/utils.py +152 -39
- agno/os/interfaces/slack/router.py +55 -37
- agno/os/interfaces/slack/slack.py +9 -1
- agno/os/interfaces/whatsapp/router.py +0 -1
- agno/os/interfaces/whatsapp/security.py +3 -1
- agno/os/mcp.py +110 -52
- agno/os/middleware/__init__.py +2 -0
- agno/os/middleware/jwt.py +676 -112
- agno/os/router.py +40 -1478
- agno/os/routers/agents/__init__.py +3 -0
- agno/os/routers/agents/router.py +599 -0
- agno/os/routers/agents/schema.py +261 -0
- agno/os/routers/evals/evals.py +96 -39
- agno/os/routers/evals/schemas.py +65 -33
- agno/os/routers/evals/utils.py +80 -10
- agno/os/routers/health.py +10 -4
- agno/os/routers/knowledge/knowledge.py +196 -38
- agno/os/routers/knowledge/schemas.py +82 -22
- agno/os/routers/memory/memory.py +279 -52
- agno/os/routers/memory/schemas.py +46 -17
- agno/os/routers/metrics/metrics.py +20 -8
- agno/os/routers/metrics/schemas.py +16 -16
- agno/os/routers/session/session.py +462 -34
- agno/os/routers/teams/__init__.py +3 -0
- agno/os/routers/teams/router.py +512 -0
- agno/os/routers/teams/schema.py +257 -0
- agno/os/routers/traces/__init__.py +3 -0
- agno/os/routers/traces/schemas.py +414 -0
- agno/os/routers/traces/traces.py +499 -0
- agno/os/routers/workflows/__init__.py +3 -0
- agno/os/routers/workflows/router.py +624 -0
- agno/os/routers/workflows/schema.py +75 -0
- agno/os/schema.py +256 -693
- agno/os/scopes.py +469 -0
- agno/os/utils.py +514 -36
- agno/reasoning/anthropic.py +80 -0
- agno/reasoning/gemini.py +73 -0
- agno/reasoning/openai.py +5 -0
- agno/reasoning/vertexai.py +76 -0
- agno/run/__init__.py +6 -0
- agno/run/agent.py +155 -32
- agno/run/base.py +55 -3
- agno/run/requirement.py +181 -0
- agno/run/team.py +125 -38
- agno/run/workflow.py +72 -18
- agno/session/agent.py +102 -89
- agno/session/summary.py +56 -15
- agno/session/team.py +164 -90
- agno/session/workflow.py +405 -40
- agno/table.py +10 -0
- agno/team/team.py +3974 -1903
- agno/tools/dalle.py +2 -4
- agno/tools/eleven_labs.py +23 -25
- agno/tools/exa.py +21 -16
- agno/tools/file.py +153 -23
- agno/tools/file_generation.py +16 -10
- agno/tools/firecrawl.py +15 -7
- agno/tools/function.py +193 -38
- agno/tools/gmail.py +238 -14
- agno/tools/google_drive.py +271 -0
- agno/tools/googlecalendar.py +36 -8
- agno/tools/googlesheets.py +20 -5
- agno/tools/jira.py +20 -0
- agno/tools/mcp/__init__.py +10 -0
- agno/tools/mcp/mcp.py +331 -0
- agno/tools/mcp/multi_mcp.py +347 -0
- agno/tools/mcp/params.py +24 -0
- agno/tools/mcp_toolbox.py +3 -3
- agno/tools/models/nebius.py +5 -5
- agno/tools/models_labs.py +20 -10
- agno/tools/nano_banana.py +151 -0
- agno/tools/notion.py +204 -0
- agno/tools/parallel.py +314 -0
- agno/tools/postgres.py +76 -36
- agno/tools/redshift.py +406 -0
- agno/tools/scrapegraph.py +1 -1
- agno/tools/shopify.py +1519 -0
- agno/tools/slack.py +18 -3
- agno/tools/spotify.py +919 -0
- agno/tools/tavily.py +146 -0
- agno/tools/toolkit.py +25 -0
- agno/tools/workflow.py +8 -1
- agno/tools/yfinance.py +12 -11
- agno/tracing/__init__.py +12 -0
- agno/tracing/exporter.py +157 -0
- agno/tracing/schemas.py +276 -0
- agno/tracing/setup.py +111 -0
- agno/utils/agent.py +938 -0
- agno/utils/cryptography.py +22 -0
- agno/utils/dttm.py +33 -0
- agno/utils/events.py +151 -3
- agno/utils/gemini.py +15 -5
- agno/utils/hooks.py +118 -4
- agno/utils/http.py +113 -2
- agno/utils/knowledge.py +12 -5
- agno/utils/log.py +1 -0
- agno/utils/mcp.py +92 -2
- agno/utils/media.py +187 -1
- agno/utils/merge_dict.py +3 -3
- agno/utils/message.py +60 -0
- agno/utils/models/ai_foundry.py +9 -2
- agno/utils/models/claude.py +49 -14
- 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 +109 -16
- agno/utils/print_response/team.py +223 -30
- agno/utils/print_response/workflow.py +251 -34
- agno/utils/streamlit.py +1 -1
- agno/utils/team.py +98 -9
- agno/utils/tokens.py +657 -0
- agno/vectordb/base.py +39 -7
- agno/vectordb/cassandra/cassandra.py +21 -5
- agno/vectordb/chroma/chromadb.py +43 -12
- agno/vectordb/clickhouse/clickhousedb.py +21 -5
- agno/vectordb/couchbase/couchbase.py +29 -5
- agno/vectordb/lancedb/lance_db.py +92 -181
- agno/vectordb/langchaindb/langchaindb.py +24 -4
- agno/vectordb/lightrag/lightrag.py +17 -3
- agno/vectordb/llamaindex/llamaindexdb.py +25 -5
- agno/vectordb/milvus/milvus.py +50 -37
- agno/vectordb/mongodb/__init__.py +7 -1
- agno/vectordb/mongodb/mongodb.py +36 -30
- agno/vectordb/pgvector/pgvector.py +201 -77
- agno/vectordb/pineconedb/pineconedb.py +41 -23
- agno/vectordb/qdrant/qdrant.py +67 -54
- agno/vectordb/redis/__init__.py +9 -0
- agno/vectordb/redis/redisdb.py +682 -0
- agno/vectordb/singlestore/singlestore.py +50 -29
- agno/vectordb/surrealdb/surrealdb.py +31 -41
- agno/vectordb/upstashdb/upstashdb.py +34 -6
- agno/vectordb/weaviate/weaviate.py +53 -14
- agno/workflow/__init__.py +2 -0
- agno/workflow/agent.py +299 -0
- agno/workflow/condition.py +120 -18
- agno/workflow/loop.py +77 -10
- agno/workflow/parallel.py +231 -143
- agno/workflow/router.py +118 -17
- agno/workflow/step.py +609 -170
- agno/workflow/steps.py +73 -6
- agno/workflow/types.py +96 -21
- agno/workflow/workflow.py +2039 -262
- {agno-2.1.2.dist-info → agno-2.3.13.dist-info}/METADATA +201 -66
- agno-2.3.13.dist-info/RECORD +613 -0
- agno/tools/googlesearch.py +0 -98
- agno/tools/mcp.py +0 -679
- agno/tools/memori.py +0 -339
- agno-2.1.2.dist-info/RECORD +0 -543
- {agno-2.1.2.dist-info → agno-2.3.13.dist-info}/WHEEL +0 -0
- {agno-2.1.2.dist-info → agno-2.3.13.dist-info}/licenses/LICENSE +0 -0
- {agno-2.1.2.dist-info → agno-2.3.13.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import TYPE_CHECKING, Any, AsyncGenerator, Dict, List, Optional, Union, cast
|
|
3
|
+
from uuid import uuid4
|
|
4
|
+
|
|
5
|
+
from fastapi import (
|
|
6
|
+
APIRouter,
|
|
7
|
+
BackgroundTasks,
|
|
8
|
+
Depends,
|
|
9
|
+
Form,
|
|
10
|
+
HTTPException,
|
|
11
|
+
Request,
|
|
12
|
+
WebSocket,
|
|
13
|
+
)
|
|
14
|
+
from fastapi.responses import JSONResponse, StreamingResponse
|
|
15
|
+
from pydantic import BaseModel
|
|
16
|
+
|
|
17
|
+
from agno.exceptions import InputCheckError, OutputCheckError
|
|
18
|
+
from agno.os.auth import get_authentication_dependency, require_resource_access, validate_websocket_token
|
|
19
|
+
from agno.os.routers.workflows.schema import WorkflowResponse
|
|
20
|
+
from agno.os.schema import (
|
|
21
|
+
BadRequestResponse,
|
|
22
|
+
InternalServerErrorResponse,
|
|
23
|
+
NotFoundResponse,
|
|
24
|
+
UnauthenticatedResponse,
|
|
25
|
+
ValidationErrorResponse,
|
|
26
|
+
WorkflowSummaryResponse,
|
|
27
|
+
)
|
|
28
|
+
from agno.os.settings import AgnoAPISettings
|
|
29
|
+
from agno.os.utils import (
|
|
30
|
+
format_sse_event,
|
|
31
|
+
get_request_kwargs,
|
|
32
|
+
get_workflow_by_id,
|
|
33
|
+
)
|
|
34
|
+
from agno.run.workflow import WorkflowErrorEvent, WorkflowRunOutput
|
|
35
|
+
from agno.utils.log import log_warning, logger
|
|
36
|
+
from agno.workflow.workflow import Workflow
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from agno.os.app import AgentOS
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class WebSocketManager:
|
|
43
|
+
"""Manages WebSocket connections for workflow runs"""
|
|
44
|
+
|
|
45
|
+
active_connections: Dict[str, WebSocket] # {run_id: websocket}
|
|
46
|
+
authenticated_connections: Dict[WebSocket, bool] # {websocket: is_authenticated}
|
|
47
|
+
|
|
48
|
+
def __init__(
|
|
49
|
+
self,
|
|
50
|
+
active_connections: Optional[Dict[str, WebSocket]] = None,
|
|
51
|
+
):
|
|
52
|
+
# Store active connections: {run_id: websocket}
|
|
53
|
+
self.active_connections = active_connections or {}
|
|
54
|
+
# Track authentication state for each websocket
|
|
55
|
+
self.authenticated_connections = {}
|
|
56
|
+
|
|
57
|
+
async def connect(self, websocket: WebSocket, requires_auth: bool = True):
|
|
58
|
+
"""Accept WebSocket connection"""
|
|
59
|
+
await websocket.accept()
|
|
60
|
+
logger.debug("WebSocket connected")
|
|
61
|
+
|
|
62
|
+
# If auth is not required, mark as authenticated immediately
|
|
63
|
+
self.authenticated_connections[websocket] = not requires_auth
|
|
64
|
+
|
|
65
|
+
# Send connection confirmation with auth requirement info
|
|
66
|
+
await websocket.send_text(
|
|
67
|
+
json.dumps(
|
|
68
|
+
{
|
|
69
|
+
"event": "connected",
|
|
70
|
+
"message": (
|
|
71
|
+
"Connected to workflow events. Please authenticate to continue."
|
|
72
|
+
if requires_auth
|
|
73
|
+
else "Connected to workflow events. Authentication not required."
|
|
74
|
+
),
|
|
75
|
+
"requires_auth": requires_auth,
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
async def authenticate_websocket(self, websocket: WebSocket):
|
|
81
|
+
"""Mark a WebSocket connection as authenticated"""
|
|
82
|
+
self.authenticated_connections[websocket] = True
|
|
83
|
+
logger.debug("WebSocket authenticated")
|
|
84
|
+
|
|
85
|
+
# Send authentication confirmation
|
|
86
|
+
await websocket.send_text(
|
|
87
|
+
json.dumps(
|
|
88
|
+
{
|
|
89
|
+
"event": "authenticated",
|
|
90
|
+
"message": "Authentication successful. You can now send commands.",
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def is_authenticated(self, websocket: WebSocket) -> bool:
|
|
96
|
+
"""Check if a WebSocket connection is authenticated"""
|
|
97
|
+
return self.authenticated_connections.get(websocket, False)
|
|
98
|
+
|
|
99
|
+
async def register_workflow_websocket(self, run_id: str, websocket: WebSocket):
|
|
100
|
+
"""Register a workflow run with its WebSocket connection"""
|
|
101
|
+
self.active_connections[run_id] = websocket
|
|
102
|
+
logger.debug(f"Registered WebSocket for run_id: {run_id}")
|
|
103
|
+
|
|
104
|
+
async def disconnect_by_run_id(self, run_id: str):
|
|
105
|
+
"""Remove WebSocket connection by run_id"""
|
|
106
|
+
if run_id in self.active_connections:
|
|
107
|
+
websocket = self.active_connections[run_id]
|
|
108
|
+
del self.active_connections[run_id]
|
|
109
|
+
# Clean up authentication state
|
|
110
|
+
if websocket in self.authenticated_connections:
|
|
111
|
+
del self.authenticated_connections[websocket]
|
|
112
|
+
logger.debug(f"WebSocket disconnected for run_id: {run_id}")
|
|
113
|
+
|
|
114
|
+
async def disconnect_websocket(self, websocket: WebSocket):
|
|
115
|
+
"""Remove WebSocket connection and clean up all associated state"""
|
|
116
|
+
# Remove from authenticated connections
|
|
117
|
+
if websocket in self.authenticated_connections:
|
|
118
|
+
del self.authenticated_connections[websocket]
|
|
119
|
+
|
|
120
|
+
# Remove from active connections
|
|
121
|
+
runs_to_remove = [run_id for run_id, ws in self.active_connections.items() if ws == websocket]
|
|
122
|
+
for run_id in runs_to_remove:
|
|
123
|
+
del self.active_connections[run_id]
|
|
124
|
+
|
|
125
|
+
logger.debug("WebSocket disconnected and cleaned up")
|
|
126
|
+
|
|
127
|
+
async def get_websocket_for_run(self, run_id: str) -> Optional[WebSocket]:
|
|
128
|
+
"""Get WebSocket connection for a workflow run"""
|
|
129
|
+
return self.active_connections.get(run_id)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
# Global manager instance
|
|
133
|
+
websocket_manager = WebSocketManager(
|
|
134
|
+
active_connections={},
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async def handle_workflow_via_websocket(websocket: WebSocket, message: dict, os: "AgentOS"):
|
|
139
|
+
"""Handle workflow execution directly via WebSocket"""
|
|
140
|
+
try:
|
|
141
|
+
workflow_id = message.get("workflow_id")
|
|
142
|
+
session_id = message.get("session_id")
|
|
143
|
+
user_message = message.get("message", "")
|
|
144
|
+
user_id = message.get("user_id")
|
|
145
|
+
|
|
146
|
+
if not workflow_id:
|
|
147
|
+
await websocket.send_text(json.dumps({"event": "error", "error": "workflow_id is required"}))
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
# Get workflow from OS
|
|
151
|
+
workflow = get_workflow_by_id(workflow_id, os.workflows)
|
|
152
|
+
if not workflow:
|
|
153
|
+
await websocket.send_text(json.dumps({"event": "error", "error": f"Workflow {workflow_id} not found"}))
|
|
154
|
+
return
|
|
155
|
+
|
|
156
|
+
# Generate session_id if not provided
|
|
157
|
+
# Use workflow's default session_id if not provided in message
|
|
158
|
+
if not session_id:
|
|
159
|
+
if workflow.session_id:
|
|
160
|
+
session_id = workflow.session_id
|
|
161
|
+
else:
|
|
162
|
+
session_id = str(uuid4())
|
|
163
|
+
|
|
164
|
+
# Execute workflow in background with streaming
|
|
165
|
+
workflow_result = await workflow.arun( # type: ignore
|
|
166
|
+
input=user_message,
|
|
167
|
+
session_id=session_id,
|
|
168
|
+
user_id=user_id,
|
|
169
|
+
stream=True,
|
|
170
|
+
stream_events=True,
|
|
171
|
+
background=True,
|
|
172
|
+
websocket=websocket,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
workflow_run_output = cast(WorkflowRunOutput, workflow_result)
|
|
176
|
+
|
|
177
|
+
await websocket_manager.register_workflow_websocket(workflow_run_output.run_id, websocket) # type: ignore
|
|
178
|
+
|
|
179
|
+
except (InputCheckError, OutputCheckError) as e:
|
|
180
|
+
await websocket.send_text(
|
|
181
|
+
json.dumps(
|
|
182
|
+
{
|
|
183
|
+
"event": "error",
|
|
184
|
+
"error": str(e),
|
|
185
|
+
"error_type": e.type,
|
|
186
|
+
"error_id": e.error_id,
|
|
187
|
+
"additional_data": e.additional_data,
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
)
|
|
191
|
+
except Exception as e:
|
|
192
|
+
logger.error(f"Error executing workflow via WebSocket: {e}")
|
|
193
|
+
error_payload = {
|
|
194
|
+
"event": "error",
|
|
195
|
+
"error": str(e),
|
|
196
|
+
"error_type": e.type if hasattr(e, "type") else None,
|
|
197
|
+
"error_id": e.error_id if hasattr(e, "error_id") else None,
|
|
198
|
+
}
|
|
199
|
+
error_payload = {k: v for k, v in error_payload.items() if v is not None}
|
|
200
|
+
await websocket.send_text(json.dumps(error_payload))
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
async def workflow_response_streamer(
|
|
204
|
+
workflow: Workflow,
|
|
205
|
+
input: Optional[Union[str, Dict[str, Any], List[Any], BaseModel]] = None,
|
|
206
|
+
session_id: Optional[str] = None,
|
|
207
|
+
user_id: Optional[str] = None,
|
|
208
|
+
background_tasks: Optional[BackgroundTasks] = None,
|
|
209
|
+
**kwargs: Any,
|
|
210
|
+
) -> AsyncGenerator:
|
|
211
|
+
try:
|
|
212
|
+
# Pass background_tasks if provided
|
|
213
|
+
if background_tasks is not None:
|
|
214
|
+
kwargs["background_tasks"] = background_tasks
|
|
215
|
+
|
|
216
|
+
run_response = workflow.arun(
|
|
217
|
+
input=input,
|
|
218
|
+
session_id=session_id,
|
|
219
|
+
user_id=user_id,
|
|
220
|
+
stream=True,
|
|
221
|
+
stream_events=True,
|
|
222
|
+
**kwargs,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
async for run_response_chunk in run_response:
|
|
226
|
+
yield format_sse_event(run_response_chunk) # type: ignore
|
|
227
|
+
|
|
228
|
+
except (InputCheckError, OutputCheckError) as e:
|
|
229
|
+
error_response = WorkflowErrorEvent(
|
|
230
|
+
error=str(e),
|
|
231
|
+
error_type=e.type,
|
|
232
|
+
error_id=e.error_id,
|
|
233
|
+
additional_data=e.additional_data,
|
|
234
|
+
)
|
|
235
|
+
yield format_sse_event(error_response)
|
|
236
|
+
|
|
237
|
+
except Exception as e:
|
|
238
|
+
import traceback
|
|
239
|
+
|
|
240
|
+
traceback.print_exc()
|
|
241
|
+
error_response = WorkflowErrorEvent(
|
|
242
|
+
error=str(e),
|
|
243
|
+
error_type=e.type if hasattr(e, "type") else None,
|
|
244
|
+
error_id=e.error_id if hasattr(e, "error_id") else None,
|
|
245
|
+
)
|
|
246
|
+
yield format_sse_event(error_response)
|
|
247
|
+
return
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def get_websocket_router(
|
|
251
|
+
os: "AgentOS",
|
|
252
|
+
settings: AgnoAPISettings = AgnoAPISettings(),
|
|
253
|
+
) -> APIRouter:
|
|
254
|
+
"""
|
|
255
|
+
Create WebSocket router with support for both legacy (os_security_key) and JWT authentication.
|
|
256
|
+
|
|
257
|
+
WebSocket endpoints handle authentication internally via message-based auth.
|
|
258
|
+
Authentication methods (in order of precedence):
|
|
259
|
+
1. JWT tokens - if JWTMiddleware is configured (via app.state.jwt_middleware)
|
|
260
|
+
2. Legacy bearer token - if settings.os_security_key is set
|
|
261
|
+
3. No authentication - if neither is configured
|
|
262
|
+
|
|
263
|
+
The JWT middleware instance is accessed from app.state.jwt_middleware, which is set
|
|
264
|
+
by AgentOS when authorization is enabled. This allows reusing the same validation
|
|
265
|
+
logic and loaded keys as the HTTP middleware.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
os: The AgentOS instance
|
|
269
|
+
settings: API settings (includes os_security_key for legacy auth)
|
|
270
|
+
"""
|
|
271
|
+
ws_router = APIRouter()
|
|
272
|
+
|
|
273
|
+
@ws_router.websocket(
|
|
274
|
+
"/workflows/ws",
|
|
275
|
+
name="workflow_websocket",
|
|
276
|
+
)
|
|
277
|
+
async def workflow_websocket_endpoint(websocket: WebSocket):
|
|
278
|
+
"""WebSocket endpoint for receiving real-time workflow events"""
|
|
279
|
+
# Check if JWT validator is configured (set by AgentOS when authorization=True)
|
|
280
|
+
jwt_validator = getattr(websocket.app.state, "jwt_validator", None)
|
|
281
|
+
jwt_auth_enabled = jwt_validator is not None
|
|
282
|
+
|
|
283
|
+
# Determine auth requirements - JWT takes precedence over legacy
|
|
284
|
+
requires_auth = jwt_auth_enabled or bool(settings.os_security_key)
|
|
285
|
+
|
|
286
|
+
await websocket_manager.connect(websocket, requires_auth=requires_auth)
|
|
287
|
+
|
|
288
|
+
# Store user context from JWT auth
|
|
289
|
+
websocket_user_context: Dict[str, Any] = {}
|
|
290
|
+
|
|
291
|
+
try:
|
|
292
|
+
while True:
|
|
293
|
+
data = await websocket.receive_text()
|
|
294
|
+
message = json.loads(data)
|
|
295
|
+
action = message.get("action")
|
|
296
|
+
|
|
297
|
+
# Handle authentication first
|
|
298
|
+
if action == "authenticate":
|
|
299
|
+
token = message.get("token")
|
|
300
|
+
if not token:
|
|
301
|
+
await websocket.send_text(json.dumps({"event": "auth_error", "error": "Token is required"}))
|
|
302
|
+
continue
|
|
303
|
+
|
|
304
|
+
if jwt_auth_enabled and jwt_validator:
|
|
305
|
+
# Use JWT validator for token validation
|
|
306
|
+
try:
|
|
307
|
+
payload = jwt_validator.validate_token(token)
|
|
308
|
+
claims = jwt_validator.extract_claims(payload)
|
|
309
|
+
await websocket_manager.authenticate_websocket(websocket)
|
|
310
|
+
|
|
311
|
+
# Store user context from JWT
|
|
312
|
+
websocket_user_context["user_id"] = claims["user_id"]
|
|
313
|
+
websocket_user_context["scopes"] = claims["scopes"]
|
|
314
|
+
websocket_user_context["payload"] = payload
|
|
315
|
+
|
|
316
|
+
# Include user info in auth success message
|
|
317
|
+
await websocket.send_text(
|
|
318
|
+
json.dumps(
|
|
319
|
+
{
|
|
320
|
+
"event": "authenticated",
|
|
321
|
+
"message": "JWT authentication successful.",
|
|
322
|
+
"user_id": claims["user_id"],
|
|
323
|
+
}
|
|
324
|
+
)
|
|
325
|
+
)
|
|
326
|
+
except Exception as e:
|
|
327
|
+
error_msg = str(e) if str(e) else "Invalid token"
|
|
328
|
+
error_type = "expired" if "expired" in error_msg.lower() else "invalid_token"
|
|
329
|
+
await websocket.send_text(
|
|
330
|
+
json.dumps(
|
|
331
|
+
{
|
|
332
|
+
"event": "auth_error",
|
|
333
|
+
"error": error_msg,
|
|
334
|
+
"error_type": error_type,
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
)
|
|
338
|
+
continue
|
|
339
|
+
elif validate_websocket_token(token, settings):
|
|
340
|
+
# Legacy os_security_key authentication
|
|
341
|
+
await websocket_manager.authenticate_websocket(websocket)
|
|
342
|
+
else:
|
|
343
|
+
await websocket.send_text(json.dumps({"event": "auth_error", "error": "Invalid token"}))
|
|
344
|
+
continue
|
|
345
|
+
|
|
346
|
+
# Check authentication for all other actions (only when required)
|
|
347
|
+
elif requires_auth and not websocket_manager.is_authenticated(websocket):
|
|
348
|
+
auth_type = "JWT" if jwt_auth_enabled else "bearer token"
|
|
349
|
+
await websocket.send_text(
|
|
350
|
+
json.dumps(
|
|
351
|
+
{
|
|
352
|
+
"event": "auth_required",
|
|
353
|
+
"error": f"Authentication required. Send authenticate action with valid {auth_type}.",
|
|
354
|
+
}
|
|
355
|
+
)
|
|
356
|
+
)
|
|
357
|
+
continue
|
|
358
|
+
|
|
359
|
+
# Handle authenticated actions
|
|
360
|
+
elif action == "ping":
|
|
361
|
+
await websocket.send_text(json.dumps({"event": "pong"}))
|
|
362
|
+
|
|
363
|
+
elif action == "start-workflow":
|
|
364
|
+
# Add user context to message if available from JWT auth
|
|
365
|
+
if websocket_user_context:
|
|
366
|
+
if "user_id" not in message and websocket_user_context.get("user_id"):
|
|
367
|
+
message["user_id"] = websocket_user_context["user_id"]
|
|
368
|
+
# Handle workflow execution directly via WebSocket
|
|
369
|
+
await handle_workflow_via_websocket(websocket, message, os)
|
|
370
|
+
|
|
371
|
+
else:
|
|
372
|
+
await websocket.send_text(json.dumps({"event": "error", "error": f"Unknown action: {action}"}))
|
|
373
|
+
|
|
374
|
+
except Exception as e:
|
|
375
|
+
if "1012" not in str(e) and "1001" not in str(e):
|
|
376
|
+
logger.error(f"WebSocket error: {e}")
|
|
377
|
+
finally:
|
|
378
|
+
# Clean up the websocket connection
|
|
379
|
+
await websocket_manager.disconnect_websocket(websocket)
|
|
380
|
+
|
|
381
|
+
return ws_router
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def get_workflow_router(
|
|
385
|
+
os: "AgentOS",
|
|
386
|
+
settings: AgnoAPISettings = AgnoAPISettings(),
|
|
387
|
+
) -> APIRouter:
|
|
388
|
+
"""Create the workflow router with comprehensive OpenAPI documentation."""
|
|
389
|
+
router = APIRouter(
|
|
390
|
+
dependencies=[Depends(get_authentication_dependency(settings))],
|
|
391
|
+
responses={
|
|
392
|
+
400: {"description": "Bad Request", "model": BadRequestResponse},
|
|
393
|
+
401: {"description": "Unauthorized", "model": UnauthenticatedResponse},
|
|
394
|
+
404: {"description": "Not Found", "model": NotFoundResponse},
|
|
395
|
+
422: {"description": "Validation Error", "model": ValidationErrorResponse},
|
|
396
|
+
500: {"description": "Internal Server Error", "model": InternalServerErrorResponse},
|
|
397
|
+
},
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
@router.get(
|
|
401
|
+
"/workflows",
|
|
402
|
+
response_model=List[WorkflowSummaryResponse],
|
|
403
|
+
response_model_exclude_none=True,
|
|
404
|
+
tags=["Workflows"],
|
|
405
|
+
operation_id="get_workflows",
|
|
406
|
+
summary="List All Workflows",
|
|
407
|
+
description=(
|
|
408
|
+
"Retrieve a comprehensive list of all workflows configured in this OS instance.\n\n"
|
|
409
|
+
"**Return Information:**\n"
|
|
410
|
+
"- Workflow metadata (ID, name, description)\n"
|
|
411
|
+
"- Input schema requirements\n"
|
|
412
|
+
"- Step sequence and execution flow\n"
|
|
413
|
+
"- Associated agents and teams"
|
|
414
|
+
),
|
|
415
|
+
responses={
|
|
416
|
+
200: {
|
|
417
|
+
"description": "List of workflows retrieved successfully",
|
|
418
|
+
"content": {
|
|
419
|
+
"application/json": {
|
|
420
|
+
"example": [
|
|
421
|
+
{
|
|
422
|
+
"id": "content-creation-workflow",
|
|
423
|
+
"name": "Content Creation Workflow",
|
|
424
|
+
"description": "Automated content creation from blog posts to social media",
|
|
425
|
+
"db_id": "123",
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
)
|
|
433
|
+
async def get_workflows(request: Request) -> List[WorkflowSummaryResponse]:
|
|
434
|
+
if os.workflows is None:
|
|
435
|
+
return []
|
|
436
|
+
|
|
437
|
+
# Filter workflows based on user's scopes (only if authorization is enabled)
|
|
438
|
+
if getattr(request.state, "authorization_enabled", False):
|
|
439
|
+
from agno.os.auth import filter_resources_by_access, get_accessible_resources
|
|
440
|
+
|
|
441
|
+
# Check if user has any workflow scopes at all
|
|
442
|
+
accessible_ids = get_accessible_resources(request, "workflows")
|
|
443
|
+
if not accessible_ids:
|
|
444
|
+
raise HTTPException(status_code=403, detail="Insufficient permissions")
|
|
445
|
+
|
|
446
|
+
accessible_workflows = filter_resources_by_access(request, os.workflows, "workflows")
|
|
447
|
+
else:
|
|
448
|
+
accessible_workflows = os.workflows
|
|
449
|
+
|
|
450
|
+
return [WorkflowSummaryResponse.from_workflow(workflow) for workflow in accessible_workflows]
|
|
451
|
+
|
|
452
|
+
@router.get(
|
|
453
|
+
"/workflows/{workflow_id}",
|
|
454
|
+
response_model=WorkflowResponse,
|
|
455
|
+
response_model_exclude_none=True,
|
|
456
|
+
tags=["Workflows"],
|
|
457
|
+
operation_id="get_workflow",
|
|
458
|
+
summary="Get Workflow Details",
|
|
459
|
+
description=("Retrieve detailed configuration and step information for a specific workflow."),
|
|
460
|
+
responses={
|
|
461
|
+
200: {
|
|
462
|
+
"description": "Workflow details retrieved successfully",
|
|
463
|
+
"content": {
|
|
464
|
+
"application/json": {
|
|
465
|
+
"example": {
|
|
466
|
+
"id": "content-creation-workflow",
|
|
467
|
+
"name": "Content Creation Workflow",
|
|
468
|
+
"description": "Automated content creation from blog posts to social media",
|
|
469
|
+
"db_id": "123",
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
404: {"description": "Workflow not found", "model": NotFoundResponse},
|
|
475
|
+
},
|
|
476
|
+
dependencies=[Depends(require_resource_access("workflows", "read", "workflow_id"))],
|
|
477
|
+
)
|
|
478
|
+
async def get_workflow(workflow_id: str, request: Request) -> WorkflowResponse:
|
|
479
|
+
workflow = get_workflow_by_id(workflow_id, os.workflows)
|
|
480
|
+
if workflow is None:
|
|
481
|
+
raise HTTPException(status_code=404, detail="Workflow not found")
|
|
482
|
+
|
|
483
|
+
return await WorkflowResponse.from_workflow(workflow)
|
|
484
|
+
|
|
485
|
+
@router.post(
|
|
486
|
+
"/workflows/{workflow_id}/runs",
|
|
487
|
+
tags=["Workflows"],
|
|
488
|
+
operation_id="create_workflow_run",
|
|
489
|
+
response_model_exclude_none=True,
|
|
490
|
+
summary="Execute Workflow",
|
|
491
|
+
description=(
|
|
492
|
+
"Execute a workflow with the provided input data. Workflows can run in streaming or batch mode.\n\n"
|
|
493
|
+
"**Execution Modes:**\n"
|
|
494
|
+
"- **Streaming (`stream=true`)**: Real-time step-by-step execution updates via SSE\n"
|
|
495
|
+
"- **Non-Streaming (`stream=false`)**: Complete workflow execution with final result\n\n"
|
|
496
|
+
"**Workflow Execution Process:**\n"
|
|
497
|
+
"1. Input validation against workflow schema\n"
|
|
498
|
+
"2. Sequential or parallel step execution based on workflow design\n"
|
|
499
|
+
"3. Data flow between steps with transformation\n"
|
|
500
|
+
"4. Error handling and automatic retries where configured\n"
|
|
501
|
+
"5. Final result compilation and response\n\n"
|
|
502
|
+
"**Session Management:**\n"
|
|
503
|
+
"Workflows support session continuity for stateful execution across multiple runs."
|
|
504
|
+
),
|
|
505
|
+
responses={
|
|
506
|
+
200: {
|
|
507
|
+
"description": "Workflow executed successfully",
|
|
508
|
+
"content": {
|
|
509
|
+
"text/event-stream": {
|
|
510
|
+
"example": 'event: RunStarted\ndata: {"content": "Hello!", "run_id": "123..."}\n\n'
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
400: {"description": "Invalid input data or workflow configuration", "model": BadRequestResponse},
|
|
515
|
+
404: {"description": "Workflow not found", "model": NotFoundResponse},
|
|
516
|
+
500: {"description": "Workflow execution error", "model": InternalServerErrorResponse},
|
|
517
|
+
},
|
|
518
|
+
dependencies=[Depends(require_resource_access("workflows", "run", "workflow_id"))],
|
|
519
|
+
)
|
|
520
|
+
async def create_workflow_run(
|
|
521
|
+
workflow_id: str,
|
|
522
|
+
request: Request,
|
|
523
|
+
background_tasks: BackgroundTasks,
|
|
524
|
+
message: str = Form(...),
|
|
525
|
+
stream: bool = Form(True),
|
|
526
|
+
session_id: Optional[str] = Form(None),
|
|
527
|
+
user_id: Optional[str] = Form(None),
|
|
528
|
+
):
|
|
529
|
+
kwargs = await get_request_kwargs(request, create_workflow_run)
|
|
530
|
+
|
|
531
|
+
if hasattr(request.state, "user_id"):
|
|
532
|
+
if user_id:
|
|
533
|
+
log_warning("User ID parameter passed in both request state and kwargs, using request state")
|
|
534
|
+
user_id = request.state.user_id
|
|
535
|
+
if hasattr(request.state, "session_id"):
|
|
536
|
+
if session_id:
|
|
537
|
+
log_warning("Session ID parameter passed in both request state and kwargs, using request state")
|
|
538
|
+
session_id = request.state.session_id
|
|
539
|
+
if hasattr(request.state, "session_state"):
|
|
540
|
+
session_state = request.state.session_state
|
|
541
|
+
if "session_state" in kwargs:
|
|
542
|
+
log_warning("Session state parameter passed in both request state and kwargs, using request state")
|
|
543
|
+
kwargs["session_state"] = session_state
|
|
544
|
+
if hasattr(request.state, "dependencies"):
|
|
545
|
+
dependencies = request.state.dependencies
|
|
546
|
+
if "dependencies" in kwargs:
|
|
547
|
+
log_warning("Dependencies parameter passed in both request state and kwargs, using request state")
|
|
548
|
+
kwargs["dependencies"] = dependencies
|
|
549
|
+
if hasattr(request.state, "metadata"):
|
|
550
|
+
metadata = request.state.metadata
|
|
551
|
+
if "metadata" in kwargs:
|
|
552
|
+
log_warning("Metadata parameter passed in both request state and kwargs, using request state")
|
|
553
|
+
kwargs["metadata"] = metadata
|
|
554
|
+
|
|
555
|
+
# Retrieve the workflow by ID
|
|
556
|
+
workflow = get_workflow_by_id(workflow_id, os.workflows)
|
|
557
|
+
if workflow is None:
|
|
558
|
+
raise HTTPException(status_code=404, detail="Workflow not found")
|
|
559
|
+
|
|
560
|
+
if session_id:
|
|
561
|
+
logger.debug(f"Continuing session: {session_id}")
|
|
562
|
+
else:
|
|
563
|
+
logger.debug("Creating new session")
|
|
564
|
+
session_id = str(uuid4())
|
|
565
|
+
|
|
566
|
+
# Return based on stream parameter
|
|
567
|
+
try:
|
|
568
|
+
if stream:
|
|
569
|
+
return StreamingResponse(
|
|
570
|
+
workflow_response_streamer(
|
|
571
|
+
workflow,
|
|
572
|
+
input=message,
|
|
573
|
+
session_id=session_id,
|
|
574
|
+
user_id=user_id,
|
|
575
|
+
background_tasks=background_tasks,
|
|
576
|
+
**kwargs,
|
|
577
|
+
),
|
|
578
|
+
media_type="text/event-stream",
|
|
579
|
+
)
|
|
580
|
+
else:
|
|
581
|
+
run_response = await workflow.arun(
|
|
582
|
+
input=message,
|
|
583
|
+
session_id=session_id,
|
|
584
|
+
user_id=user_id,
|
|
585
|
+
stream=False,
|
|
586
|
+
background_tasks=background_tasks,
|
|
587
|
+
**kwargs,
|
|
588
|
+
)
|
|
589
|
+
return run_response.to_dict()
|
|
590
|
+
|
|
591
|
+
except InputCheckError as e:
|
|
592
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
593
|
+
except Exception as e:
|
|
594
|
+
# Handle unexpected runtime errors
|
|
595
|
+
raise HTTPException(status_code=500, detail=f"Error running workflow: {str(e)}")
|
|
596
|
+
|
|
597
|
+
@router.post(
|
|
598
|
+
"/workflows/{workflow_id}/runs/{run_id}/cancel",
|
|
599
|
+
tags=["Workflows"],
|
|
600
|
+
operation_id="cancel_workflow_run",
|
|
601
|
+
summary="Cancel Workflow Run",
|
|
602
|
+
description=(
|
|
603
|
+
"Cancel a currently executing workflow run, stopping all active steps and cleanup.\n"
|
|
604
|
+
"**Note:** Complex workflows with multiple parallel steps may take time to fully cancel."
|
|
605
|
+
),
|
|
606
|
+
responses={
|
|
607
|
+
200: {},
|
|
608
|
+
404: {"description": "Workflow or run not found", "model": NotFoundResponse},
|
|
609
|
+
500: {"description": "Failed to cancel workflow run", "model": InternalServerErrorResponse},
|
|
610
|
+
},
|
|
611
|
+
dependencies=[Depends(require_resource_access("workflows", "run", "workflow_id"))],
|
|
612
|
+
)
|
|
613
|
+
async def cancel_workflow_run(workflow_id: str, run_id: str):
|
|
614
|
+
workflow = get_workflow_by_id(workflow_id, os.workflows)
|
|
615
|
+
|
|
616
|
+
if workflow is None:
|
|
617
|
+
raise HTTPException(status_code=404, detail="Workflow not found")
|
|
618
|
+
|
|
619
|
+
if not workflow.cancel_run(run_id=run_id):
|
|
620
|
+
raise HTTPException(status_code=500, detail="Failed to cancel run")
|
|
621
|
+
|
|
622
|
+
return JSONResponse(content={}, status_code=200)
|
|
623
|
+
|
|
624
|
+
return router
|