You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use Claude for routing, implement a new MCP tool in the gateway agent that calls Claude with a prompt to decide the routing. Here's how:
New Tool in Gateway Agent: Add a new tool to gateway-agent/service.py. This tool will receive the user input and call Claude to determine the routing.
Prompt for Claude: Create a prompt to send to Claude. The prompt should ask Claude to classify the user input as either "personal-trainer" or "work-assistant".
Process Claude's Response: Receive Claude's response and extract the routing decision.
Route the Task: Based on Claude's classification, call the appropriate downstream server using the method in your current code.
Example Code Snippet (gateway-agent/service.py):
# ... existing code@server.call_tool() # new route toolasyncdefclaude_route(name: str, arguments: dict) ->str:
ifname!="route_by_claude":
raiseValueError(f"Unknown tool: {name}")
user_input=arguments.get("user_input")
ifnotuser_input:
raiseValueError("Missing 'user_input' argument.")
claude_prompt=f"""Classify the following user query as either "personal-trainer" or "work-assistant": User Query: {user_input}"""# Replace with your actual call to Claudetry:
claude_response=get_claude_response(claude_prompt)
print(f"Claude response: {claude_response}", file=sys.stderr) # Log Claude's decisionif"personal-trainer"inclaude_response.lower():
target_server=SERVER_Aelif"work-assistant"inclaude_response.lower():
target_server=SERVER_Belse:
# Default or error handlingtarget_server=SERVER_Bresult=ask_mcp_server(target_server["url"], target_server["tool_name"], user_input)
return [TextContent(type="text", text=result)]
exceptExceptionase:
print(f"Error: {e}")
return [TextContent(type="text", text="Error during routing")]
# function to interface with claudedefget_claude_response(prompt: str) ->str:
client=anthropic.Anthropic()
completion=client.completions.create(
model="claude-instant-v1", # Or whichever model you wantmax_tokens_to_sample=30,
prompt=f"{anthropic.HUMAN_PROMPT}{prompt}{anthropic.AI_PROMPT}",
)
returncompletion.completion# ... rest of existing code
This outlines the core functionalities of the mcp-agent-router project. Remember to consult the MCP documentation for more information.
The text was updated successfully, but these errors were encountered:
Adding Claude API Call for Routing
To use Claude for routing, implement a new MCP tool in the gateway agent that calls Claude with a prompt to decide the routing. Here's how:
New Tool in Gateway Agent: Add a new tool to
gateway-agent/service.py
. This tool will receive the user input and call Claude to determine the routing.Prompt for Claude: Create a prompt to send to Claude. The prompt should ask Claude to classify the user input as either "personal-trainer" or "work-assistant".
Process Claude's Response: Receive Claude's response and extract the routing decision.
Route the Task: Based on Claude's classification, call the appropriate downstream server using the method in your current code.
Example Code Snippet (gateway-agent/service.py):
This outlines the core functionalities of the
mcp-agent-router
project. Remember to consult the MCP documentation for more information.The text was updated successfully, but these errors were encountered: