Installation
Copy
npm install @runflow-ai/sdk
# or
yarn add @runflow-ai/sdk
# or
pnpm add @runflow-ai/sdk
Simple Agent
Create your first agent in just a few lines:Copy
import { Agent, openai } from '@runflow-ai/sdk';
// Create a basic agent
const agent = new Agent({
name: 'Support Agent',
instructions: 'You are a helpful customer support assistant.',
model: openai('gpt-4o'),
});
// Process a message
const result = await agent.process({
message: 'I need help with my order', // Required
sessionId: 'session_456', // Optional: For conversation history
userId: 'user_789', // Optional: User identifier
companyId: 'company_123', // Optional: For multi-tenant apps
});
console.log(result.message);
Agent with Memory
Enable conversation history:Copy
import { Agent, openai } from '@runflow-ai/sdk';
const agent = new Agent({
name: 'Support Agent',
instructions: 'You are a helpful assistant with memory.',
model: openai('gpt-4o'),
memory: {
maxTurns: 10,
},
});
// First interaction
await agent.process({
message: 'My name is John',
sessionId: 'session_456', // Same session for conversation continuity
});
// Second interaction - agent remembers the name
const result = await agent.process({
message: 'What is my name?',
sessionId: 'session_456', // Same session
});
console.log(result.message); // "Your name is John"
Agent with Tools
Add custom tools for your agent:Copy
import { Agent, openai, createTool } from '@runflow-ai/sdk';
import { z } from 'zod';
// Create a custom tool
const weatherTool = createTool({
id: 'get-weather',
description: 'Get current weather for a location',
inputSchema: z.object({
location: z.string(),
}),
execute: async ({ context }) => {
// Fetch weather data
return {
temperature: 22,
condition: 'Sunny',
location: context.location,
};
},
});
// Create agent with tool
const agent = new Agent({
name: 'Weather Agent',
instructions: 'You help users check the weather.',
model: openai('gpt-4o'),
tools: {
weather: weatherTool,
},
});
const result = await agent.process({
message: 'What is the weather in São Paulo?',
});
console.log(result.message);
Agent with RAG (Knowledge Base)
Enable semantic search in your knowledge base:Copy
import { Agent, openai } from '@runflow-ai/sdk';
const agent = new Agent({
name: 'Support Agent',
instructions: 'You are a helpful support agent.',
model: openai('gpt-4o'),
rag: {
vectorStore: 'support-docs',
k: 5,
threshold: 0.7,
searchPrompt: `Use searchKnowledge tool when user asks about:
- Technical problems
- Process questions
- Specific information`,
},
});
// Agent automatically has 'searchKnowledge' tool
// LLM decides when to use it (not always searching - more efficient!)
const result = await agent.process({
message: 'How do I reset my password?',
});
Next Steps
Core Concepts
Learn about Agents, Memory, Tools, and more
Real-World Examples
See production-ready examples
Configuration
Configure your SDK
API Reference
Complete API documentation
Note on Parameters:
messageis required (the user’s message)companyIdis optional (for multi-tenant applications)sessionIdis optional but recommended (maintains conversation history)userIdis optional (for user identification)- All other fields are optional and can be set via
Runflow.identify()or environment variables