Created
October 5, 2025 00:29
-
-
Save matthew-harper/a7b193ae25547f01ab0dcfc533b0139c to your computer and use it in GitHub Desktop.
Pattern 5 — Agents as Tools: Routing to Specialists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydantic import BaseModel, Field | |
| class RouteDecision(BaseModel): | |
| target: str = Field(description="Target specialist (math, code, generalist)") | |
| reason: str = Field(description="Why this target was chosen") | |
| confidence: float = Field(description="Confidence score (0.0-1.0)") | |
| def route_query(q: str) -> RouteDecision: | |
| ql = q.lower() | |
| if any(k in ql for k in ["factor", "integrate", "derivative", "+", "*", "^", "solve", "math"]): | |
| return RouteDecision(target="math", reason="Mathematical keywords detected", confidence=0.85) | |
| elif any(k in ql for k in ["python", "error", "debug", "code", "compile", "syntax"]): | |
| return RouteDecision(target="code", reason="Programming keywords detected", confidence=0.78) | |
| else: | |
| return RouteDecision(target="generalist", reason="No specialist domain detected", confidence=0.60) | |
| if __name__ == "__main__": | |
| print(route_query("Factor x^2 + 7x + 12")) | |
| print(route_query("Why does my Python code raise a TypeError?")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment