A charity must know who can approve a spend. The notes say who holds each fund and who reports to whom. Some people have limits, and some are away.
The first try pastes every note and the rules, then asks. The model follows the links again for each question. It can stop at the wrong person, though most of its answers are right.
The model reads the notes once and lists the links. Your code stores them as a graph. Then code follows the links.
- The model lists links, such as who reports to whom. This is structured output.
- A guard drops any link with a name the notes never say.
- Code walks from the project to the right approver.
For example, a large spend moves up from one person to the next until a limit fits.
sequenceDiagram
participant Code as Your code
participant Model
Code->>Model: list the links in these notes
Model-->>Code: links
alt the names are in the notes
Code->>Code: store the link
else a name is new
Code->>Code: drop the link
end
Code->>Code: follow the links to the approver
- The stored links form a graph.
- The check on names is a guard.
- The links come back as structured output.
uv run lab graph-memory naive
uv run lab graph-memoryAdd --case 2 or --case 3 to try the other cases.
There are six spends with a known approver. Each one runs three times. Code compares each name, out of 18. More is better.
In this run the pattern did not win. Pasting all the notes named every approver too.
| Version | Right approvers |
|---|---|
| Paste all notes | 18 |
| Graph and code | 18 |
Now break it. Open the pattern file and find keep_links. Make it keep every link. Then run the test:
uv run pytest tests/promises/test_graph_memory.pyThe test fails, because a name from nowhere is now stored.
- An
unknownanswer means a link is missing. The model did not list it. - The guard checks names, not whether a link is true. Read the links for key jobs.
Building the graph costs one large call. In our run it used fewer calls but a few more tokens. Try pasting the notes first. A graph may pay off with many more questions about the same notes. Build it again when the notes change.
Go to Connect tools over MCP. It lets an app find tools on a server.