/** * A2A executor that bridges a Strands Agent into the A2A protocol. * * Implements the AgentExecutor interface from `@a2a-js/sdk/server` to allow * a Strands Agent to handle A2A JSON-RPC requests. */ import type { ExecutionEventBus, RequestContext } from '@a2a-js/sdk/server'; import type { AgentExecutor } from '@a2a-js/sdk/server'; import type { InvokableAgent } from '../types/agent.js'; /** Builds a fresh agent for a given A2A `contextId`, invoked once per context. */ export type AgentFactory = (contextId: string) => InvokableAgent; /** Default cap on concurrently tracked A2A contexts. */ export declare const DEFAULT_MAX_CONTEXTS = 1000; /** * Options for constructing an {@link A2AExecutor}. * * Provide exactly one of `agent` (deprecated) or `agentFactory`. */ export interface A2AExecutorOptions { /** @deprecated A single agent reused across contexts. Prefer `agentFactory`. */ agent?: InvokableAgent; /** Callable that returns a fresh agent per `contextId`. Recommended. */ agentFactory?: AgentFactory; /** Maximum contexts to retain; the least-recently-used is evicted beyond it. Must be at least 1. */ maxContexts?: number; } /** * Bridges a Strands Agent into the A2A protocol as an AgentExecutor. * * Converts A2A message parts to Strands content blocks, streams the agent * execution, and publishes text deltas as artifact updates through the A2A * event bus. * * Conversation state is isolated per A2A `contextId`. There are two modes: * * - **`agentFactory`** (recommended): returns a dedicated agent per context. Each * context owns an independent agent under its own lock, so different contexts run * concurrently and never share state. The factory is also where per-context * concerns such as a `sessionManager` are wired. * - **`agent`** (deprecated): a single agent reused across contexts, with each * context's state swapped on/off it under a lock. Not multi-tenant safe; prefer * `agentFactory`. * * `contextId` is client-supplied and is **not** an authentication boundary: a caller * that knows another's `contextId` can attach to that conversation. Multi-tenant * deployments must enforce authenticated identity at the transport/gateway layer. * * The incoming {@link RequestContext} is forwarded to the agent's `invocationState` * under the reserved key `a2aRequestContext` for hooks and tools to read. * * @example * ```typescript * import { Agent } from '@strands-agents/sdk' * import { A2AExecutor } from '@strands-agents/sdk/a2a' * * const executor = new A2AExecutor({ agentFactory: (contextId) => new Agent({ model: 'my-model' }) }) * ``` */ export declare class A2AExecutor implements AgentExecutor { private readonly _agentFactory?; private readonly _maxContexts; /** Serializes single-agent mode: only one request may use the shared agent at a time. */ private readonly _sharedAgentLock; private readonly _contexts; private readonly _agent?; private readonly _templateSnapshot?; private readonly _snapshots; /** * Creates a new A2AExecutor. * * Provide exactly one of `agent` (deprecated) or `agentFactory`. * * @param options - Executor options: `agent` or `agentFactory`, plus optional `maxContexts`. */ constructor(options?: A2AExecutorOptions); /** Snapshot an agent's session state. */ private _captureState; /** Load a snapshot into an agent, restoring its session state. */ private _restoreState; /** Evict least-recently-used contexts beyond `maxContexts`. */ private _evictExcessContexts; /** Return the dedicated agent and lock for a context, creating it on first use (factory mode). */ private _acquireContextAgent; /** * Executes the agent in response to an A2A message. * * @param context - The A2A request context containing the user message * @param eventBus - The event bus for publishing A2A artifact and status events */ execute(context: RequestContext, eventBus: ExecutionEventBus): Promise; /** Factory mode: run against this context's dedicated agent, serialized only per context. */ private _runWithContextAgent; /** Single-agent mode: swap this context's snapshot on/off the shared agent under a lock. */ private _runWithSharedAgent; /** Streams one agent invocation and translates its events to A2A artifact updates. */ private _streamAgent; /** * Cancels a running task. Not supported by this executor. * * @param taskId - The ID of the task to cancel * @param eventBus - The event bus for publishing status events */ cancelTask(_taskId: string, _eventBus: ExecutionEventBus): Promise; } //# sourceMappingURL=executor.d.ts.map