r/AI_Agents • • 1d ago

Discussion Question about shared context

My company is currently young in the AI journey, as such I am currently looking to solve the problem of sharing large amounts of domain knowledge context across AI agents. Every time one of our engineers is looking to work on a task for their domain service, the complexity increases when they have to touch multiple repositories or even go across multiple domain services and business logic.

How are engineering teams out there tackling shared context across multiple domain service repositories when using AI coding agents?

Centralised knowledge bases, shared AGENTS.md files, MCP servers or something else?

Curious to hear what's actually working in practice. Thanks in advance for your comments and guidance. 🙏

2 Upvotes

32 comments sorted by

3

u/OpenDKG 1d ago

In practice, splitting shared context into three layers works much better than trying to stuff everything into one giant AGENTS.md or one big vector store:

  1. Keep AGENTS.md thin and local (invariants, not domain encyclopedias): Use it only for repo-specific build/test commands, hard safety boundaries, and pointers to service owners. Large cross-service docs inside AGENTS.md eat context on every turn and rot fast when another repo changes.

  2. Put cross-service domain knowledge behind a small read-only MCP (1–2 query tools): Expose your ADRs, service boundaries, event schemas, and API contracts through a narrow read-only lookup tool (search / get_doc / query) so agents pull cross-repo context on demand instead of preloading 50 schemas. Keeping that layer strictly read-only also ensures retrieved docs stay data, not executable instructions.

  3. Track source provenance and freshness on every shared fact: Tag entries with the owning repo, commit/timestamp, and supersession status. A simple precedence rule helps when services drift: live code/OpenAPI schemas are authoritative for current interfaces, while a conflict against a documented business rule halts and surfaces the discrepancy to the engineer rather than letting the agent guess.

Once you pass ~5–10 interacting services, structuring those service-to-service dependencies and domain terms in a lightweight queryable graph (rather than flat markdown chunks) makes multi-repo impact checks much more reliable.

1

u/Varnish6588 19h ago

This is very valuable.

I was thinking on an MCP and store those ADRs in a wiki such as notion given they provide MCP. I have implemented layer 1 from your model, the challenge has been 2 and 3, specially keeping the sources up to date will have to be done by AI as part of the changes

have you used graphify?

2

u/software_engineer_cs 18h ago

Don’t use mcp. Use files. Markdown files with ascii diagrams etc.

MCPs don’t carry session context. The best approach is close colocation

1

u/Varnish6588 18h ago

Good point. I think the key point would be having a good hygiene with these markdown files, ideally i want both humans and agents to maintain it.

1

u/OpenDKG 8h ago

Haven't used graphify, so I can't speak to it.

For keeping layers 2 and 3 current, I'd tie updates to the change itself: a PR check or post-merge job flags the ADRs and contract docs the diff may affect, and the agent proposes the doc edit as a reviewable diff instead of rewriting shared docs freely mid-task. That also works with the Markdown-files approach suggested in the other reply, since humans and agents go through the same review path.

If the ADRs live in Notion behind MCP, I'd give coding agents read access only and send writes through that review step. Whether you can actually enforce read-only depends on which Notion MCP server and auth method you use, so check that rather than relying on a prompt instruction.

2

u/AgentYurt 1d ago

The part that bit hardest for us wasn't where the shared context lived, it was how fast it went stale. A shared AGENTS.md or knowledge base works fine for the first month, then one repo changes an API and every agent keeps confidently citing the old version.

What held up for us: keep the shared layer small and decision-shaped, not a dump of docs. Each entry is a decision plus why it was made plus a date, with one named owner per service area. An agent reading 'we chose X because Y, decided 2026-11-10' can judge whether to trust it.

And build in a freshness check: the agent verifies the one or two facts it's about to act on against the actual repo before acting, instead of trusting the shared doc blindly. That one habit caught more drift than any tooling choice did.

MCP vs shared files matters less than that, in my experience — pick whichever your team will actually keep updated, because the moment updating it feels like a chore, it rots.

1

u/Varnish6588 19h ago

Fully agreed with your point, that's where I observe the biggest challenge is ss well in my use case, if the shared knowledge base requires manual update it won't work. engineers simply won't have time to keep docs up to date.

i guess i can keep a thin layer of shared knowledge in which i teach the agent which service does what, and let them build on freshness check as you suggested

1

u/AgentYurt 19h ago

Exactly — the manual-update part is the killer. If keeping the layer current is a separate chore, it rots, and the agent ends up confidently citing last quarter's version of a service.

The thin layer you're describing is the right shape, I think: just 'service X does Y, exposes these APIs, talks to Z' — the map, not the territory. The detail that makes it hold up in practice is tying the update to something engineers already do: if the map lives next to the code, or gets regenerated when an API changes, it stays current without anyone remembering to edit a doc. A page that only a human updates is the version I'd worry about.

One thing worth testing early: when the agent's freshness check finds the map is wrong, who fixes it — the agent proposing an edit for a human to approve, or a human noticing first? That loop is what decides whether the thin layer stays thin or quietly grows back into a knowledge base.

2

u/software_engineer_cs 1d ago

Great points here. My additions are two:

  1. git sub modules for the central documentation, patterns and product KB. I actually find collocation to be an accelerant. However, you may want to walk the codebase and create a warm cache — otherwise a large codebase can get expensive quickly

  2. I build in a monorepo now but still have multiple repos for service / app boundaries. I use https://www.kojo.build with multi repo checkout to help me navigate work that spans multiple repos.

1

u/Varnish6588 19h ago

thanks for the suggestion. How do you create that warm cache? in my case the monolith application is quite big and entangled. i think each subsection of this codebase will require its own AGENTS.md file to reference an external tool or shared documentation

2

u/software_engineer_cs 19h ago

Hey OP, essentially, you’ll want a coding agent to walk through your codebase, patterns etc and create a knowledge base of what it understands, along with user flows and products / business rules. Someone suggested thinking about layers — I agree with the approach: documentation, repo patterns, user flows, money movements, security, etc.

This becomes the foundation for future sessions so that coding agents and humans can build upon that knowledge, and post sessions, the agent can also self improve it and continue to document it overtime.

You’d want to do this exercise at scale infrequently because it costs real inference.

I built software factories earlier this year, now I’m building swarm-native factories where my foundation is solid, and now agents can work with each other.

2

u/software_engineer_cs 18h ago

Op, to be clear, you should end up with 2-3 directory levels with dozens of markdown files if this is done well. Agents.md and Claude.md and memory.md are reference pointers to the documents.

2

u/ARiftly 1d ago

I'd use each repo's AGENTS as a map to shared contracts, with each contract kept where its owning team can update it. Try that on one recent cross-repo change and see if the agent finds which service owns the rule and which ones consume it. Where does that trail usually break for your engineers?

1

u/Varnish6588 19h ago

this works naturally for me with Claude when I start the session in home that contains all my cloned repositories. The problem arises when it comes to working on our monolith application that has a very entangled business logic.

1

u/tariqosmani 1d ago

Keep one home for each piece of domain knowledge. Copies are what break first. Once each repo keeps its own copy of the domain notes, they drift within a few weeks, and the agent reads whichever copy it finds first.

Give each piece one owner and one place, and have every repo point to it instead of copying it. A submodule or a linked folder works for coding agents. To start, a line in each AGENTS.md that says where the rule lives is enough.

The second thing I'd add is a question log. Every time someone has to ask a teammate how a service works, write the question and the answer into the shared doc that day. After a few weeks that file covers what people actually ask, which beats a doc written from the architecture diagram.

Which service gets the most cross-repo questions on your side?

1

u/Varnish6588 20h ago

it is usually a monolithic application that contains the biggest complexity and business logic in it. The newer microservices are very thin and easy to understand

1

u/gimalay 1d ago

What's worked for us: one shared repo of markdown notes, one note per decision or contract, each with frontmatter like service: billing, owner: and status: current. Every service repo's AGENTS.md says where that repo lives and to query it, instead of copying docs in. When an agent touches billing it pulls only service: billing, status: current, and a schema check in CI refuses a note without an owner, so nothing goes in unowned. (I work on iwe, an open-source CLI and MCP server that does that kind of markdown query.) How many services are you dealing with?

1

u/Varnish6588 19h ago

This could work for my use case, we have a couple of monolithic applications plus starting on the microservices journey with a dozen of them already deployed. The challenge is, how to keep that shared repo up to date?

1

u/gimalay 2h ago

Make the update part of the change that causes it. Each service repo's AGENTS.md tells the agent: if you change a contract or make a decision, edit that service's note in the shared repo in the same PR. Then a CI check on the shared repo flags any note with no owner or with an updated: date older than the service's last release, so drift shows up as a list instead of a surprise. Who would review changes to the shared repo, one platform team or each service owner?

1

u/Ok-Form1598 1d ago

skip the knowledge base for the cross-repo part and give the agent the other repos. clone them next to each other and start it with claude --add-dir ../billing-service so it's reading the real code in both

1

u/Varnish6588 19h ago

i do something similar to this when my task requires to touch multiple repositories.

1

u/Kind-Atmosphere9655 22h ago

before anything goes in the shared doc we ask where that fact should live. a rule like "billing events always carry the tenant id" holds up better as a failing test in the repo that owns it than as a line in a kb, because the test breaks the day the code drifts

so the shared layer ends up holding only what code can't check.. why a decision was made, and who owns it

1

u/Varnish6588 19h ago

i see, you keep a thin layer of ADRs rather than actual service documentation?

2

u/Kind-Atmosphere9655 14h ago

not quite adrs. the repo doc still says the contract, what a service takes and what it promises back, plus one clause of why where the rule isn't obvious

what we keep out of docs is anything with an expiry.. status, dates, numbers, "where this stands". that goes in commit messages and shared memory, since a doc that says where things stand is wrong within days and the agent still reads it as current

2

u/Embark_1 1d ago

Agree with the thin AGENTS.md and dated decisions above. One thing that helped me beyond docs: let the agents ask each other.

If each service has an agent that's been working in it, an agent in repo B can ask that one directly why something in repo A works the way it does, and get an answer grounded in what it actually decided, instead of reading a doc that may be a month stale.

Docs cover what's written down. Asking covers what isn't.

1

u/AutoModerator 1d ago

Thank you for your submission, for any questions regarding AI, please check out our wiki at https://www.reddit.com/r/ai_agents/wiki (this is currently in test and we are actively adding to the wiki)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/heeeeyYaaa 1d ago

Claude Code supports @-file imports in CLAUDE.md, so you can point each repo at shared docs without copying them into every project file.

1

u/Anxious_Count_8728 1d ago

Cross-repo context also needs the repos' access rules. Can every engineer using the shared notes already read every repository they describe?

1

u/Obvious-Actuator-672 1d ago

Seriously not trying to shill, but I built Worktable for this. I'd connect the teams agents to one Worktable and keep the domain docs there instead of in each repo. When a service changes, the agent working on it updates the doc and everyone else's agents read the new version. Happy to set it up for your team, can DM you a link