RobutlerRobutler

TypeScript SDK Reference

Install the SDK:

npm install webagents

BaseAgent

The core agent class. Processes UAMP events, manages skills, and exposes run methods.

import { BaseAgent } from 'webagents';

const agent = new BaseAgent({
  name: 'my-agent',
  instructions: 'You are a helpful assistant.',
  model: 'gpt-4o',
  skills: [new MySkill()],
});

Constructor

ParameterTypeDescription
namestringAgent display name
instructionsstringSystem prompt
modelstringLLM model identifier
skillsSkill[]Array of skill instances
scopesstring[]Required auth scopes
capabilitiesCapabilitiesUAMP capabilities (modalities, audio formats)

Methods

MethodSignatureDescription
run(input: string, options?: RunOptions) => Promise<RunResponse>Single-turn execution
runStreaming(input: string, options?: RunOptions) => AsyncGenerator<StreamChunk>Streaming execution

Skill

Abstract base class for skills. Skills bundle tools, hooks, handoffs, and endpoints.

import { Skill, tool, hook } from 'webagents';

class WeatherSkill extends Skill {
  @tool({ description: 'Get weather for a city' })
  async getWeather(city: string): Promise<string> {
    return `Weather in ${city}: sunny`;
  }

  @hook({ lifecycle: 'before_run' })
  async onBeforeRun(data: HookData): Promise<HookResult> {
    return {};
  }
}

Decorators

@tool

Register a method as an LLM-callable tool.

@tool({ name?: string, description?: string, schema?: ZodSchema })

@hook

Register a lifecycle hook.

@hook({ lifecycle: 'before_run' | 'after_run' | 'before_tool' | 'after_tool' })

@handoff

Register a handoff handler for multi-agent delegation.

@handoff({ name?: string, description?: string, subscribes?: string[], produces?: string[] })

@observe

Register a non-consuming event observer.

@observe({ subscribes: string[] })

@http

Register an HTTP endpoint on the agent server.

@http({ path: string, method?: 'get' | 'post' | 'put' | 'delete' })

@websocket

Register a WebSocket endpoint.

@websocket({ path: string })

Server

createAgentApp

Creates a Hono HTTP application for an agent.

import { createAgentApp } from 'webagents';

const app = createAgentApp(agent, {
  port: 8080,
  cors: true,
});

serve

Starts an HTTP server for the agent (Bun or Node.js).

import { serve } from 'webagents';

await serve(agent, { port: 8080 });

createFetchHandler

Creates a standard fetch handler for serverless/edge deployments.

import { createFetchHandler } from 'webagents';

const handler = createFetchHandler(agent);
export default { fetch: handler };

Context

The Context object is available inside tools, hooks, and handoffs. It carries session state, auth info, and payment info.

interface Context {
  session: SessionState;
  auth: AuthInfo;
  payment: PaymentInfo;
  metadata: Record<string, unknown>;
  get(key: string): unknown;
  set(key: string, value: unknown): void;
  hasScope(scope: string): boolean;
}

MessageRouter

Routes UAMP messages through the agent pipeline.

import { MessageRouter } from 'webagents';

const router = new MessageRouter(agent);
const response = await router.route(events);

Sinks

Output adapters for different transports:

ClassDescription
WebSocketSinkWebSocket transport
SSESinkServer-Sent Events
WebStreamSinkWeb Streams API
CallbackSinkCustom callback function
BufferSinkIn-memory buffer

Daemon

Background process manager for agent lifecycle.

import { WebAgentsDaemon } from 'webagents';

const daemon = new WebAgentsDaemon({
  agents: [agent],
  enableCron: true,
});
await daemon.start();

UAMP Types

Key types for the Universal Agentic Message Protocol:

TypeDescription
CapabilitiesAgent capabilities declaration
ModalitySupported modalities (text, image, audio)
MessageUAMP message envelope
ToolDefinitionTool schema for LLM
ContentItemMultimodal content item
UsageStatsToken usage statistics

Crypto

JWT and JWKS utilities for agent authentication.

import { JWKSManager } from 'webagents';

const jwks = new JWKSManager({ jwksUrl: 'https://robutler.ai/.well-known/jwks.json' });
const payload = await jwks.verify(token);

On this page