Architecture
Compressed history pattern that keeps full history for a while, then when a threshold is hit, summarizes the last chunk and replaces detailed turns with a shorter summary message. Dramatically reduces prompt size on long-running chats while maintaining gist continuity.
Full FlowZap Code
User {
n1: circle label="New message"
n2: rectangle label="See reply"
n1.handle(right) -> Agent.n3.handle(left)
Agent.n12.handle(right) -> n2.handle(left)
}
Agent {
n3: rectangle label="Append turn to history"
n4: diamond label="Summary threshold reached?"
n5: rectangle label="Request latest summary"
n6: rectangle label="Build compact prompt"
n7: rectangle label="Call LLM"
n12: rectangle label="Return answer"
n3.handle(right) -> n4.handle(left)
n4.handle(right) -> Summarizer.n8.handle(left) [label="Yes"]
n4.handle(bottom) -> n5.handle(top) [label="No"]
n5.handle(bottom) -> SummaryStore.n10.handle(top) [label="Load summary"]
n6.handle(right) -> n7.handle(left)
n7.handle(right) -> LLM.n13.handle(left)
}
Summarizer {
n8: rectangle label="Summarize recent turns"
n9: rectangle label="Store summary snapshot"
n8.handle(right) -> n9.handle(left)
n9.handle(bottom) -> SummaryStore.n11.handle(top) [label="Save summary"]
}
SummaryStore {
n10: rectangle label="Read latest summary"
n11: rectangle label="Write summary"
n10.handle(right) -> Agent.n6.handle(left)
}
LLM {
n13: rectangle label="Generate answer"
n13.handle(right) -> Agent.n12.handle(left)
}
Related templates
Architecture
Short-term context pattern where the channel sends new messages plus recent history. The agent runtime merges that with local session state, assembles the prompt, and persists the response back into history. Simple but cost and latency grow with history length.
Architecture
Identity-style memory pattern where profile data is loaded at session start. Each prompt combines system persona, user profile, and current message. New facts can be written back to profile memory. Small predictable overhead with big UX lift — the agent remembers your name, stack, tone, and constraints.
Architecture
Vector-based memory pattern where text is chunked, embedded, and stored in a vector database. On query, the question is embedded, a vector search is run, candidates are reranked, and top results are injected into the prompt. Where the agent feels like it remembers everything without hallucinating.
Architecture
Learning-from-experience pattern where every task run becomes an episode with input, actions, and outcome. Before tackling a new task, the agent fetches similar episodes and uses them as hints. Over time, the agent feels like it's learning instead of repeating the same failed plans.
Architecture
Multi-modal retrieval pattern combining semantic search, exact/keyword search, and recency search in parallel. Results are merged and reranked into a single context set. Much higher recall because the agent can find both fuzzy references and exact entities. Essential for comprehensive knowledge retrieval.
Architecture
Multi-agent coordination pattern where an orchestrator breaks work into subtasks, specialist agents pull from and push to a shared state store, and the orchestrator composes the final answer from that shared state. Multi-agent setups feel coherent instead of each assistant having its own inconsistent memory.