Context policies
ContextPolicy controls what prior information an agent sees on each step: earlier step outputs, the original run input, and size limits. It applies in both Linear workflows and Graph workflows. Graph state from node outputs may also arrive via exec_config.initial_state and the runtime map.
Agent overview: Defining agents. workflow specification types: Workflow specification.
ContextPolicy fields
| Field | Type | Default | Meaning |
|---|---|---|---|
include_prior_steps | "none" | "last" | "all" | "last" | Which prior step outputs to inject |
include_run_input | boolean | true | Include original run input string |
max_prior_step_chars | integer | 4096 | Truncate prior step text to this length |
Engine default for max_prior_step_chars is 4096 (verified in types.rs).
include_prior_steps modes
"last" (default)
Only the immediately preceding step output is included. Typical for pipelines where each stage refines the previous result.
"all"
All completed prior steps are included up to max_prior_step_chars budget (implementation applies per-step truncation rules). Use when downstream agents need full chain context; watch token costs.
"none"
Prior step text is omitted. The agent still receives run input if include_run_input is true. Useful for isolated classification steps that should not be biased by earlier prose.
include_run_input
When true, the original input passed to workflow.run(input) or POST /v1/runs is available to the agent prompt assembly. Set false when later steps should only see structured prior outputs or memory, not the raw user message.
Example for a summarize-only second step:
max_prior_step_chars
Prevents unbounded prompt growth from large intermediate outputs. Prior text is trimmed before provider request (ProviderRequestSent records prompt_size_bytes in trace, not content).
Raise the limit for long-document workflows:
Balance against model context window and cost.
Graph workflows and initial_state
Graph nodes may write keys via outputs:
Seed or resume graph state through exec_config:
Context policy and graph state compose: policy controls step output text; graph state supplies structured fields the engine merges into agent context per scheduler rules.
Memory vs context policy
| Mechanism | Purpose |
|---|---|
| Context policy | Ephemeral prompt assembly from run history |
| Memory types | Durable or scoped key-value and vector retrieval |
Use shared memory for multi-agent handoff that must survive truncation limits:
Multi-agent linear example
Step 1 researcher with full user input; step 2 writer with last step only:
Trace visibility
Context assembly is not a separate trace event. Related events:
AgentInvokedwithinput_size_bytesProviderRequestSentwithprompt_size_bytes
No prompt text appears in traces (trace data policy).