File size: 1,364 Bytes
2f235a0
 
 
 
 
 
 
 
 
 
 
 
 
 
c16e1c9
2f235a0
 
c16e1c9
 
2f235a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# =============================================================
# File: backend/api/routes/agent.py
# =============================================================

from fastapi import APIRouter
from pydantic import BaseModel
import os
import sys
from pathlib import Path

# Add backend to path for imports
backend_dir = Path(__file__).parent.parent.parent
sys.path.insert(0, str(backend_dir))

from api.services.agent_orchestrator import AgentOrchestrator
from api.models.agent import AgentRequest, AgentResponse


router = APIRouter()


orchestrator = AgentOrchestrator(
    rag_mcp_url=os.getenv("RAG_MCP_URL", "http://localhost:8001"),
    web_mcp_url=os.getenv("WEB_MCP_URL", "http://localhost:8002"),
    admin_mcp_url=os.getenv("ADMIN_MCP_URL", "http://localhost:8003"),
    llm_backend=os.getenv("LLM_BACKEND", "ollama")
)


class ChatRequest(BaseModel):
    tenant_id: str
    user_id: str | None = None
    message: str
    conversation_history: list[dict] = []
    temperature: float = 0.0


@router.post("/message", response_model=AgentResponse)
async def agent_chat(req: ChatRequest):
    agent_req = AgentRequest(
        tenant_id=req.tenant_id,
        user_id=req.user_id,
        message=req.message,
        conversation_history=req.conversation_history,
        temperature=req.temperature
    )
    return await orchestrator.handle(agent_req)