Call Graph Context
Why Clean returns callers, callees, and neighbours alongside every top search result.
A function rarely makes sense in isolation. To understand "what does this do?" an agent usually also needs "what does it call?" and "who calls it?". Clean answers those questions in the same response by attaching the top result's call-graph neighbourhood.
What's attached
For the rank #1 result, search_code includes three relationship blocks:
CALLS →— the functions this entity calls (its callees).CALLED BY ←— the functions that call this entity (its callers).SAME FILE— sibling entities defined in the same file.
This pre-empts the agent's likely next question and prevents a follow-up search.
How deep
The depth argument controls how far the graph is walked:
depth | What you get |
|---|---|
0 | Just the matched entities, no relationships. |
1 (default) | Direct callers and callees. |
2 | Two levels of relationships. |
3 | Maximum (the handler clamps higher values to 3). |
Why it's cheap to compute
Gathering a neighbourhood naively means one database lookup per node — O(branching^depth) queries. Clean instead issues one batched query per depth level (O(depth) total), tracks a visited set to handle cycles, and caps each direction at 50 entities so a heavily-connected function can never blow up the query count or the response size.
The result: richer context, far fewer round-trips, and a bounded response. See How Clean reduces cost.