Добавить FastAPI endpoint запуска сценария через AgentOS base_app.

Подключен верхний HTTP-слой с POST /api/runs и обновлены схемы/README, чтобы запуск сценариев шел через единый API-контракт поверх Agno workflow.
This commit is contained in:
Barabashka
2026-04-21 17:37:36 +03:00
parent d341941f87
commit 0fbd7dce1a
4 changed files with 73 additions and 3 deletions
+34 -1
View File
@@ -6,7 +6,7 @@
## Требования
- Python 3.11+
- Python 3.10+
- Запущенный Ollama endpoint (по умолчанию: `http://localhost:11435`)
- Доступная модель в Ollama (по умолчанию: `gemma4:31b`)
@@ -23,11 +23,13 @@ prisma_platform/
│ └── v1.json
└── src/
├── __init__.py
├── api_routes.py
├── agent_os.py
├── agent_runner.py
├── main.py
├── observability.py
├── scenario_store.py
├── schemas.py
├── stub_tools.py
└── workflow_runner.py
```
@@ -76,6 +78,37 @@ python -m src.agent_os
- `http://127.0.0.1:7777/docs`
- `http://127.0.0.1:7777/redoc`
Верхний слой сервиса реализован как кастомные FastAPI роуты (`src/api_routes.py`), подключенные через `AgentOS(base_app=...)`.
### Запуск сценария через HTTP
- `POST http://127.0.0.1:7777/api/runs`
- Тело запроса (JSON):
```json
{
"scenario_id": "news_source_discovery_v1",
"input": {
"url": "https://example.com/news"
}
}
```
Пример запроса:
```bash
curl -X POST "http://127.0.0.1:7777/api/runs" \
-H "Content-Type: application/json" \
-d '{
"scenario_id": "news_source_discovery_v1",
"input": {
"url": "https://example.com/news"
}
}'
```
Endpoint возвращает структурированный ответ со статусом `success` или `failed`.
Проверка, что сервер поднят:
```bash
+13 -1
View File
@@ -1,9 +1,11 @@
import os
from dotenv import load_dotenv
from fastapi import FastAPI
from agno.os import AgentOS
from src.api_routes import router as api_router
from src.agent_runner import get_agent
from src.observability import init_phoenix_tracing
from src.scenario_store import load_scenario_definition
@@ -16,7 +18,17 @@ _agent = get_agent()
_default_scenario_id = "news_source_discovery_v1"
_scenario = load_scenario_definition(_default_scenario_id)
_workflow = get_workflow_for_scenario(_default_scenario_id, _scenario)
_agent_os = AgentOS(agents=[_agent], workflows=[_workflow], tracing=_tracing_enabled)
_base_app = FastAPI(
title="Prisma Platform API",
version="0.1.0",
)
_base_app.include_router(api_router)
_agent_os = AgentOS(
agents=[_agent],
workflows=[_workflow],
tracing=_tracing_enabled,
base_app=_base_app,
)
app = _agent_os.get_app()
+17
View File
@@ -0,0 +1,17 @@
from fastapi import APIRouter
from pydantic import TypeAdapter
from src.schemas import ScenarioRunRequest, ScenarioRunResponse
from src.workflow_runner import run_scenario_workflow
router = APIRouter(prefix="/api", tags=["workflow"])
_run_response_adapter = TypeAdapter(ScenarioRunResponse)
@router.post("/runs", response_model=ScenarioRunResponse)
async def run_scenario(request: ScenarioRunRequest) -> ScenarioRunResponse:
result = await run_scenario_workflow(
input_data=request.input,
scenario_id=request.scenario_id,
)
return _run_response_adapter.validate_python(result)
+9 -1
View File
@@ -2,7 +2,7 @@ from __future__ import annotations
from typing import Any, Literal
from pydantic import BaseModel
from pydantic import BaseModel, Field
class RunError(BaseModel):
@@ -10,6 +10,11 @@ class RunError(BaseModel):
message: str
class ScenarioRunRequest(BaseModel):
scenario_id: str = "news_source_discovery_v1"
input: dict[str, Any] = Field(default_factory=dict)
class ScenarioRunBase(BaseModel):
scenario_id: str
status: Literal["success", "failed"]
@@ -29,3 +34,6 @@ class ScenarioRunSuccess(ScenarioRunBase):
result: dict[str, Any]
run_id: str | None = None
session_id: str | None = None
ScenarioRunResponse = ScenarioRunSuccess | ScenarioRunFailed