# Discovery, Routing and Delegation — MCP & Agent-to-Agent Protocols

Source: https://www.geekswithgeeks.com/en/mcp-a2a/a-discover

> Choose which remote agent should handle a job.

## Match need to advertised skill

A client agent needs a way to find candidates: a **configured list** of trusted agent URLs, an internal **registry** or catalogue of Agent Cards, or **direct knowledge** between partners. Routing then compares the job with the cards' **skills and descriptions**, ideally using exact ids or tags first and a model only for ambiguous cases. Delegation decisions should consider **trust** (is this agent approved for this data?), **cost and latency**, and **fallbacks** (what if it is down or declines?). If no agent advertises the needed skill, say so and escalate to a human rather than guessing. Pass the remote agent **only the data it needs**, since it operates outside your boundary.

## Skill-based routing, run

I ran this with plain Python 3 (standard library only). Refund work maps to the billing agent and compliance work to the legal agent. A request for "poetry" matches no advertised skill, so the code escalates to a human instead of guessing.

```python
AGENTS = {
    "billing": {"skills": {"invoice", "refund"}},
    "legal":   {"skills": {"contract", "compliance"}},
    "support": {"skills": {"faq", "troubleshoot"}},
}

def discover(needed_skill):
    return [name for name, card in AGENTS.items() if needed_skill in card["skills"]]

for skill in ("refund", "compliance", "poetry"):
    found = discover(skill)
    print(skill, "->", found if found else "no agent advertises this skill; escalate to a human")

```

Output:

```
refund -> ['billing']
compliance -> ['legal']
poetry -> no agent advertises this skill; escalate to a human
```

**Quiz:** What should happen when no agent advertises the needed skill?

- [ ] Send the data to everyone
- [ ] Pick a random agent
- [x] Say so and escalate rather than guess
- [ ] Ignore the request

*Answer:* Say so and escalate rather than guess. Guessing can leak data to an unsuitable agent.
