batch Commands
Batch mode submits all records at one time for asynchronous processing. Use batch mode when you have hundreds or thousands of records to process. To run these records one at a time is inefficient and expensive.
Submit a Batch
To submit a batch, use the standard run command with a workflow that has the batch mode configuration:
# In your workflow config
defaults:
run_mode: batch
agac run -w my_workflow
When run_mode: batch is set, Agent Actions submits the records asynchronously. Then it pauses the workflow with Workflow paused - batch job(s) submitted for: <actions>. The batch ID is in the Batch <id> submitted: <n> requests to <provider> line. Use the commands below to manage the batch from submission to retrieval.
A paused run exits with code 4 (see Exit codes). Run the workflow again to check the batch and continue.
To submit, check and collect the batch with one command, use agac run --wait:
agac run -w my_workflow --wait
agac batch <subcommand> [options]
You can run batch commands from any subdirectory in your project.
Subcommands
| Subcommand | Description |
|---|---|
status | Show the status of a batch job |
retrieve | Retrieve the results of a completed batch |
batch status
This subcommand shows when a batch job is finished.
After you submit a batch, you can poll its status. The status shows if the batch is still processing, completed successfully or failed:
agac batch status --batch-id <id>
Options:
| Option | Description |
|---|---|
--batch-id | Required. The ID of the batch job. If you omit this option, the command raises UsageError: --batch-id is required. Get the batch ID from the Batch <id> submitted line of the run. |
-w, --workflow | The workflow name. Required in a project with more than one workflow. -a names the same option. |
-A, --action | The action name. Required when the workflow has more than one batch action and the batch ID does not identify one action. |
Example:
$ agac batch status --batch-id batch_abc123
Batch job status: completed
--batch-id is required. The command does not use the last job as a fallback. You must give the batch ID from the submission output.
batch retrieve
When a batch is complete, retrieve the results:
agac batch retrieve --batch-id <id>
Options:
| Option | Description |
|---|---|
--batch-id | Required. The ID of the batch job to retrieve. If you omit this option, the command raises UsageError: --batch-id is required. |
-w, --workflow | The workflow name. Required in a project with more than one workflow. -a names the same option. |
-A, --action | The action name. Required when the workflow has more than one batch action and the batch ID does not identify one action. |
Example:
agac batch retrieve --batch-id batch_abc123
The command writes the results to agent_workflow/<workflow>/agent_io/target/<action>/<batch-id>_results.jsonl. Then it prints that path.
The command reads each answer as agac run reads it. With json_mode: false, the file holds the answer as text in the output_field of the action. To do this, the command loads the workflow configuration. The configuration can fail to load, or it can have no action of that name. A limit variable that is not an integer, such as AGAC_RECORD_LIMIT=abc, also stops the load. Then the command shows a warning and writes the raw answers of the provider.
Batch Workflow
The typical batch process has three parts: run (the run submits the batch), poll the status, and retrieve the results.
Batch mode works best for independent records that do not have to share state.
If your workflow requires coordination between records, process the batch results in a separate step after retrieval. An example of coordination between records is to aggregate the results from many records.
See Also
- run Command: Run workflows synchronously
- Troubleshooting: Debug batch problems