Spaces:
Paused
Paused
| """Agent router.""" | |
| from __future__ import annotations | |
| import logging | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from pydantic import BaseModel, Field | |
| from hermes.agents.orchestrator.agent import OrchestratorAgent | |
| from hermes.api.middleware import sanitize_input | |
| from hermes.core.auth import get_api_key_dependency | |
| logger = logging.getLogger(__name__) | |
| router = APIRouter(dependencies=[Depends(get_api_key_dependency)]) | |
| class RunAgentRequest(BaseModel): | |
| task: str = Field(..., max_length=2000, description="Task to execute") | |
| strategy: str = Field(default="react", description="Reasoning strategy") | |
| class AgentResponse(BaseModel): | |
| status: str | |
| result: str | |
| steps: int | |
| orchestrator = OrchestratorAgent() | |
| async def run_agent(request: RunAgentRequest) -> AgentResponse: | |
| task = sanitize_input(request.task, max_length=2000) | |
| try: | |
| report = await orchestrator.execute_research(task) | |
| return AgentResponse( | |
| status="completed", | |
| result=report.summary, | |
| steps=len(report.findings), | |
| ) | |
| except Exception as e: | |
| logger.error(f"Agent execution failed: {e}", exc_info=True) | |
| raise HTTPException(status_code=500, detail="Agent execution failed") from e | |
| async def list_agents() -> dict: | |
| return { | |
| "agents": [ | |
| {"type": "orchestrator", "description": "Coordinates multi-agent workflows"}, | |
| {"type": "research", "description": "Conducts research and information gathering"}, | |
| {"type": "code_analysis", "description": "Analyzes code quality and patterns"}, | |
| {"type": "security", "description": "Performs security scans and vulnerability analysis"}, | |
| {"type": "planning", "description": "Creates implementation plans"}, | |
| {"type": "report", "description": "Generates comprehensive reports"}, | |
| ] | |
| } | |