Skip to content
reaatechREAATECH

@reaatech/agent-handoff

npm v0.1.0

Provides the core TypeScript definitions, error classes, and utility functions required to implement the Agent Handoff Protocol. It exports a set of interfaces, a typed event emitter, and retry logic to standardize data structures and communication across agent handoff systems.

@reaatech/agent-handoff

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Core types, utilities, and configuration for the Agent Handoff Protocol. This package is the foundation that all other @reaatech/agent-handoff-* packages build on.

Installation

terminal
npm install @reaatech/agent-handoff
# or
pnpm add @reaatech/agent-handoff

Feature Overview

  • 35+ exported types — every handoff domain concept has a corresponding type: payloads, agents, routing decisions, triggers, messages, and more
  • 7 typed error classesHandoffError hierarchy with TransportError, ValidationError, TimeoutError, RejectionError, RoutingError, CompressionError, ConfigurationError
  • Typed event emitterTypedEventEmitter<EventMap> with type-safe on/off/once/emit for lifecycle observability
  • Retry utilitywithRetry with configurable exponential/linear backoff and full jitter
  • Config factorycreateHandoffConfig with deeply merged sensible defaults
  • Zero runtime dependencies — everything is built-in or injected by the consumer
  • Dual ESM/CJS output — works with import and require

Quick Start

typescript
import {
  createHandoffConfig,
  defaultHandoffConfig,
  HandoffError,
  TypedEventEmitter,
  withRetry,
  pickDefined,
} from '@reaatech/agent-handoff';
import type {
  HandoffPayload,
  AgentCapabilities,
  RoutingDecision,
  HandoffConfig,
  Message,
} from '@reaatech/agent-handoff';
 
// Create a configuration with defaults
const config = createHandoffConfig({
  routing: { minConfidenceThreshold: 0.6 },
});
 
// Use the typed event emitter
const emitter = new TypedEventEmitter<{ update: { id: string } }>();
emitter.on('update', ({ id }) => console.log(id));
 
// Retry with backoff
const result = await withRetry(() => fetchSomething(), {
  maxRetries: 3,
  backoff: 'exponential',
  baseDelayMs: 100,
  maxDelayMs: 5000,
  shouldRetry: (err) => err instanceof Error,
});

Exports

Types

ExportDescription
HandoffPayloadComplete handoff data: session history, compressed context, metadata
CompressedContextCompression output: summary, key facts, intents, entities, open items
AgentCapabilitiesAgent descriptor: skills, domains, load, languages, availability
RoutingDecisionDiscriminated union: PrimaryRoute | ClarificationRoute | FallbackRoute
HandoffConfigCompression, routing, transport, and trigger configuration
HandoffTriggerDiscriminated union of 5 trigger types
HandoffContextInput context for HandoffManager.executeHandoff()
HandoffOptionsOptional overrides: source agent, timeout, transport preference
HandoffResultResult type: success/failure, receiving agent, routing decision
MessageConversation message: id, role, content, timestamp
TransportLayerInterface: sendHandoff, validateConnection, getCapabilities
ContextCompressorInterface: compress + estimateTokens
HandoffRouterInterface: route returning a RoutingDecision
DeepPartialRecursive partial utility type

Errors

All errors extend HandoffError which includes code: HandoffErrorCode, message: string, and optional details.

ClassCodeWhen
HandoffError(custom)Base class for all handoff errors
TransportErrortransport_errorTransport layer failure
ValidationErrorvalidation_errorPayload incompatible with target agent; includes validationErrors[]
TimeoutErrortimeout_errorHandoff exceeded timeout; includes timeoutMs
RejectionErrorrejection_errorTarget agent rejected; includes rejectionReason
RoutingErrorrouting_errorNo suitable agent found
CompressionErrorcompression_errorContext compression failed
ConfigurationErrorconfiguration_errorInvalid configuration

Utilities

ExportDescription
TypedEventEmitter<EventMap>Type-safe event emitter with on, off, once, emit
withRetryAsync retry with exponential/linear backoff + full jitter
pickDefinedBuild object from key-value pairs, omitting undefined values
createHandoffConfigDeep-merge partial config with defaultHandoffConfig
defaultHandoffConfigSensible defaults for compression, routing, transport, triggers

License

MIT