Initial implementation of xtrm-agent multi-agent system
Multi-agent AI automation system with shared message bus, specialized roles (coder/researcher/reviewer), and deny-by-default security. - Config system with Pydantic validation and YAML loading - Async message bus with inter-agent delegation - LLM providers: Anthropic (Claude) and LiteLLM (DeepSeek/Kimi/MiniMax) - Tool system: registry, builtins (file/bash/web), approval engine, MCP client - Agent engine with tool-calling loop and orchestrator for multi-agent management - CLI channel (REPL) and Discord channel - Docker + Dockge deployment config - Typer CLI: chat, serve, status, agents commands Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
48
xtrm_agent/router.py
Normal file
48
xtrm_agent/router.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Message router — routes inbound messages to the correct agent."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
from xtrm_agent.bus import InboundMessage
|
||||
|
||||
|
||||
class Router:
|
||||
"""Routes messages to agents based on mentions, channel defaults, or delegation."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
agent_names: list[str],
|
||||
channel_defaults: dict[str, str] | None = None,
|
||||
) -> None:
|
||||
self.agent_names = set(agent_names)
|
||||
self.channel_defaults = channel_defaults or {}
|
||||
|
||||
def resolve(self, msg: InboundMessage) -> str:
|
||||
"""Determine which agent should handle this message."""
|
||||
# 1. Explicit target set by delegation or system
|
||||
if msg.target_agent and msg.target_agent in self.agent_names:
|
||||
return msg.target_agent
|
||||
|
||||
# 2. @agent_name mention in content
|
||||
mentioned = self._extract_mention(msg.content)
|
||||
if mentioned and mentioned in self.agent_names:
|
||||
return mentioned
|
||||
|
||||
# 3. Channel default
|
||||
default = self.channel_defaults.get(msg.channel)
|
||||
if default and default in self.agent_names:
|
||||
return default
|
||||
|
||||
# 4. First available agent
|
||||
return next(iter(self.agent_names)) if self.agent_names else "coder"
|
||||
|
||||
def strip_mention(self, content: str) -> str:
|
||||
"""Remove @agent_name from content."""
|
||||
return re.sub(r"@(\w+)\s*", "", content, count=1).strip()
|
||||
|
||||
def _extract_mention(self, content: str) -> str | None:
|
||||
match = re.match(r"@(\w+)", content.strip())
|
||||
if match:
|
||||
return match.group(1).lower()
|
||||
return None
|
||||
Reference in New Issue
Block a user