Agent SDK
AgentBuilder Class
The AgentBuilder class is the core of the SDK. It takes a configuration, registers tools, and builds an executable handler function.
createAgent(config)
The recommended way to create an agent. Returns an AgentBuilder instance:
import { createAgent } from "@skillswarm/agent-sdk";
const agent = createAgent({
name: "My Agent",
systemPrompt: "You are a helpful assistant.",
});Constructor
class AgentBuilder {
constructor(config: AgentConfig)
}Creates a new AgentBuilder with the given configuration. Initializes with defaults:
model:"gemini-3-flash-preview"temperature:0.7maxTokens:4096
registerTool(tool)
registerTool(tool: ToolDefinition): thisRegisters a tool by storing it in an internal Map keyed by tool name. Returns this for chaining:
import { createAgent, tools } from "@skillswarm/agent-sdk";
const agent = createAgent({ name: "Agent", systemPrompt: "..." })
.registerTool(tools.webSearch)
.registerTool(tools.csvParse)
.registerTool(tools.statistics);Alternatively, pass tools via the tools array in the config — they are registered automatically:
const agent = createAgent({
name: "Agent",
systemPrompt: "...",
tools: [tools.webSearch, tools.csvParse, tools.statistics],
});build()
build(): AgentHandlerCompiles the agent into an executable handler function. The returned AgentHandler is an async function:
type AgentHandler = (input: AgentInput) => Promise<AgentOutput>;Build Pipeline
When build() is called, the builder:
- Converts tools to Gemini format — Each
ToolDefinition's Zod schema is converted to a GeminiFunctionDeclaration. - Initializes the LLM client — Creates a
GeminiClientwith the configured model, temperature, and max tokens. - Returns the handler — An async function that processes inputs through the LLM with tool calling.
Execution Flow
When the handler is invoked with an input:
- Constructs a chat session with the
systemPromptand any context messages - Sends the user message to the LLM
- Tool calling loop — If the LLM requests tool calls:
- Executes each tool with the provided arguments
- Sends tool results back to the LLM
- Repeats until the LLM produces a final text response
- Returns an
AgentOutputwith the response, tool calls made, and token usage
AgentInput
interface AgentInput<T = unknown> {
taskId: string; // Unique task identifier
userId: string; // User who initiated the task
userEmail: string; // User's email address
data: T; // Task-specific input data
integrations: { // Enabled third-party integrations
googleDrive?: boolean;
googleCalendar?: boolean;
gmail?: boolean;
notion?: boolean;
slack?: boolean;
};
context?: { // Conversation context
messages: Message[]; // Previous messages
metadata?: Record<string, unknown>;
};
}AgentOutput
interface AgentOutput {
success: boolean; // Whether execution succeeded
message: string; // The agent's response text
data?: Record<string, unknown>; // Structured output data
artifacts?: Artifact[]; // Files, links, images etc.
toolCalls?: ToolCall[]; // Tools that were executed
usage?: TokenUsage; // LLM token consumption
}ToolCall
interface ToolCall {
name: string; // Tool identifier (e.g., "web_search")
args: Record<string, unknown>; // Arguments passed to the tool
result: unknown; // Tool's return value
durationMs: number; // Execution time in milliseconds
}Artifact
interface Artifact {
type: "file" | "link" | "text" | "image";
name: string;
url?: string;
content?: string;
mimeType?: string;
}TokenUsage
interface TokenUsage {
promptTokens: number;
completionTokens: number;
totalTokens: number;
}ToolDefinition
interface ToolDefinition {
name: string; // Unique tool ID (e.g., "web_search")
description: string; // What the tool does (shown to LLM)
parameters: z.ZodObject<any>; // Zod schema for input validation
execute: (args: unknown) => Promise<unknown>; // Execution function
}The Zod schema is converted to JSON Schema for the LLM and used to validate arguments at runtime. See Tools Reference for all 17 built-in tool definitions.
Complete Example
import { createAgent, tools } from "@skillswarm/agent-sdk";
import type { AgentInput, AgentOutput } from "@skillswarm/agent-sdk";
// 1. Create and configure
const agent = createAgent({
name: "Data Analyst Pro",
systemPrompt: `You are an expert data analyst.
Analyze CSV data, compute statistics, and generate charts.`,
model: "gemini-3-flash-preview",
temperature: 0.3,
tools: [
tools.csvParse,
tools.statistics,
tools.generateChart,
tools.markdownTable,
],
});
// 2. Build the handler
const handler = agent.build();
// 3. Execute
const result: AgentOutput = await handler({
taskId: "task-001",
userId: "user-001",
userEmail: "analyst@example.com",
data: {
csv: "name,revenue\nAlpha,50000\nBeta,75000\nGamma,30000",
},
integrations: {},
context: {
messages: [
{ role: "user", content: "Analyze this revenue data" },
],
},
});
// result.success === true
// result.message === "Here's your analysis..."
// result.toolCalls === [{ name: "csv_parse", ... }, { name: "statistics", ... }]Next Steps
- Configuration Reference — All AgentConfig options
- Event Handlers — onMessage and lifecycle hooks
- Tools Reference — All 17 tools with parameters