Skip to content

API Reference

Functions

createAgent(config) factory

Creates an Agent instance.

function createAgent(config: AgentConfig): Agent;

See Creating Agents for usage details.


createTool(definition) factory

Creates a Tool instance. This is a passthrough helper for type inference.

function createTool<TInput = unknown, TOutput = unknown>(
tool: Tool<TInput, TOutput>
): Tool<TInput, TOutput>;

See Tools for usage details.


createAgentRegistry() factory

Creates an AgentRegistry for multi-agent delegation.

function createAgentRegistry(): AgentRegistry;

createPipeline(config) factory

Creates a SynkroWorkflow from a list of agent steps.

function createPipeline(config: PipelineConfig): SynkroWorkflow;

See Synkro Integration for usage details.

createDebate(config) factory

Creates a debate orchestration for multi-agent collaboration.

function createDebate(config: DebateConfig): {
run(topic: string, options?: AgentRunOptions): Promise<DebateResult>;
asHandler(): HandlerFunction;
};

See Debate for usage details.


Classes

Agent

The core agent class. Created via createAgent().

MethodSignatureDescription
run(input: string, options?: AgentRunOptions) => Promise<AgentRunResult>Execute the ReAct loop and return the result.
asHandler() => HandlerFunctionConvert the agent to a Synkro-compatible event handler.
PropertyTypeDescription
namestringAgent name (readonly).
descriptionstring | undefinedAgent description (readonly).

OpenAIProvider

class OpenAIProvider implements ModelProvider {
constructor(options: OpenAIProviderOptions);
chat(messages: Message[], options: ModelOptions): Promise<ModelResponse>;
}
FieldTypeDefault
apiKeystringrequired
baseUrlstring"https://api.openai.com/v1"

AnthropicProvider

class AnthropicProvider implements ModelProvider {
constructor(options: AnthropicProviderOptions);
chat(messages: Message[], options: ModelOptions): Promise<ModelResponse>;
}
FieldTypeDefault
apiKeystringrequired
baseUrlstring"https://api.anthropic.com/v1"

GeminiProvider

class GeminiProvider implements ModelProvider {
constructor(options: GeminiProviderOptions);
chat(messages: Message[], options: ModelOptions): Promise<ModelResponse>;
}
FieldTypeDefault
apiKeystringrequired
baseUrlstring"https://generativelanguage.googleapis.com/v1beta"

ConversationMemory

Redis-backed conversation memory using Synkro’s transport.

class ConversationMemory implements AgentMemory {
constructor(options: ConversationMemoryOptions);
addMessage(agentId: string, runId: string, message: Message): Promise<void>;
getMessages(agentId: string, runId: string): Promise<Message[]>;
clear(agentId: string, runId: string): Promise<void>;
}
FieldTypeDefault
transportTransportManagerrequired
maxMessagesnumber100
ttlSecondsnumber86400

AgentRegistry

Registry for multi-agent delegation.

class AgentRegistry {
register(agent: Agent): void;
get(name: string): Agent | undefined;
has(name: string): boolean;
list(): Agent[];
}

ToolRegistry

Internal registry for agent tools.

class ToolRegistry {
register(tool: Tool): void;
get(name: string): Tool | undefined;
getDefinitions(): ToolDefinition[];
}

ToolExecutor

Internal executor that runs tool calls returned by the LLM.

class ToolExecutor {
constructor(registry: ToolRegistry);
executeAll(toolCalls: ToolCall[], ctx: AgentContext): Promise<ToolResult[]>;
}

Types

AgentConfig

type AgentConfig = {
name: string;
description?: string;
systemPrompt: string;
provider: ModelProvider;
model: ModelOptions;
tools?: Tool[];
memory?: AgentMemory;
maxIterations?: number; // default: 10
tokenBudget?: number;
retry?: RetryConfig;
onTokenUsage?: (usage: TokenUsage) => void;
registry?: AgentRegistry;
};

AgentRunOptions

type AgentRunOptions = {
requestId?: string;
payload?: unknown;
synkroCtx?: HandlerCtx;
};

AgentRunResult

type AgentRunResult = {
agentName: string;
runId: string;
output: string;
messages: Message[];
toolCalls: ToolResult[];
tokenUsage: TokenUsage;
status: "completed" | "failed" | "max_iterations" | "token_budget_exceeded";
};

AgentContext

type AgentContext = HandlerCtx & {
agentName: string;
runId: string;
tokenUsage: TokenUsage;
delegate: (agentName: string, input: string) => Promise<AgentRunResult>;
};

Tool

type Tool<TInput = unknown, TOutput = unknown> = {
name: string;
description: string;
parameters: Record<string, unknown>;
execute: (input: TInput, ctx: AgentContext) => Promise<TOutput>;
};

ToolResult

type ToolResult = {
toolCallId: string;
name: string;
result: unknown;
error?: string;
durationMs: number;
};

ToolCall

type ToolCall = {
id: string;
name: string;
arguments: string;
};

ToolDefinition

type ToolDefinition = {
name: string;
description: string;
parameters: Record<string, unknown>;
};

Message

type Message = {
role: MessageRole;
content: string;
toolCallId?: string;
toolCalls?: ToolCall[];
};
type MessageRole = "system" | "user" | "assistant" | "tool";

ModelProvider

interface ModelProvider {
chat(messages: Message[], options: ModelOptions): Promise<ModelResponse>;
chatStream?(messages: Message[], options: ModelOptions): AsyncIterable<ModelStreamChunk>;
}

ModelOptions

type ModelOptions = {
model: string;
temperature?: number;
maxTokens?: number;
tools?: ToolDefinition[];
};

ModelResponse

type ModelResponse = {
content: string;
toolCalls?: ToolCall[];
usage: TokenUsage;
finishReason: "stop" | "tool_calls" | "length";
};

ModelStreamChunk

type ModelStreamChunk = {
content?: string;
toolCalls?: ToolCall[];
usage?: TokenUsage;
finishReason?: "stop" | "tool_calls" | "length";
};

TokenUsage

type TokenUsage = {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};

AgentMemory

interface AgentMemory {
addMessage(agentId: string, runId: string, message: Message): Promise<void>;
getMessages(agentId: string, runId: string): Promise<Message[]>;
clear(agentId: string, runId: string): Promise<void>;
}

PipelineConfig

type PipelineConfig = {
name: string;
steps: AgentStep[];
registry?: AgentRegistry;
onSuccess?: string;
onFailure?: string;
onComplete?: string;
};

AgentStep

type AgentStep = {
agent: Agent | string;
inputMapper?: (payload: unknown) => string;
};

DebateConfig

type DebateConfig = {
name: string;
participants: Agent[];
maxRounds?: number; // default: 3
moderator?: Agent;
onTokenUsage?: (usage: TokenUsage) => void;
};

DebateResult

type DebateResult = {
topic: string;
rounds: DebateRound[];
synthesis: string | undefined;
output: string;
tokenUsage: TokenUsage;
status: "completed" | "failed";
};

DebateRound

type DebateRound = {
roundNumber: number;
contributions: DebateContribution[];
};

DebateContribution

type DebateContribution = {
agentName: string;
output: string;
};