Skip to main content
Agents are the fundamental building blocks of the Runflow SDK. Each agent is configured with:
  • Name: Agent identifier
  • Instructions: Behavior instructions (system prompt)
  • Model: LLM model to use (OpenAI, Anthropic, Bedrock, Groq, Gemini, Azure OpenAI, or custom)
  • Tools: Available tools for the agent
  • Memory: Memory configuration
  • RAG: Knowledge base search configuration

Complete Agent Configuration

import { Agent, anthropic } from '@runflow-ai/sdk';

const agent = new Agent({
  name: 'Advanced Support Agent',
  instructions: `You are an expert customer support agent.
    - Always be polite and helpful
    - Solve problems efficiently
    - Use tools when needed`,

  // Model
  model: anthropic('claude-3-5-sonnet-20241022'),

  // Model configuration
  modelConfig: {
    temperature: 0.7,
    maxTokens: 4000,
    topP: 0.9,
    frequencyPenalty: 0,
    presencePenalty: 0,
  },

  // Memory
  memory: {
    maxTurns: 20,
    summarizeAfter: 50,
    summarizePrompt: 'Create a concise summary highlighting key points and decisions',
    summarizeModel: openai('gpt-4o-mini'), // Cheaper model for summaries
  },

  // RAG (Agentic - LLM decides when to search)
  rag: {
    vectorStore: 'support-docs',
    k: 5,
    threshold: 0.7,
    searchPrompt: 'Use for technical questions',
  },

  // Tools
  tools: {
    createTicket: ticketTool,
    searchOrders: orderTool,
  },

  // Tool iteration limit
  maxToolIterations: 10,

  // Streaming
  streaming: {
    enabled: true,
  },

  // Debug mode
  debug: true,
});

Supported Models

import { openai, anthropic, bedrock, groq, gemini, custom } from '@runflow-ai/sdk';

// OpenAI
const gpt4 = openai('gpt-4o');
const gpt4mini = openai('gpt-4o-mini');

// Anthropic (Claude)
const claude = anthropic('claude-sonnet-4-20250514');
const claudeHaiku = anthropic('claude-3-5-haiku-20241022');

// AWS Bedrock
const claudeBedrock = bedrock('anthropic.claude-3-5-sonnet-20241022-v2:0');
const titan = bedrock('amazon.titan-text-express-v1');

// Groq (ultra-fast inference)
const llama = groq('llama-3.3-70b-versatile');
const llamaFast = groq('llama-3.1-8b-instant');

// Google Gemini
const flash = gemini('gemini-2.5-flash');
const pro = gemini('gemini-2.5-pro');

// Custom (OpenAI-compatible: Ollama, vLLM, LiteLLM, etc.)
const local = custom('llama3', 'Ollama Local');
See LLM Providers for full details on configuring providers, credentials, and named configurations.

Agent Methods

// Process a message
const result = await agent.process(input: AgentInput): Promise<AgentOutput>;

// Stream a message
const stream = await agent.processStream(input: AgentInput): AsyncIterable<ChunkType>;

// Simple generation (without full agent context)
const response = await agent.generate(input: string | Message[]): Promise<{ text: string }>;

// Streaming generation
const stream = await agent.generateStream(prompt: string): AsyncIterable<ChunkType>;

// Generation with tools
const response = await agent.generateWithTools(input): Promise<{ text: string }>;

Multi-Agent Systems (Supervisor Pattern)

Add the agents field to create a supervisor that automatically routes requests to specialized child agents using LLM-based intent classification:
const supervisor = new Agent({
  name: 'Customer Service',
  instructions: `Route requests to the right specialist:
    - Sales: pricing, plans, purchases
    - Support: technical issues, bugs, how-to`,
  model: openai('gpt-4o-mini'), // Cheap model for routing
  agents: {
    support: {
      name: 'Support Agent',
      instructions: 'Solve technical problems step by step.',
      model: openai('gpt-4o'),
      tools: { searchOrders: orderTool },
      rag: { vectorStore: 'support-docs', k: 5 },
    },
    sales: {
      name: 'Sales Agent',
      instructions: 'Handle sales inquiries. Be consultative.',
      model: openai('gpt-4o'),
    },
  },
  memory: { maxTurns: 30 },
});

// Supervisor analyzes intent and routes automatically
await supervisor.process({
  message: 'I want to buy your product',
  sessionId: 'session_123',
});
Each child agent can have its own model, tools, RAG, and memory. The supervisor uses a cheap model for routing while specialists use powerful models for quality responses.
See the dedicated Supervisor guide for routing logic, cost optimization, fallback behavior, and configuration reference.

Debug Mode

const agent = new Agent({
  name: 'Debug Agent',
  instructions: 'Help users',
  model: openai('gpt-4o'),

  // Simple debug (all logs enabled)
  debug: true,

  // Or detailed debug configuration
  debug: {
    enabled: true,
    logMessages: true,      // Log messages
    logLLMCalls: true,      // Log LLM API calls
    logToolCalls: true,     // Log tool executions
    logRAG: true,           // Log RAG searches
    logMemory: true,        // Log memory operations
    truncateAt: 1000,       // Truncate logs at N characters
  },
});

Next Steps

Memory

Learn about memory management

Tools

Create custom tools