- agent_runner: local directory + cloud agent orchestration via Redis - 5 domain agents: filesystem, task, note, project, timeline - integrations: Gmail, MS Graph (Outlook + Teams) - journey: guided chatbot conversation to build prompt_template - routes: REST endpoints (catalog, can-create, trigger) - redis_consumer: subscribes to batch:request:* pattern - ws_context: Redis-based execute_on_client for tool round-trip - Dockerfile with 300s timeout for long-running batch jobs
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
"""Batch Agent Service — FastAPI application.
|
|
|
|
Owns: agent_runner (local directory + cloud connectors), journey builder,
|
|
filesystem_agent, integrations (Gmail, MS Graph).
|
|
|
|
Communicates with WS Gateway via Redis:
|
|
- Subscribes to batch:request:{user_id} (journey_start, journey_message)
|
|
- Publishes to ws:out:{user_id} (journey replies + tool calls)
|
|
- BRPOP on tool:result:{call_id} (tool-call round-trip, 30s timeout)
|
|
- SET+EX on journey:{user_id} (journey session state, TTL 1800s)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
|
|
from contextlib import asynccontextmanager
|
|
from typing import AsyncGenerator
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.redis_consumer import start_consumer
|
|
from app.routes import router
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
logger.info("batch-agent: starting Redis consumer")
|
|
task = asyncio.create_task(start_consumer())
|
|
yield
|
|
task.cancel()
|
|
try:
|
|
await task
|
|
except asyncio.CancelledError:
|
|
pass
|
|
logger.info("batch-agent: Redis consumer stopped")
|
|
|
|
|
|
app = FastAPI(title="Adiuva Batch Agent Service", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["GET", "POST"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(router)
|
|
|
|
|
|
@app.get("/health")
|
|
async def health() -> dict[str, str]:
|
|
return {"status": "ok", "service": "batch-agent"}
|