Usage
The agent's working cycle with RAGRAF — ensure, search, the graph, reading a body; the rule "navigation by operation, content by reading", freshness and stale_warnings, and what to do on a refusal. Examples taken from a real corpus.
Updated: 2026-11-10
The rule the product exists for #
Navigation by operation, content by reading. The question "where is this" is worth one call, not a dozen file reads; the question "how exactly is it written" needs the body of a function, and code is what gives it. Mixing these two questions means paying in tokens for what the index already knows.
The five-step cycle #
| Step | Operation | What you get |
|---|---|---|
| 1. Refresh | ensure | the corpus status: actual, reindexed, created, not_a_project, error |
| 2. Find | search, search_multi | hits with path:line, a score and an explanation of "why it matched" |
| 3. Understand the layout | symbol, callers, callees, impact | the declaration, callers, callees, the price of an edit |
| 4. Check before editing | table_usage, write_check, policy_trace | who reads and writes, whether a write like that is allowed, who is granted the right |
| 5. Read the text | code, doc_get, live_read | a symbol body from the index, a document fragment, a live file |
ensure is the first call of any session: it is also what locates the corpus by project directory and creates it if there is no corpus yet.
Example: one question, three calls #
Measured on this site's corpus (PHP, 87 operations available; the revision is in the index_rev field):
python tools/ragraf.py -p config/site.yaml --json query search "locale switcher" --limit 3{"op": "search", "index_rev": "rev-0014", "capability": "full", "found": true,
"limits": ["static analysis; runtime values are not covered"],
"result": [{"path": "languages/site-ru_RU.php", "start_line": 111, "end_line": 230,
"score": 11.1111, "why": "matched on: lexical", "source_kind": "file"}],
"freshness": {"rev_id": "rev-0014", "stale": false, "verified_by": "fingerprint"}}What comes next is no longer search but the graph: who calls what was found, and what will break.
python tools/ragraf.py -p config/site.yaml query callers "Site\Support\Locale::htmlLang"The callers answer carries not only names but also the kind of evidence for each edge:
| Field | Value in the measurement |
|---|---|
provenance | stated — the link is confirmed by the analyser; derived — inferred from the name |
confidence | 1.0 for a confirmed one, 0.6 for an inferred one |
evidence | src/Support/Locale.php:128, src/Components/LanguageSwitcher.php:135 |
limits | "1 confirmed by CPG, 5 of 6 inferred (83.3 %) — an inferred link is not evidence" |
That is exactly why the answer carries limits: the agent can see that three quarters of the links are inferred, and does not call them confirmed.
The body of the function comes as the third call, and only if it is genuinely needed:
python tools/ragraf.py -p config/site.yaml query code "Site\Support\Locale::label"src/Support/Locale.php:53-64 (text_source: index)Freshness: what stale means #
Every answer has a freshness block and, on divergence, stale_warnings. The values:
| Field | What it means |
|---|---|
stale: false | the code has not changed since the last indexing; the facts can be trusted |
stale: true | the files have changed; the facts describe the past — they must not be passed off as the current state |
changed_since_index | for a particular fragment: whether it changed after indexing |
verified_by | what verified it: the corpus fingerprint or a checksum comparison |
The rule is simple: stale: true does not mean "almost current", it means "wrong". ensure first, work after.
A refusal is an answer too #
If an operation cannot answer, it does not silently return emptiness. A refusal carries a kind (kind), a cause (problem, why), one command (action) and the flag possible — whether this is fixable at all. This is what a real refusal looks like before the first indexing:
index is missing: python tools/ragraf.py -p <config> index. Build the index:
python tools/ragraf.py -p <config> index (or python tools/ragraf.py ensure <project dir>)The same refusal in machine form (next_action from src/ragraf/util.py):
{"operation": "symbol", "kind": "no_index", "problem": "the corpus has no index",
"why": "the operation reads the index, and it has not been built yet",
"action": "python tools/ragraf.py -p <config> index", "action_note": "", "possible": true}The full list of refusal kinds is on the Errors and the next step page. Not one of them suggests "try again": each one names an action.
Task and statistics: why name the task #
If task_set is called in a session (or the ragraf_task tool), calls are attributed to the task, and task_stats shows how many calls there were and what share of facts arrived with a file:line address. This is the only way to check the value of the rollout without surveys: numbers, not impressions.
python tools/ragraf.py -p config/site.yaml query task_set --name "documentation migration"
python tools/ragraf.py -p config/site.yaml query task_statsWhat the agent gets in a session #
When connected over MCP, the ragraf_* tools are available (their list is on the MCP tools reference page). The difference from the CLI is exactly one thing: the transport. The answer comes from the same code, so index_rev, limits and stale_warnings match.
Boundaries stated plainly #
- The index is static: dynamic calls (
call_user_func, reflection) do not enter the graph and
are flagged in limits.
- Search answers "where the text resembles the question", not "where the answer is": lexis and
vectors decide.
- The index lives in the project directory (
.ragraf/) and does not update itself: freshness is
your responsibility, and ensure is your tool.
- If a capability is not unlocked by the edition, the operation answers with an
editionrefusal
rather than an empty result: "no rights" and "no data" are different answers.