Context Handling
Agent Actions makes the prompt context in the same way in batch mode and in online mode. The template pattern is {{ source.field }} in the two modes. The rest of this page gives the reason.
Mode Differences
For your templates, the two modes have no differences. In batch mode and in online mode, each record starts with an empty base dict. The framework then merges in only the data that context_scope admits, under the namespaces that it admits. For the same context_scope configuration, the final Jinja context is identical in the two modes.
| Property | Online | Batch |
|---|---|---|
The start base for templates | {} | {} |
| The namespace of the source data | source namespace | source namespace |
| The namespace of the seed data | seed namespace | seed namespace |
| The namespace of the upstream action output | {action_name} namespace | {action_name} namespace |
| The correct template pattern | {{ source.field }} | {{ source.field }} |
A bare {{ field }} works | No | No |
Online Mode
{
"source": {
"content": "Document text...",
"url": "https://example.com"
},
"seed": { "exam_syllabus": {...} }
}
Analyze: {{ source.content }}
Batch Mode
{
"source": {
"content": "Document text...",
"url": "https://example.com"
},
"seed": { "exam_syllabus": {...} }
}
Analyze: {{ source.content }}
Use {{ source.field }} in batch prompts and in online prompts. Before the framework renders a prompt, it puts the input of each record under the source namespace. Thus {{ source.field }} gives the value of each record identically in the two modes.
Do not use a bare {{ field }}. Before the framework renders the template, base is empty. Thus field is not defined, and the template render fails (Jinja StrictUndefined). This occurs in the two modes.
Do not use unwrapped variables, for example {{ content }} in place of {{ source.content }}. The two modes do not accept them. If a prompt contains {{ passage }}, write {{ source.passage }} in its place.
Mode-Agnostic Templates
A template does not need {% if source is defined %} conditionals or other code that finds the mode. By design, a template works in the two modes:
Content: {{ source.content }}
This template renders in the same way when the run_mode of the action is online and when it is batch.
Context Variables
| Variable | Description | Available In |
|---|---|---|
source | The input record (always under this namespace) | The two modes |
seed | Static seed data | The two modes |
{action_name} | The output of an upstream action (also a namespace) | The two modes |
Each item in your context_scope.observe list gets to the template. It is under the namespace prefix that the list declares for it. The framework puts no data at the root level.
Context Scope
Use context_scope to control which data an action can see:
actions:
- name: my_action
dependencies: [prev_action]
context_scope:
observe:
- source.content
- seed.exam_syllabus
- prev_action.result
drop:
- source.sensitive_field
The same configuration works identically in the two modes.
The Request to the Model
The two modes also send the same request. For the same prompt, record, schema and json_mode, a batch request holds the messages that the online request holds. The prompt, the record and the schema instructions are in the same places.
Agent Actions sends the record to the model as JSON. It does not escape text that is not ASCII. A NaN or an infinite number becomes null. A field that the prompt prints is not sent again in that JSON, unless the action sets context_block: all. See The context block.
A prompt that is too large for the context window of the model fails its record in the two modes. In batch mode, Agent Actions does not send that record. It sends the other records of the batch. A judge request that is too large fails only its judge call, with judge call failed: <error>, as online. Agent Actions sends the other judge requests.
Agent Actions estimates the size of a prompt as its number of characters divided by 4. It compares the estimate with the context window of the model. For OpenAI in text mode, Gemini, Groq, Ollama and a judge call, Agent Actions uses a window of 128,000 tokens. If the prompt has more than about 512,000 characters, Agent Actions does not send it. The context_window of the action replaces the window for every vendor and every call.
The estimate counts every message of the request: the rendered prompt and the context block. By default (context_block: auto), a field that the prompt prints as it is goes out once, in the prompt, so the estimate counts it once. With context_block: all, the field is in the request two times, and the estimate counts it two times. See The context block.
When context_window is not set, Agent Actions takes the window of a model from a fixed list of model names (in agent_actions/prompt/message_builder.py). A model name that is not in the list gets 128,000 tokens, also when the model accepts more. If a large record fails with Estimated prompt size (N tokens) exceeds model context window (M tokens) and the model reads more, set context_window. If the record is larger than the real window, split its longest field with chunk_config.field, or observe a shorter field.
Best Practices
- Always put a namespace on the fields in a template —
{{ source.field }},{{ seed.field }},{{ upstream_action.field }}. Never use a bare{{ field }}. - Select a mode for cost or latency, not for templates —
run_mode: batchchanges when the LLM calls occur. It does not change the context that the prompt sees. - Use seed data for static content — seed data works identically in the two modes.
- Examine the rendered prompts —
agac traces -w <workflow> -A <action>shows the exact text that the LLM received.
See Also
- Run Modes — Batch execution and online execution (what changes when you change the mode)
- Context Scope — Configure the fields that an action can see