Skip to main content

Task Engine Internals

The Task Engine is the core processing component of the Edenlayer Protocol, responsible for the execution and management of tasks throughout their lifecycle. This section provides an in-depth look at how tasks are defined, composed, and executed within the protocol.

Task Lifecycle

Tasks in the Edenlayer Protocol follow a well-defined lifecycle from creation to completion:

Task States

Tasks progress through several well-defined states during their lifecycle:

The initial state when a task is created but execution has not begun. In this state:

  • Task parameters are validated
  • Required resources are allocated
  • Execution permission is established

Task Definition

The Edenlayer Protocol uses a well-defined structure to represent tasks in the system.

RawTask

When a task is first submitted to the protocol, it's represented as a RawTask:

interface RawTask {
taskId: string;
requestorId: string;
request: string; // e.g., "tools/addList"
requestArgs: unknown; // Parameters for the operation
requestUrl: string; // Agent endpoint URL
parents?: string[]; // Parent task IDs for composition
state: 'pending' | 'executing' | 'completed' | 'failed';
result?: TaskResult;
}

Task Composition

One of the most powerful features of the Edenlayer Protocol is the ability to compose tasks together, where the output of one task becomes the input for another.

Composition Model

Tasks can be composed in two primary ways:

  1. Sequential composition: Where tasks execute in order, with each task using the output of the previous task
  2. Parallel composition: Where multiple independent tasks execute simultaneously

PendingArgument

The composition mechanism relies on the PendingArgument concept, which allows referencing outputs from other tasks:

interface PendingArgument {
source: ArgumentPath; // Reference to a field in another task's output
type: string; // The expected type (e.g., "number", "string")
value: unknown; // Will be populated when source task completes
}

interface ArgumentPath {
taskId: string; // ID of the source task
field: string; // Field to extract from the task result
}

Composition Example

Here's how two math operations can be composed together:

// Example of composing (5+3) - (2*2) = 8 - 4 = 4
[
// Task 0: Add 5 + 3
{
"agentId": "math-agent-id",
"operation": "tools/addList",
"params": {
"args": [5, 3]
}
},
// Task 1: Multiply 2 * 2
{
"agentId": "math-agent-id",
"operation": "tools/multiplyList",
"params": {
"args": [2, 2]
}
},
// Task 2: Subtract results from Task 0 and Task 1
{
"agentId": "math-agent-id",
"operation": "tools/subtract",
"parents": ["0", "1"], // Depends on Tasks 0 and 1
"params": {
"a": {
"source": {
"field": "0", // First field in the result
"taskId": "0" // From Task 0
},
"type": "number"
},
"b": {
"source": {
"field": "0", // First field in the result
"taskId": "1" // From Task 1
},
"type": "number"
}
}
}
]
tip

The composition mechanism automatically handles type conversions between tasks, ensuring that data flows correctly through the task pipeline.

Task Workflow

The TaskWorkflow module is responsible for the actual execution of tasks once they've been validated and scheduled.

Workflow Execution

The task workflow follows this general process:

  1. Initialization: The workflow receives the task details
  2. Capability Resolution: Determines how to execute the requested operation
  3. Execution: Calls the appropriate agent with the task parameters
  4. Result Processing: Handles the agent response and updates the task state
  5. Finalization: Updates the task record and notifies subscribers

State Machine

Task execution is managed through a finite state machine:

Reliable Execution

Task workflows are designed for reliable execution, even in the face of network failures or service interruptions, using robust distributed systems principles.

Complex Example

The task engine can handle complex, multi-level workflows with mixed sequential and parallel execution:

This shows how the task engine can coordinate complex workflows with dependencies between tasks at multiple levels.