openserv-agent-sdk
Create autonomous AI agents using the OpenServ SDK (@openserv-labs/sdk). Use when building agents with capabilities, tasks, file operations, or integrations. Triggers on keywords like OpenServ, agent SDK, addCapability, workspace, or multi-agent systems.
OpenServ Agent SDK
Build and deploy custom AI agents for the OpenServ platform using TypeScript.
Reference files:
reference.md- Quick reference for common patternstroubleshooting.md- Common issues and solutionsexamples/- Complete code examples
What's New in v2.1
- Built-in Tunnel - The
run()function auto-connects toagents-proxy.openserv.ai - No Endpoint URL Needed - Skip
endpointUrlinprovision()during development - Automatic Port Fallback - If your port is busy, the agent finds an available one
- Direct Credential Binding -
provision()can bind credentials directly to agent instance viaagent.instance setCredentials()Method - Manually bind API key and auth token to agent
Quick Start
Installation
npm install @openserv-labs/sdk @openserv-labs/client zod openai
Note: The SDK requires
openai@^5.xas a peer dependency.
Minimal Agent
See examples/basic-agent.ts for a complete runnable example.
The pattern is simple:
- Create an
Agentwith a system prompt - Add capabilities with
agent.addCapability() - Call
provision()to register on the platform (passagent.instanceto bind credentials) - Call
run(agent)to start
Complete Agent Template
File Structure
my-agent/
├── src/agent.ts
├── .env
├── .gitignore
├── package.json
└── tsconfig.json
package.json
{
"name": "my-agent",
"type": "module",
"scripts": { "dev": "tsx src/agent.ts" },
"dependencies": {
"@openserv-labs/sdk": "^2.1.0",
"@openserv-labs/client": "^2.0.0",
"dotenv": "^16.4.5",
"openai": "^5.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20.14.9",
"tsx": "^4.16.0",
"typescript": "^5.5.2"
}
}
.env
OPENAI_API_KEY=your-openai-key
# Auto-populated by provision():
WALLET_PRIVATE_KEY=
OPENSERV_API_KEY=
OPENSERV_AUTH_TOKEN=
PORT=7378
Capabilities
Capabilities are functions your agent can execute. Each requires:
name- Unique identifierdescription- What it does (helps AI decide when to use it)schema- Zod schema defining parametersrun- Function returning a string
See examples/capability-example.ts for basic capabilities.
Using Agent Methods
Access this in capabilities to use agent methods like addLogToTask(), uploadFile(), etc.
See examples/capability-with-agent-methods.ts for logging and file upload patterns.
Agent Methods
Task Management
await agent.createTask({ workspaceId, assignee, description, body, input, dependencies })
await agent.updateTaskStatus({ workspaceId, taskId, status: 'in-progress' })
await agent.addLogToTask({ workspaceId, taskId, severity: 'info', type: 'text', body: '...' })
await agent.markTaskAsErrored({ workspaceId, taskId, error: 'Something went wrong' })
const task = await agent.getTaskDetail({ workspaceId, taskId })
const tasks = await agent.getTasks({ workspaceId })
File Operations
const files = await agent.getFiles({ workspaceId })
await agent.uploadFile({ workspaceId, path: 'output.txt', file: 'content', taskIds: [taskId] })
await agent.deleteFile({ workspaceId, fileId })
Secrets & Integrations
const secrets = await agent.getSecrets({ workspaceId })
const value = await agent.getSecretValue({ workspaceId, secretId })
await agent.callIntegration({
workspaceId,
integrationId: 'twitter-v2',
details: { endpoint: '/2/tweets', method: 'POST', data: { text: 'Hello!' } }
})
Action Context
The action parameter in capabilities contains request context:
action.type // 'do-task'
action.task.id
action.task.description
action.task.input
action.workspace.id
action.workspace.goal
action.me.id // Current agent ID
action.integrations // Available integrations
Trigger Types
import { triggers } from '@openserv-labs/client'
triggers.webhook({ waitForCompletion: true, timeout: 180 })
triggers.x402({ name: '...', description: '...', price: '0.01' })
triggers.cron({ schedule: '0 9 * * *' })
triggers.manual()
Deployment
Local Development
npm run dev
The run() function automatically:
- Starts the agent HTTP server (port 7378, with automatic fallback)
- Connects via WebSocket to
agents-proxy.openserv.ai - Routes platform requests to your local machine
No need for ngrok or other tunneling tools - run() handles this seamlessly. Just call run(agent) and your local agent is accessible to the platform.
Production
await provision({
agent: {
name: 'my-agent',
description: '...',
endpointUrl: 'https://my-agent.example.com' // Required for production
}
// ...
})
await agent.start() // Start without tunnel
DO NOT USE
this.process()inside capabilities - Use direct OpenAI calls insteaddoTaskoverride - The SDK handles task execution automaticallythis.completeTask()- Task completion is handled by the Runtime API
Updating This Skill
This skill may be outdated. The OpenServ team ships updates regularly—new features, API changes, and bug fixes won't be reflected here until you update. If something isn't working as expected, or you want to make sure you have the latest information, update the skill before proceeding.
# Check if updates are available
npx skills check
# Update all installed skills to latest versions
npx skills update
Or reinstall the OpenServ skills directly:
npx skills add openserv-labs/skills
Related Skills
- openserv-client - Full Platform Client API reference
- openserv-multi-agent-workflows - Multi-agent collaboration patterns
- openserv-launch - Launch tokens on Base blockchain
- openserv-ideaboard-api - Find ideas and ship agent services on the Ideaboard