add_routing_rule
Add a new routing rule to a strategy by specifying keywords, agent name, and priority to manage communication between ACP agents and MCP clients effectively.
Instructions
Add a new routing rule to a strategy
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_name | Yes | ||
| description | No | ||
| keywords | Yes | ||
| priority | No | ||
| strategy_name | Yes |
Implementation Reference
- acp_mcp_server/agent_router.py:212-247 (handler)The FastMCP tool handler for 'add_routing_rule'. Parses comma-separated keywords, creates a RoutingRule instance, and appends it to an existing strategy or creates a new RouterStrategy.@mcp.tool() async def add_routing_rule( strategy_name: str, keywords: str, # Comma-separated agent_name: str, priority: int = 5, description: str = "" ) -> str: """Add a new routing rule to a strategy""" try: keyword_list = [k.strip() for k in keywords.split(",")] new_rule = RoutingRule( keywords=keyword_list, agent_name=agent_name, priority=priority, description=description or f"Route to {agent_name}" ) # Get or create strategy if strategy_name in router.strategies: strategy = router.strategies[strategy_name] strategy.rules.append(new_rule) else: strategy = RouterStrategy( name=strategy_name, description=f"Custom strategy: {strategy_name}", rules=[new_rule] ) router.strategies[strategy_name] = strategy return f"Successfully added rule: {keyword_list} -> {agent_name}" except Exception as e: return f"Error: {e}"
- acp_mcp_server/agent_router.py:9-13 (schema)Pydantic model defining the structure of routing rules, directly used in the add_routing_rule handler to instantiate new rules.class RoutingRule(BaseModel): keywords: List[str] agent_name: str priority: int = 1 description: str = ""
- acp_mcp_server/server.py:88-88 (registration)Registers all router tools, including 'add_routing_rule', by calling register_router_tools during ACPMCPServer initialization in _register_all_tools method.register_router_tools(self.mcp, self.router)
- acp_mcp_server/agent_router.py:188-188 (registration)The registration function that defines and registers the add_routing_rule tool (and others) with the FastMCP instance using @mcp.tool() decorators.def register_router_tools(mcp: FastMCP, router: AgentRouter):