Sequential Runner
The Runner
executes tasks in a sequential order. It is useful for debugging and testing the Workflow. Use this for simple workflows or for testing out functionality before you scale compute it with the QueueRunner
.
Basic Usage
The basic usage pattern of the Runner
follows three steps:
- Initialize the runner
- Implement the logic for each stage in your Workflow you want to capture with the runner
- Execute the runner
The following example shows how to initialize the runner and implement the logic for each stage in your Workflow you want to capture with the runner.
To execute the runner via the CLI, you can do:
Running Agents
Basic Execution
Both options:
- Connect to your Encord project
- Poll for tasks in the configured stages
- Execute your agent functions on each task
- Move tasks according to returned pathway
- Retry failed tasks up to
num_retries
times
See the configuration options below.
Command Line Interface
The runner exposes configuration via CLI:
Order of execution
The runner processes tasks by emptying the queue for "stage_1"
first, then successively emptying the queue for "stage_2"
. If you set the refresh_every
argument, the runner repolls both queues after emptying the initial set. This ensures data that arrived in the queue after the initial poll is picked up in the subsequent iteration. If an execution’s time already exceeds the refresh_every
threshold, the agent instantly polls for new tasks.
To illustrate the order of execution, see the pseudo-code below.
Error Handling
The runner:
- Retries failed tasks up to
num_retries
times (default: 3). Changes to the label row are not rolled back. - Logs errors for debugging
- Continues processing other tasks if a task fails
- Bundles updates for better performance (configurable via
task_batch_size
)
Configuration
Initialization
::: encord_agents.tasks.runner.Runner.init options: show_if_no_docstring: false show_subodules: false
Runtime Configuration
There are two ways to execute the runner.
- Either run the runner directly from your code:
- Or run it using the command-line interface (CLI) by employing the
runner.run()
function.
Suppose you have an example.py
file that looks like this:
Then, the runner functions as a CLI tool, accepting the same arguments as when executed in code.
Performance Considerations
By default, the Runner bundles task updates for better performance with a batch size of 300. For debugging or when immediate updates are needed, you can set task_batch_size=1:
Or in code
Scaling with the QueueRunner
The QueueRunner is an advanced runner designed for parallel processing of multiple tasks, ideal for speeding up execution of large task volumes.
Both the Runner and QueueRunner share the same interface. The primary distinction lies in their execution:
- The Runner executes tasks sequentially using its
run()
function. - The QueueRunner converts your implementations into functions that accept a task specification as a JSON string and return a
encord_agents.tasks.models.TaskCompletionResult
as a JSON string. This stringified JSON format is necessary for passing messages over queues, which typically do not support custom object types.
Here’s an example of how this difference manifests:
=== “The (sequential) Runner
”
=== “The (parallel) QueueRunner
”
Please refer to the Celery example or Modal example for more information.
Comparison with Queue Runner
The key differences between QueueRunner
and the sequential Runner
are:
Feature | Runner | QueueRunner |
---|---|---|
Execution Model | Executes tasks sequentially in a single process | Designed for distributed execution across multiple processes |
Project Hash | Optional at initialization | Required at initialization |
Function Wrapping | Executes your function directly with injected dependencies | Additionally wraps your function to handle JSON task specifications |
Execution Control | Handles task polling and execution | You control task distribution and execution through your queue system |
Scaling | Not suitable for scaling | Suitable for scaling |