Sharing Context
What should each agent see?.
A company where everyone reads every email gets nothing done. A company where nobody shares anything falls apart. Agent teams have exactly the same dilemma. How much should each agent see? Too much, and they get confused. Too little, and they contradict each other.

- Everyone reads every email
- Nobody shares anything
- How much should each see?
Private work, shared results
Here's the pattern that works best. The researcher reads forty pages, and keeps its messy notes private. It only writes the finding to the shared state. The writer then sees a clean result, with none of the clutter. Run it. The writer got what it needed, in one line. Keep the working out private, and share the conclusions. That's how good teams write reports.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
customer: str
findings: dict
def researcher(state):
private_notes = "Read 40 pages. Page 12 mentions a recall. Many dead ends."
print("Researcher kept", len(private_notes), "letters private")
return {"findings": {**state["findings"], "recall": "Batch 77 chains recalled"}}
def writer(state):
print("Writer can see:", list(state))
return {"findings": {**state["findings"], "reply": f"Hi {state['customer']}: "
f"{state['findings']['recall']}."}}
g = StateGraph(State)
g.add_node("researcher", researcher)
g.add_node("writer", writer)
g.add_edge(START, "researcher")
g.add_edge("researcher", "writer")
g.add_edge("writer", END)
print(g.compile().invoke({"customer": "Priya", "findings": {}})["findings"]["reply"])Researcher kept 57 letters private Writer can see: ['customer', 'findings'] Hi Priya: Batch 77 chains recalled.
Teams inside teams
A compiled graph can be used as a node inside another graph. So here, a whole research team is one box in the bigger graph. They share the fields that have the same names, and everything else stays private. Run it. The outer graph didn't need to know how the research worked. This is how you scale. Each team owns its own graph, and it plugs in with a clean interface.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class Inner(TypedDict):
question: str
answer: str
inner = StateGraph(Inner)
inner.add_node("search", lambda s: {"answer": f"Found info on {s['question']}"})
inner.add_edge(START, "search")
inner.add_edge("search", END)
research_team = inner.compile()
class Outer(TypedDict):
question: str
answer: str
reply: str
outer = StateGraph(Outer)
outer.add_node("research", research_team)
outer.add_node("reply", lambda s: {"reply": s["answer"].upper()})
outer.add_edge(START, "research")
outer.add_edge("research", "reply")
outer.add_edge("reply", END)
print(outer.compile().invoke({"question": "chain wear"})["reply"])FOUND INFO ON CHAIN WEAR
Context rules for teams
Here are the rules. Share conclusions, not working out. Give each agent only the tools and data that it needs, which is also better security. Agree on a shared format for handing work on. And write important decisions down in one place, so that agents don't contradict one another.
Summary
Private notes, shared results, and clean interfaces. Next, a surprising way to get better answers. Make your agents disagree.
Key takeaways- Keep working notes private
- Graphs can contain graphs
- Agree on a handover format