Selector de agentes

This commit is contained in:
Jordan Diaz
2026-04-07 10:57:40 +00:00
parent 38ac9cecdc
commit c1a29bbbf8
30 changed files with 760 additions and 357 deletions

View File

@@ -1,7 +1,7 @@
"""Orchestrator Engine — single-agent execution.
Flow: message → coder agent (with tools) → response
No planner, no reviewer. The coder decides what to do.
Flow: message → selected agent (with tools) → response
The agent is determined by the session's agent_id via AgentRegistry.
"""
from __future__ import annotations
@@ -15,16 +15,16 @@ from ..config import settings
from ..context.engine import ContextEngine
from ..mcp.manager import MCPManager
from ..memory.store import MemoryStore
from ..models.agent import AgentRole
from ..models.agent import AgentProfile
from ..models.session import SessionState, SessionStatus, TaskStatus
from ..streaming.sse import SSEEmitter, EventType
from .agents.coder import CoderAgent, create_coder_profile
from .agents.base import BaseAgent
logger = logging.getLogger(__name__)
class OrchestratorEngine:
"""Drives execution for a session message. Single agent, no planning."""
"""Drives execution for a session message with the selected agent."""
def __init__(
self,
@@ -33,13 +33,14 @@ class OrchestratorEngine:
mcp_client: MCPManager,
memory_store: MemoryStore,
sse_emitter: SSEEmitter,
agent_profile: AgentProfile,
) -> None:
self.model = model_adapter
self.context = context_engine
self.mcp = mcp_client
self.memory = memory_store
self.sse = sse_emitter
self._coder_profile = create_coder_profile()
self.agent_profile = agent_profile
# ------------------------------------------------------------------
# Public
@@ -84,11 +85,15 @@ class OrchestratorEngine:
session: SessionState,
message: str,
) -> dict[str, Any]:
"""Execute: message → coder → response."""
"""Execute: message → agent → response."""
await self.sse.emit(
EventType.EXECUTION_STARTED,
{"session_id": session.session_id, "message": message[:200]},
{
"session_id": session.session_id,
"agent_id": session.agent_id,
"message": message[:200],
},
session_id=session.session_id,
)
@@ -96,9 +101,9 @@ class OrchestratorEngine:
task = session.begin_task(objective=message)
task.status = TaskStatus.EXECUTING
# Execute with the coder agent directly
agent = CoderAgent(
profile=self._coder_profile,
# Execute with the selected agent
agent = BaseAgent(
profile=self.agent_profile,
model_adapter=self.model,
context_engine=self.context,
mcp_client=self.mcp,
@@ -130,6 +135,7 @@ class OrchestratorEngine:
session.task_history.append({
"task_id": task.task_id,
"objective": message,
"agent_id": session.agent_id,
"status": "completed",
"steps": 1,
"facts": task.facts_extracted[-10:],
@@ -167,6 +173,7 @@ class OrchestratorEngine:
{
"session_id": session.session_id,
"task_id": task.task_id,
"agent_id": session.agent_id,
"steps_completed": 1,
"steps_failed": [],
"status": "completed",
@@ -177,8 +184,9 @@ class OrchestratorEngine:
)
logger.info(
"Task %s completed (%d tools, %d artifacts, %d input tokens)",
"Task %s completed (agent=%s, %d tools, %d artifacts, %d input tokens)",
task.task_id,
session.agent_id,
len(result.get("tool_executions", [])),
len(result.get("artifacts", [])),
total_input,
@@ -187,6 +195,7 @@ class OrchestratorEngine:
return {
"session_id": session.session_id,
"task_id": task.task_id,
"agent_id": session.agent_id,
"content": content or "Task completed.",
"steps_completed": 1,
"steps_failed": [],