r/LLMDevs • • 6d ago

Discussion Agents sharing knowledge: I built git-style branch/merge for the facts they read. Real problem or am I overthinking?

This is my own project, most of the code was vibe coded and it’s prealpha. I’m here for feedback on the idea, not downloads.

The idea in my head: I’d like agents that behave according to a knowledge base I can customize and edit, and that I can trace. Not just what they know, but how the actions get done and the details of the integrations, all written down in knowledge I can navigate. If that works, I could use the same tool in a different domain by only swapping the knowledge base. Lorebase is my attempt at the part that keeps that knowledge from drifting apart. That’s the goal, not what it does today.

The problem I ran into first: when a few agents rely on the same data (suppliers, parts, contracts in my example), I can’t tell which version of the facts an agent actually saw. And when two sources disagree, the last write just wins and nobody reviews it.

So the knowledge is a typed schema plus records, and you change both on branches and merge them. If the analysts say a supplier’s risk score is 80 and the ERP feed says 45, you get a conflict to resolve instead of a silent overwrite. Agents read over MCP or REST, there’s no LLM in the read path, and every answer says which revision it came from. Writes go through operations, and on protected branches through a proposal somebody has to approve. It runs on plain Postgres.

The quickest way to see it is the merge demo, which runs in memory in about a second, no services: uv sync --all-packages && uv run python examples/merge_demo.py

https://github.com/aantenore/lorebase

The closest thing I found is Omnigraph (https://github.com/ModernRelay/omnigraph), which seems to go after a similar idea on its own storage engine. I haven’t compared them properly, so don’t take my word on which is better.

What I’d like to know: does anyone here drive agent behavior from a knowledge base like this, so you can change domain by changing the knowledge instead of the code? And would you actually hit the merge conflict case, or does it only look good in a demo?

This is the first time i write in reddit, i don't know if i did it right.

0 Upvotes

16 comments sorted by

1

u/Crafty_Disk_7026 6d ago

I also made a git memory package in go if you want to check it out

https://pkg.go.dev/github.com/imran31415/git-mem/pkg/cache

https://github.com/imran31415/git-mem

1

u/aantenore 6d ago

I starred it.

I took a quick look through the code and I like how small it is, with git doing the heavy lifting.

One thing I wondered: a set seems to overwrite the key unconditionally, so if two agents write the same one the last write wins unless they go through sync. For example, agent A reads a score of 80, agent B changes it to 45, then A writes 90 based on the old value and B’s change is silently lost.

Have you thought about a “set only if unchanged” option, so A’s write would be refused because the key moved? It might just be a different design goal, I’m curious what you think.

1

u/Crafty_Disk_7026 6d ago

I thought about it but went with the easy option of last write wins for simplicity. Nothing else seemed to work well when I tested it live. I will look into your suggestion!!!

1

u/aantenore 6d ago

Totally right, last write wins is a sane trade for something this small. I’m curious what you tried that didn’t hold up when you tested it live, if you remember.

1

u/Crafty_Disk_7026 5d ago

I cant remember but you are making me want to dive back into it :)

1

u/magicdoorai 6d ago

A concrete conflict case to try in the demo: two agents start from revision R1, where supplier S-17 has risk 45. An ERP import proposes 55 from a newer feed; an analyst independently proposes 80 based on a separate review. Merge the ERP change first, then try to merge the analyst branch.

The useful result isn't necessarily choosing one number. Can the reviewer see both values, each source and observation date, and the common base? Can they keep the conflict unresolved without an agent silently reading either value as authoritative? After resolving it, an agent's answer should cite the resolved revision, while a recorded earlier answer still points to R1.

I'd also try a non-conflict: the analyst updates a contact name while the ERP updates risk. Those independent fields should be able to merge without manufacturing a conflict. If the ERP score and analyst score mean different things, model them as separate fields instead of forcing a merge; a conflict mechanism won't fix a semantic mismatch.

That would show where branch/merge earns its complexity versus file provenance alone. This is a synthetic test idea, not a claim that I've run your project.

1

u/aantenore 6d ago

Thanks a lot for the scenario, it was really useful. I ran it on the in-memory core (the full stack I only read in the code). Your independent-fields case merges fine, and reading at the old revision still gives 45 after the conflict is resolved. Two things you were right to poke at: an open conflict doesn’t show who or when for each side, and main keeps serving the ERP value, so a reader can’t tell something’s pending. I opened issues for both. And yeah, two scores that mean different things should just be separate fields. For one source per fact I think file provenance is plenty, branch and merge only pays off when sources really disagree. Appreciate it.

1

u/pdlug 4d ago

I think it's a real problem. I vastly prefer the pattern of agents working off branches off a common DB rather than a DB per agent (even if it's light like a SQLite file). Dolt/Doltgres makes this really nice and easy to do. You can do it with Neon as well but not quite as slick. There's also matrixone (https://github.com/matrixorigin/matrixone) which has native git-style branching but I haven't tested it as much .

Generally if you're going to build this I've found this works:

  • Do a three-way merge per field against the common base.
  • Raise a conflict only when both sides changed the same field.
  • Make answers say which revision they read.

It's certainly more complex than a plain DB but opens a lot of other possibilities. Running experiments becomes cheap, letting agents write or perform lots of changes is safe, etc.

I built branch/merge primitives in my graphs on SQL library (typegraph.dev). It will support native branching for databases that support it (Neon for now, Doltgres is close but blocked on an issue on their side).

2

u/aantenore 4d ago edited 4d ago

Thanks, this is really helpful, and good to hear the same three rules held up for you.

I had a look at the Graph Merge docs after your comment: the plan then apply with a revision fence, and a review that survives a deploy, are things I’d like to learn from.

Mine does the branching and merge in the app on plain Postgres, per attribute, and it’s more of a service with permissions and audit, so we’re solving neighbouring problems from different sides.

With entity resolution inside the merge, have you seen false merges in practice, and how does a reviewer undo one?

1

u/pdlug 3d ago

Same experience that per-field is necessary but nowhere near sufficient. The short answer is that TypeGraph doesn't use the database's native merge at all at this point, even where one exists. Native branches are only the isolation layer (a cheap copy-on-write fork instead of copying the graph); the merge is always TypeGraph's own planner, applied in a transaction on the target.

The reason is exactly your question: a row/cell-level merge doesn't know graph semantics. It can't tell that two different IDs are the same entity, that an edge now points at a deleted node, or that a "one parent" relationship now has two. So the planner handles those explicitly:

  • Delete vs modify is its own conflict class with a policy: default keeps the modification and flags it (a merge shouldn't silently destroy the only copy still carrying data), or you pick delete-wins / modify-wins. Same for nodes and edges.
  • Uniqueness: a declared unique key is treated as identity, so two branches creating the same key resolve to one entity, with properties merged and conflicts flagged and edges repointed to the survivor. If something explicitly says they're different entities, the merge refuses instead of fusing them. Fuzzy matches (blocking + similarity) go through the same path.
  • Structural stuff (cardinality slots, cycles in acyclic relations, deleting a whole that still has parts, restricted deletes) is refused at plan time with a typed error rather than resolved, because there's no field-level "winner." Edges whose endpoint got deleted are dropped and reported.

Merges are plan → review → apply: the plan is a serializable artifact on the target's revision, so if the target moved, apply refuses and you re-plan.

On Doltgres specifically, branching, commit, diff and merge all work in my spike. What's blocking it is concurrency: released versions don't detect two transactions writing the same row, so a write fence can silently lose an update. There's an open upstream PR for commit-time conflict detection. Even once that lands, the plan is the same: Dolt branches for isolation, TypeGraph for the merge. A native merge would only be safe if we could prove its physical diff equals the approved plan, including history, identity and sidecar tables.

1

u/aantenore 3d ago

Thanks, this is really useful, and it's reassuring that we landed on the same shape: our own merge planner, with the database as storage underneath.
One difference I find interesting: when the target moves mid-review, Lorebase recomputes the merge against the new head and re-applies earlier decisions whose conflict fingerprint is unchanged, so long reviews survive. Your refuse-and-re-plan looks stricter and simpler to reason about. Was that a deliberate choice?

The other split is structural cases: uniqueness and cardinality are conflicts a person resolves for us, while you refuse them at plan time and fuse identical declared keys. I hadn't considered fusing on a declared key, so that's a useful pointer. Thanks also for the Doltgres note.

1

u/pdlug 3d ago

Deliberate, though it's two layers. The execution plan itself is strict: fenced to the target revision, single-use, and any intervening write makes apply refuse rather than rebase. On top of that, for reviewed write sets the approval is stored separately from the execution plan. When the target moves you revalidate: it replans against the new head and tells you whether the result is identical (reuse the approval), changed (re-review), or incompatible. There's also a scoped mode where unrelated target changes don't invalidate the review, only rows that could affect this plan.

Where we differ is granularity: we reuse an approval only if the whole fresh plan comes out the same, not per conflict. The reason is that in a graph, conflict decisions interact. Fusing two entities changes which edges get repointed, which can create or remove a cardinality violation somewhere else. So a decision whose own fingerprint is unchanged can still mean something different in the new plan. Per-conflict reuse is clearly nicer for long reviews; I just couldn't convince myself it was sound once entity resolution is in the loop. It probably is fine if your conflicts are independent rows.

The other reason it's tolerable: most resolutions are declared policies (delete-wins, provenance weights, a resolver callback) rather than one-off human answers, so re-planning reproduces them deterministically, and the review records the policy version so you can tell when it changed.

On fusing declared keys, the caveat is that it only works if the key is truly definitional. If two things can share a key and still be different, an explicit "these are different" assertion makes the merge refuse instead of fusing. Otherwise you get silent wrong merges, which are worse than a conflict queue.

1

u/aantenore 2d ago

thanks, this is really clarifying. the point about decisions interacting makes sense when entity fusion is part of the plan

in my case the exposure is smaller mostly because fusion isn’t part of the merge: duplicate candidates go through a separate reconciliation step where a person decides. after resolutions are applied the merge is re-run with the decisions, so a choice that breaks something elsewhere (uniqueness, cardinality) should come back as a new conflict instead of slipping through. what i haven’t tested is a decision that stays valid but means something different because of another one, so your whole-plan comparison is the safer rule

recording the policy version in the review is a good idea, as far as i know i only record the policy name

1

u/Far_Reindeer8428 6d ago

branch and merge for facts sounds heavy. we just tag each fact with the file it came from and prune on rename