Skip to main content

Run Modes

Agent Actions supports two execution modes: online (real-time) and batch (cost-optimized).

Overview​

ModeProcessingLatencyCostUse Case
onlineSynchronousReal-timeStandardInteractive, development
batchAsynchronousHoursUp to 50% savingsProduction, large datasets

Configuration​

yaml
YAML
defaults:
run_mode: batch # or "online"

actions:
- name: my_action
run_mode: online # Override per-action
note

run_mode accepts the string values batch and online (case-insensitive). These values map to the RunMode enum internally.

note

Tool actions and human-in-the-loop (HITL) actions always run online, also in a batch workflow. For these actions, Agent Actions accepts a run_mode: batch from defaults: or on the action, and shows no message. Agent Actions stages, runs and reports these actions as online actions.

Online Mode​

Online mode processes requests synchronously, with immediate responses. An LLM action sends one record at a time, unless the action sets record_concurrency.

yaml
YAML
defaults:
run_mode: online

When to use:

  • Development and testing
  • Interactive applications
  • Small datasets (fewer than 100 records)
  • Debugging workflows

Batch Mode​

Batch mode puts requests in a queue for asynchronous batch processing, with significant cost savings.

yaml
YAML
defaults:
run_mode: batch

When to use:

  • Production workloads
  • Large datasets (100+ records)
  • Cost-sensitive processing
  • Scheduled jobs and overnight jobs

Provider Support​

ProviderBatch APICost Savings
OpenAIYes, except an action with base_url~50%
AnthropicYes~50%
Google GeminiYesVaries
GroqYesVaries
OllamaNo. Agent Actions runs the batch in its own processN/A

Ollama batch​

Ollama has no batch API. For ollama_local and ollama_cloud, a run_mode: batch action sends its records from the Agent Actions process, when the run submits the batch. The run then collects the answers as it collects the answers of any batch. The records, the rules of an expect: block and the stored output are those of a batch action.

Two settings control how many records Agent Actions sends at the same time. Each setting applies to one run mode only:

SettingApplies toDefault
record_concurrencyAn online LLM action, of any vendor1
batch_max_workersAn Ollama action in run_mode: batch1
yaml
YAML
defaults:
model_vendor: ollama_local
run_mode: batch
batch_max_workers: 4 # every Ollama batch action sends 4 records at a time

actions:
- name: classify
batch_max_workers: 8 # this action sends 8
  • batch_max_workers is an integer from 1 to 32. Set it on an action or in defaults:.
  • If no action or default sets it, the OLLAMA_BATCH_MAX_WORKERS environment variable gives the value. If the variable is unset, is not an integer or is below 1, the value is 1. A value above 32 from the variable becomes 32.
  • An Ollama batch action does not read record_concurrency. The load refuses record_concurrency on a batch action. On an Ollama batch action, the message names batch_max_workers. If the action inherits record_concurrency from defaults:, the action ignores it.
  • An online Ollama action does not read batch_max_workers. A batch action of another vendor does not read it either, because the provider runs the batch.
  • Agent Actions sends the judge batch of an Ollama batch action (see Judging in batch) in the same way, batch_max_workers requests at a time.
  • Each request of an Ollama batch waits the request_timeout of the action, or 600 seconds if the action sets none.

Memory while a batch step prepares​

A batch action prepares its requests one input file at a time. The store keeps the output of an action as one entry for each input file. Thus, to read a record, the store reads all of the records of that file. While the action prepares a file, it holds:

  • The records of that file, with the namespace of each action above it. This is the largest part.
  • One request for each record of the file. A request holds only what the prompt observes.
  • The context map of the batch. Collection rebuilds each output row from this map. The map holds each record of the file, and it shares the record with the input. The store keeps the map in parts of about 4 MB. Thus a save does not make a second copy of the file in memory.

The action lets the file go before it reads the next file. Thus the memory grows with the largest input file, and not with all of the files. To lower the peak, split a large staging file into smaller files.

All of the actions of a step run at the same time, up to --concurrency-limit (default 5). Each batch action of the step holds one file. An online action beside it also holds the file that it processes. For a step with large records, use one of these settings:

SettingWhat it limitsEffect on the other actions
batch_preparation_concurrency in the workflow fileThe batch actions of a step that prepare at the same timeAn online action of the step continues to run beside them. A batch action that collects is not limited
--concurrency-limit 1 or --execution-mode sequentialEvery action of the runAn online action of the step waits for the batch actions, or the batch actions wait for the online action. An online action can run for many minutes, so the batch requests can go out much later

Each batch file writes a Prepared {action}/{file} in ... line to the run log. The line gives the time, the number of records and requests, and the peak memory of the process. Each StepCompleteEvent has peak_rss_mb. Use these values to find the step and the file that use the most memory.

How a batch reads an answer​

A batch action reads each answer as the same action reads the answer online:

  • With json_mode: false, the action stores the answer as text in its output_field. The action also stores an answer that contains JSON as text. The request does not offer the schema as a tool. If an Anthropic answer holds a tool call (from a tool in vendor_params), the action stores only the text of the answer, as the online action does. An answer that holds a tool call and no text fails the record, as the online action does.
  • With json_mode: true and no schema, the action runs. For OpenAI, Groq, Gemini and Ollama, the request asks for JSON output, as the online request does. For Anthropic, the action reads the text answer as JSON, as the online action does.
  • If an answer does not match the schema of the action, the action stores the answer and the run log shows a Schema validation warning line. To enforce the schema, add an expect: block.
  • The action applies the passthrough rules of the online action. The action stores an answer item that holds source_guid and content as its content. A dropped passthrough field that has the name of a namespace copies that namespace.

When the provider refuses a batch​

Agent Actions sends each input file as a separate batch. The provider can refuse a batch (a network error, a request that the provider rejects). If the provider refuses a batch, the run fails the action after the run walks all files. The run fails the action even when the provider took the batches of the other files of the action.

There is one exception. If the provider refuses a batch because the quota of the account is at its limit, the run stops at that file. The run exits with code 5 and fails no record (see quota stop). After you add credits, the next run sends that file and the files after it.

Run the workflow again. The next run sends again the records of the refused file that have no answer yet. The run keeps the records that the action already answered, in that file or in any other file. The run keeps a batch that is still at the provider for another file. The run collects that batch, and does not send it again.

A run collects batches only after a run that sent all files. Thus, while the provider refuses a file, the batches that are already at the provider for the other files wait. The run names these batches. A refusal that continues holds these batches for as long as the refusal continues. An example is a request that the provider rejects each time. A provider keeps results only for a limited time. Fix the file that the error names, or remove the file from the input. Then run the workflow again.

When the provider cannot be reached while collecting​

Before a run reads the results of a finished batch, the run asks the provider about the batch. The run cannot reach the provider if the call cannot connect, times out, or gets a server error. If the run cannot reach the provider about one batch, the run reads the other batches. The run does not change that batch. Then the run pauses, as it does while a batch is still at the provider. The run names the file that it could not read.

To collect the batch, run the workflow again. The next run sends nothing again. The next run does not read again the files that a run already read.

A run that cannot reach the provider while it checks whether its batches have finished pauses in the same way. The run continues to pause for as long as the provider cannot be asked. To abandon those batches, use agac run --fresh --abandon-in-flight. This command sends each record of the workflow again.

When the run cannot read the results of one file​

The run can fail while it reads the results of one file. An example is an error from the SDK of the provider while the run downloads the results. This error is a failure of that file only. The run marks the records of that file as failed, with the error as the reason. Then the run reads the other files.

  • If the run reads another file of the action, or an earlier run read one, the action completes with failures (exit code 3). agac retry sends the records of that file again.
  • If no file of the action is read, because the action has one file or because every file fails, the action fails with the error "No batch results were successfully processed" (exit code 1). The files stay in the batch registry, not collected. Run the workflow again without --fresh to read them. The first run after the failure can report the batch as submitted. Run again until the run reads the results.
  • If the run waits for another file (see the section above), the action pauses.

If the run fails after it wrote the results of the file, for example while it removes the recovery batches of that file, the records keep the answers that the run wrote. The run logs a warning that names the file and the error.

Some errors stop the run at the file, because each file fails in the same way, or because the run cannot keep what it read:

  • An expect: block that the run cannot resolve. An example is a suite: that the run cannot load.
  • A store that fails to write the file.

The action fails, and the next run reads that file again.

To mark the records of a file as failed, the run reads what it sent in the batch of that file. If the run cannot read it, the records stay deferred. Thus the run reads the other files, and then fails the action with an error that names each of these files. If another file halts the action in the same pass (for example under on_exhausted: raise), the action fails with that halt instead, and these files are named only in a warning in the log. In both cases the files stay in the batch registry, not collected, and the next run reads them again.

When the provider omits a record​

A batch can come back finished, with a record missing from its results. If retry is enabled (see Retry), the action sends that record again in a retry batch (Batch Recovery). If retry is disabled, or if nothing will send the record again, the record fails with the reason batch_not_returned. The action completes with failures, and the downstream actions skip the record. agac retry sends the record again.

When the provider ends a batch without results​

agac reads nothing from these batches, in this run or in any later run:

  • A batch that the provider failed or cancelled before the batch finished.
  • A batch that used all of the time window of the provider (expired for OpenAI and Groq, JOB_STATE_EXPIRED for Gemini).
  • A batch that the provider answers about but no longer reports as finished. An example is a batch that the provider now reports as failed or expired.

For such a batch, the run reads the other files and names the file and its batch. The run marks the records of that file as failed. The run completes the action with those failures, so that agac retry can send the records again. agac retry sends each record of the file again. These records include the records that an expired OpenAI or Groq batch already answered. The provider keeps those answers, but agac does not read them.

If the run cannot read the store, the run cannot mark those records. In this case, the run pauses as for a batch that is still at the provider. The next run marks the records. If the provider ended the batch of each file in this way, the run fails the action instead. The next run sends each file again.

A batch that the provider is still cancelling has not ended. The run pauses as for a batch that is still at the provider. After the provider reports the batch as cancelled, a later run marks its records as failed, as described above. An Anthropic batch that was canceled while it ran ends with a result for each request. The run reads that batch like any other batch.

When the provider reports a status agac does not know​

agac maps the batch statuses of each provider to its own statuses. agac treats a status that no mapping knows as still running. An example is a status that a provider adds later. The run pauses and names the batch and the status. Each later run asks the provider again, until the provider reports a status that agac knows.

When a file's input changes while its batch is out​

A batch answers the records that it got. A record can leave the input of a file while the batch of that file is at the provider. For example, you remove the record from staging. A run that resumes the action reads the input again in two cases. The first case is after a collect pass stopped partway. The second case is after a run that checked on the batch was interrupted. That run does not write the answer of the departed record into the file, as online mode does.

A file that all its records left waits for its batch like any other file. Then the system stores the file empty. This is also true for a file whose input is gone completely.

A change to the staged input while a batch is out is answered after the batch. The run that collects the batch then runs the batch action again in the same run, and keeps its answers. That pass sends the records that you added or changed in a new batch, and forgets the records that are no longer staged. The actions after the batch action run when that batch is collected. Thus every action gets the same records as the first action. This is also true when the batch action is the first action of the workflow, and when a check on the batch stopped before the change (Ctrl-C, a crash, or an error from the provider).

In each case, the provider has already answered the records that it got. After a batch is at the provider, you pay for its answers, whether the run keeps them or not.

Batch Commands​

bash
BASH
# Check batch status
agac batch status --batch-id batch_abc123

# Retrieve completed results
agac batch retrieve --batch-id batch_abc123

# Retry failed records
agac retry -w my_workflow

For the complete CLI reference, see batch Commands.

The top-level retry command retries the failed records of a batch action, as it does for an online action. The retry submits a batch that holds only the records that it names. The next run collects that batch. While a batch is still at the provider, the retry command refuses the retry. Run the workflow again to collect the batch first. Pass --abandon-in-flight only when the provider no longer has the batch. See Retrying an action that runs in batch mode.

Mixing Modes​

For a hybrid workflow, override the mode at the action level:

yaml
YAML
defaults:
run_mode: batch

actions:
- name: bulk_extraction
# Uses default batch mode

- name: interactive_validation
run_mode: online # Override for this action

Switching an interrupted online action to batch​

If an online run stops partway through a file, the run keeps the finished records as checkpoint rows. The run keeps these rows until the file is written. If you then set run_mode: batch, the batch run sends those records again with the rest of the file. Thus the provider answers each record a second time, and you pay for each record a second time. If you resume the action online, the action keeps those answers. The action sends only the records that it did not finish.

The same rule applies when an earlier run also stored the file. For example, agac run --rerun answered a completed action again, and that run was stopped. If you resume the action online, each record that the rerun answered keeps that answer. That answer takes the place of the row stored before it. If you change the action to batch, the batch run sends each of these records again. Neither the online resume nor the batch run keeps the row stored before the rerun.

See Also​