Skip to main content
The AgentWorkflowEngine manages workflow execution with built-in retry logic, episode logging, and parallel task processing.
The Workflow path is the older of the two agent-authoring paths. For new code, see the AgentFlow & Evaluator protocol — it doesn’t need a custom engine wrapper. The cookbooks/ directory has seven worked examples.

AgentWorkflowEngine

Constructor

workflow_cls
type[Workflow]
Workflow class to instantiate for each task.
workflow_args
dict
Arguments to pass to workflow instances.
rollout_engine
RolloutEngine
Engine for model inference and rollout.
config
dict | None
Optional configuration object for training.
n_parallel_tasks
int
default:"128"
Number of parallel workflow instances to maintain.
retry_limit
int
default:"3"
Maximum number of retry attempts for failed tasks.
raise_on_error
bool
default:"True"
Whether to raise exceptions on permanent failures.
episode_logger
EpisodeLogger | None
Optional logger for saving episode data to files.

Methods

initialize_pool

Initialize the workflow pool with parallel workflow instances.

set_training_step

Set current training step for episode logging.
step
int
Current training step number.
mode
str
default:"train"
Mode identifier: “train” or “val”.
epoch
int
default:"0"
Current epoch number.

process_task_with_retry

Process a single task rollout with retry logic based on termination reasons.
task
dict
Task dictionary containing the task specification.
task_id
str
Unique identifier for the task.
rollout_idx
int
Index of this rollout attempt for the task.
task_id
str
The task ID.
rollout_idx
int
The rollout index.
episode
Episode
Completed episode.

execute_batch

Execute a batch of tasks with automatic retry and error handling.
tasks
list[dict]
List of task dictionaries.
num_rollouts_per_task
int
default:"1"
Number of rollouts to generate per task.
episodes
list[Episode]
List of completed episodes.

Retry Logic

The engine automatically retries tasks based on termination reason:
  • Retryable: TIMEOUT, ERROR, MAX_PROMPT_LENGTH_EXCEEDED, MAX_RESPONSE_LENGTH_EXCEEDED
  • Non-retryable: ENV_DONE, MAX_TURNS_EXCEEDED, UNKNOWN
Tasks are retried up to retry_limit times before failing permanently.

Example: Simple Workflow Execution


Example: Multi-Turn Workflow


Episode Logging

The engine supports optional episode logging to save episodes during training: