Context Blocks
Context blocks are live data feeds for agent prompts. Before every agent request, registered context blocks run in parallel to fetch real-time data — CRM profiles, active tasks, user memory, knowledge base summaries — and inject it into the system prompt. The agent sees your live organizational context without you pasting it into every message.How it works
- Context blocks are registered with the
@context_blockdecorator, declaring which agent(s) they apply to - Before a chat request, all blocks for the target agent run in parallel
- Each block returns a text string (or empty to skip)
- The rendered strings are injected into the agent’s system prompt as
runtime_prompt_blocks - Results are cached per-user with a 5-minute TTL to avoid redundant data fetches
Built-in context blocks
| Block | Source | What it provides |
|---|---|---|
| CRM context | Connected CRM | User’s title, department, org hierarchy, rep management structure, CRM field mappings |
| Tasks | Task system | Active tasks, follow-ups, and due items for the current user |
| User memory | Memory service | Persistent memory — learned preferences, facts, and behavioral patterns distilled from past conversations |
| Knowledge | Knowledge bases | Summaries of attached knowledge bases available for retrieval |
| Personalization | User settings | Style/tone preferences, custom instructions, and about-user profile |
Pre-warming
Context blocks can be pre-warmed before the user sends their first message. Your client calls the warm endpoint when the chat interface opens, caching all context so the first chat message doesn’t incur block-building latency.SDK
REST API
Listing and inspecting context blocks
SDK
REST API
Per-agent scoping
Context blocks declare which agents they apply to. The CRM context block might only run forMainAgent, while the tasks block runs for all agents. This ensures each agent only receives context relevant to its domain.
Entity resolution
In addition to background context blocks, AgentFlow supports inline entity resolution viacontext_refs on chat requests. When a user @mentions a CRM account or contact, the entity resolver fetches its data and injects it directly into the current turn:
Cache management
- TTL: 5 minutes per user per agent
- Max entries: 200 (LRU eviction when full)
- Invalidation: updating user memory or settings automatically invalidates the cache
- Per-execution snapshots: each agent execution gets its own snapshot, so sub-agents build independent context

