API ReferenceClassesDefaultAgentExecutor

title: Server. Default Agent Executor

A2A Node SDK - v0.1.0 / Modules / Server / DefaultAgentExecutor

Class: DefaultAgentExecutor

Server.DefaultAgentExecutor

Default implementation of the AgentExecutor interface

This class provides a basic implementation of the AgentExecutor interface that manages task lifecycle, publishes events, and handles errors. It uses a TaskManager for task persistence and a TaskEventManager for event publishing.

Example

// Create dependencies
const taskStore = new InMemoryTaskStore();
const taskManager = new TaskManager(taskStore);
const taskEventManager = new TaskEventManager();
 
// Create the executor
const executor = new DefaultAgentExecutor(taskManager, taskEventManager);
 
// Execute a task
await executor.execute(
  createRequestContext(task, 'agent-123'),
  new EventQueue()
);

Implements

Table of contents

Constructors

Methods

Constructors

constructor

new DefaultAgentExecutor(taskManager, taskEventManager): DefaultAgentExecutor

Creates a new DefaultAgentExecutor

Parameters

NameTypeDescription
taskManagerTaskManagerThe task manager for task persistence
taskEventManagerTaskEventManagerThe task event manager for event publishing

Returns

DefaultAgentExecutor

Methods

cancel

cancel(context, eventQueue): Promise<void>

Cancel an ongoing task execution

Parameters

NameTypeDescription
contextRequestContextRequest context including task details
eventQueueEventQueueEvent queue for publishing cancellation events

Returns

Promise<void>

Implementation of

AgentExecutor.cancel


execute

execute(context, eventQueue): Promise<void>

Executes a task on behalf of an agent

This method handles the execution of a task, including updating its status, publishing events, and handling errors. It transitions the task from its current state to ‘working’ and then to ‘completed’ if successful.

Parameters

NameTypeDescription
contextRequestContextThe request context containing task and agent information
eventQueueEventQueueThe event queue for publishing events

Returns

Promise<void>

Promise that resolves when execution is complete

Throws

Various task-related errors if execution fails

Implementation of

AgentExecutor.execute