Patter: Dynamic Variables

April 14, 2026 · View on GitHub

Patter

Patter: Dynamic Variables

Per-call prompt personalization with {variable} placeholder substitution in system prompts and first messages.

Part of the Patter Voice AI SDK.

Prerequisites

  • Twilio account with a phone number
  • OpenAI API key with Realtime access

Quick Start

Python

cd python
cp ../.env.example .env   # fill in your keys
pip install -r requirements.txt
python main.py

TypeScript

cd typescript
cp ../.env.example .env   # fill in your keys
npm install
npx tsx main.ts

Environment Variables

VariableRequiredDescription
OPENAI_API_KEYYesOpenAI API key with Realtime access
TWILIO_ACCOUNT_SIDYesTwilio account SID
TWILIO_AUTH_TOKENYesTwilio auth token
TWILIO_PHONE_NUMBERYesYour Twilio phone number (E.164)
WEBHOOK_URLNoPublic URL for webhooks (auto-tunneled if omitted)

What This Demonstrates

  • variables in agent() — define default placeholder values when creating an agent
  • {placeholder} syntax — use {customer_name}, {account_number}, etc. in system prompts and first messages
  • on_call_start returning variable overrides — dynamically swap variables per caller at runtime
  • Per-caller personalization — look up caller info from a database and inject it into the conversation

How It Works

  1. Define an agent with {variable} placeholders in the system prompt and first message
  2. Provide default values via the variables parameter
  3. When a call comes in, on_call_start looks up the caller in a database
  4. If found, return {"variables": {...}} to override defaults for that specific call
  5. Patter substitutes all placeholders before the conversation begins

Next Steps

License

MIT