By Tağmaç Çankaya · 9 July 2026
CairnBlackboardMiddleware you can drop into LangChain.
Say you point three agents at one task — a performance reviewer, a security reviewer, a DX reviewer. The obvious way to let them "collaborate" is one shared conversation passed to each agent every turn. It works on a toy example and then the token bill detonates: every turn, every agent re-reads everything every other agent already said. The cost scales with the square of the conversation, and most of it isn't thinking — it's re-reading.
Borrow from how ants coordinate. Instead of talking to each other, agents leave short traces on a shared blackboard, and each agent only ever sees its own task plus a small, bounded digest of the board. No transcript re-passing. Coordination emerges from a shared filter, not from chatter — this is stigmergy.
agent(full_transcript) every turn → tokens carried per turn keep growing.agent(my_task + bounded_digest) → tokens carried per turn stay roughly flat.DONE), so the run ends by itself instead of looping to fill a turn budget.I packaged this as Cairn, a small framework-agnostic coordination library (a cairn is a stack of stones that marks a path without a word — which is the mechanism). Cairn never calls an LLM; your model makes every call, Cairn only structures how the agents coordinate.
The langchain-cairn package gives you a CairnBlackboardMiddleware. Give every collaborating agent the same board (a file path makes it shared across agents and processes), one middleware instance each with a distinct name:
pip install langchain-cairn
from langchain.agents import create_agent
from langchain_cairn import CairnBlackboardMiddleware
board = "review-board.jsonl" # file-backed -> shared across agents/processes
perf = create_agent(
model="gpt-4o-mini", tools=[...],
middleware=[CairnBlackboardMiddleware(board, agent_name="perf")],
)
sec = create_agent(
model="gpt-4o-mini", tools=[...],
middleware=[CairnBlackboardMiddleware(board, agent_name="sec")],
)
Under the hood, the middleware uses two standard LangChain hooks:
before_model injects a bounded digest of the shared board (the last N traces, capped) — not the full history. That bounded view is the token lever.after_model captures this agent's latest output as a short trace on the board. An agent that has nothing new replies DONE and writes nothing, so the board stays signal, not chatter.In a controlled A/B on Cairn's own core — same task, same model, only the context architecture changed — the blackboard style cut input tokens ~54% and cost ~65%.
| naive full-context | minimal + blackboard | reduction | |
|---|---|---|---|
| billable input tokens | 488,477 | 222,680 | 54% |
| short-run cost (illustrative) | $4.13 | $1.44 | 65% |
pip install langchain-cairn · code + benchmark harness at github.com/echo-toolkit/cairn. I build working AI systems and automation at tagmac.dev — analyze → build → hand over. If you run it on a real workload, I'd like to hear the token delta you measure, especially where it doesn't help.