Task
A Task is a request to execute an AgentSystem. Tasks are the unit of work in Orloj -- they carry input, track execution state, and produce output.
Defining a Task
apiVersion: orloj.dev/v1
kind: Task
metadata:
name: weekly-report
spec:
system: report-system
input:
topic: AI startups
priority: high
retry:
max_attempts: 3
backoff: 5s
message_retry:
max_attempts: 2
backoff: 250ms
max_backoff: 2s
jitter: full
requirements:
region: default
model: gpt-4oTask Lifecycle
Every task moves through a well-defined set of phases:
Pending ──► Running ──► Succeeded
└──► Failed
└──► DeadLetter| Phase | Meaning |
|---|---|
Pending | Task is created and waiting for a worker to claim it. |
Running | A worker has claimed the task and is executing the agent graph. |
Succeeded | All agents in the graph completed successfully. |
Failed | Execution failed and retries are not exhausted. May transition back to Pending. |
DeadLetter | All retry attempts exhausted. Terminal state requiring manual investigation. |
Worker Assignment and Leases
The scheduler assigns tasks to workers based on requirements (region, GPU, model). Workers claim tasks through a lease mechanism:
- Scheduler matches task requirements to worker capabilities.
- Worker claims the task and acquires a time-bounded lease.
- Worker renews the lease via heartbeats during execution.
- If the lease expires (worker crash, network partition), another worker may safely take over.
This guarantees exactly-once processing semantics even under failure.
Retry Configuration
Tasks support two levels of retry:
Task-level retry (spec.retry) -- retries the entire task from the beginning if it fails.
retry:
max_attempts: 3
backoff: 5sMessage-level retry (spec.message_retry) -- retries individual agent-to-agent messages within the graph without restarting the full task.
message_retry:
max_attempts: 2
backoff: 250ms
max_backoff: 2s
jitter: fullRetry uses capped exponential backoff with configurable jitter (none, full, equal). Messages that exhaust retries transition to deadletter phase.
Cyclic Graphs
For AgentSystems with cycles (loops), spec.max_turns bounds the number of iterations to prevent infinite execution:
spec:
system: manager-research-loop-system
input:
topic: AI coding assistants
max_turns: 6Task Templates
Tasks with mode: template serve as templates for TaskSchedules and TaskWebhooks. They are not executed directly.
spec:
mode: template
system: report-system
input:
topic: AI startupsRelated
- TaskSchedule -- automate task creation with cron
- TaskWebhook -- trigger tasks from external events
- Worker -- the execution units that run tasks
- Resource Reference: Task
- Execution and Messaging