Skip to main content
A sophisticated support agent that searches documentation, remembers context, and creates tickets in HubSpot.
import { Agent, openai, createTool } from '@runflow-ai/sdk';
import { z } from 'zod';

// Create a support agent with memory and RAG
const supportAgent = new Agent({
  name: 'Customer Support AI',
  instructions: `You are a helpful customer support agent.
  - Search the knowledge base for relevant information
  - Remember previous conversations
  - Create tickets for complex issues
  - Always be professional and empathetic`,

  model: openai('gpt-4o'),

  // Remember conversation history
  memory: {
    maxTurns: 20,
    summarizeAfter: 10,
    summarizePrompt: 'Summarize key customer issues and resolutions',
  },

  // Search in documentation
  rag: {
    vectorStore: 'support-docs',
    k: 5,
    threshold: 0.7,
  },

  // Available tools
  tools: {
    createTicket: createTool({
      id: 'create-ticket',
      description: 'Create a support ticket',
      inputSchema: z.object({
        subject: z.string(),
        description: z.string(),
        priority: z.enum(['low', 'medium', 'high']),
      }),
      execute: async ({ context }) => {
        // Create ticket logic
        return { ticketId: 'TICKET-123' };
      },
    }),
    searchOrders: createTool({
      id: 'search-orders',
      description: 'Search customer orders',
      inputSchema: z.object({
        customerId: z.string(),
      }),
      execute: async ({ context }) => {
        const orders = await fetchOrders(context.customerId);
        return { orders };
      },
    }),
  },
});

// Handle customer message
const result = await supportAgent.process({
  message: 'My order #12345 has not arrived yet',
  sessionId: 'session_xyz',  // For conversation history
  userId: 'user_123',         // For user identification
});

console.log(result.message);
// Agent searches docs, retrieves order info, and provides solution

Features

  • RAG Search: Automatically searches documentation when needed
  • Memory: Remembers conversation context
  • Tools: Can create tickets and search orders
  • Professional: Always maintains professional tone

Next Steps