Skip to content

Latest commit

 

History

History
90 lines (62 loc) · 2.71 KB

graph-memory.md

File metadata and controls

90 lines (62 loc) · 2.71 KB

Link facts in a graph

The problem

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.

How it works

Link facts in a graph.

The model reads the notes once and lists the links. Your code stores them as a graph. Then code follows the links.

  1. The model lists links, such as who reports to whom. This is structured output.
  2. A guard drops any link with a name the notes never say.
  3. 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.

The flow

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
Loading

Concepts

Run it

uv run lab graph-memory naive
uv run lab graph-memory

Add --case 2 or --case 3 to try the other cases.

Prove it

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.py

The test fails, because a name from nowhere is now stored.

Stuck points

  • An unknown answer 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.

What to watch for

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.

Where to go next

Go to Connect tools over MCP. It lets an app find tools on a server.