agentsdk-js
v0.1.0
Published
TypeScript-first, multi-provider AI agent SDK — build, orchestrate, and run AI agents anywhere. Bundles core + agent + graph in one package.
Maintainers
Readme
agentsdk-js
TypeScript-first, multi-provider AI agent SDK — build, orchestrate, and run AI agents anywhere.
One package, everything included. agentsdk-js bundles the core LLM
client, the multi-step agent runtime, and the JSON graph engine into a
single install — no need to install multiple packages.
npm install agentsdk-jsimport 'agentsdk-js/bootstrap'
import { generateText, runAgent, runGraph } from "agentsdk-js-js'✨ Features
- Multi-provider — OpenAI, Anthropic, and GLM with one unified interface.
- Lazy-loaded providers — only install the SDK packages you actually use.
- Cost tracking built-in — every call returns token usage and USD cost.
- Agent-as-tool handoff — wrap any agent as a callable tool for multi-agent orchestration.
- Graph engine — 7 node types (Trigger, Agent, Tool, Condition, Loop, Output, HumanInLoop) with cycle detection and sandboxed condition evaluation.
- Streaming — full streaming support across all three providers.
- Retry & resilience — automatic retry on rate limits and server errors with exponential backoff.
- Parallel tool execution — when an agent calls multiple tools in one turn, they run concurrently.
- TypeScript-first — strict types throughout.
📦 Install
npm install agentsdk-jsThen install the provider SDK(s) for the LLM backend(s) you want to use:
# For OpenAI (works anywhere):
npm install openai
# For Anthropic (works anywhere):
npm install @anthropic-ai/sdk
# For GLM:
npm install z-ai-web-dev-sdkTip: Set
OPENAI_API_KEY,ANTHROPIC_API_KEY, orZAI_API_KEYin your environment.
🚀 Quick start
Basic LLM call
import 'agentsdk-js/bootstrap'
import { generateText } from "agentsdk-js'
const result = await generateText({
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: 'You are a concise assistant.' },
{ role: 'user', content: 'What is 2+2?' },
],
}, { provider: 'openai' })
console.log(result.text)
console.log(result.cost.total)Multi-step agent with tools
import 'agentsdk-js/bootstrap'
import { runAgent, type AgentConfig } from "agentsdk-js'
const agent: AgentConfig = {
id: 'researcher',
name: 'Researcher',
model: 'gpt-4o-mini',
provider: 'openai',
systemPrompt: 'You research topics. Use tools. Cite sources.',
tools: [webSearchTool],
maxSteps: 8,
}
const result = await runAgent(agent, {
messages: [{ role: 'user', content: 'What are the latest AI news?' }],
})Multi-agent orchestration
import { asTool, withHandoffs, runAgent } from "agentsdk-js'
const researcher = { id: 'researcher', model: 'gpt-4o-mini', systemPrompt: '...' }
const writer = { id: 'writer', model: 'gpt-4o-mini', systemPrompt: '...' }
const orchestrator = {
id: 'orchestrator',
model: 'gpt-4o-mini',
systemPrompt: 'Coordinate: research then write.',
tools: withHandoffs([], [
{ agent: researcher, opts: { description: 'Research a topic' } },
{ agent: writer, opts: { description: 'Write a draft' } },
]),
maxSteps: 12,
}JSON graph workflow
import 'agentsdk-js/bootstrap'
import { runGraph, GRAPH_SCHEMA_VERSION } from "agentsdk-js'
const graph = {
schemaVersion: GRAPH_SCHEMA_VERSION,
id: 'my-workflow',
name: 'My Workflow',
nodes: [/* ... */],
edges: [/* ... */],
}
const result = await runGraph(graph, 'Hello!')📚 API
Everything is exported from the main entry point:
import {
// Core — LLM calls
generateText, streamText, generateObject,
createGlmProvider, createOpenAIProvider, createAnthropicProvider,
registerProvider, getProvider, hasProvider, listProviders,
AgentSDKError, normalizeError,
setModelPricing, computeCost, addUsage, addCost,
// Agent — multi-step runtime
runAgent, asTool, withHandoffs, applyMemory,
type AgentConfig, type AgentRunResult, type StepEvent,
// Graph — workflow engine
runGraph, validateGraph, isRunnable,
resolveRef, resolveValue, evaluateCondition,
GRAPH_SCHEMA_VERSION,
type AgentGraph, type AnyGraphNode, type GraphState,
} from "agentsdk-js'
// Bootstrap (side-effect import for auto-registration):
import 'agentsdk-js/bootstrap'🌐 Providers
| Provider | id | Env var | Works anywhere? |
|----------|------|---------|-----------------|
| OpenAI | openai | OPENAI_API_KEY | ✅ |
| Anthropic | anthropic | ANTHROPIC_API_KEY | ✅ |
| GLM | glm | ZAI_API_KEY | ✅ |
The SDK auto-detects which providers are available (via import 'agentsdk-js/bootstrap') and gracefully falls back.
📄 License
MIT — see LICENSE. Copyright (c) 2026 Shetan Mehra.
