Rabbit SDK Logo
Rabbit SDK
GitHub
Documentation

Core Concepts

Agents

The core Agent engine of the Rabbit SDK.

Agents

The Agent class is the central orchestration engine. It manages the execution loop, memory, tools, guardrails, and provider fallback chains.

The Agent Loop

Basic Initialization

typescript
import { Agent, OpenAIProvider } from "@rabbit-agent-sdk/rabbit-agent-sdk";
 
const agent = new Agent({
  provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }),
  systemPrompt: "You are a helpful and concise assistant.",
});
 
const response = await agent.run("Hello, who are you?");
console.log(response);
// → "I'm a helpful and concise assistant. How can I help you today?"

Full Configuration

You can configure the agent with memory, guardrails, multiple tools, and fallbacks:

typescript
import {
  Agent,
  OpenAIProvider,
  GroqProvider,
  BufferMemory,
  ProfanityGuardrail,
  PIIGuardrail,
  MaxLengthGuardrail,
  FetchTool,
  WebSearchTool,
} from "@rabbit-agent-sdk/rabbit-agent-sdk";
 
const agent = new Agent({
  // Required — the primary LLM provider
  provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY }),
 
  // Optional — backup providers tried in order if primary fails
  fallbackProviders: [
    new GroqProvider({ apiKey: process.env.GROQ_API_KEY }),
  ],
 
  // Optional — system prompt injected at the start of every conversation
  systemPrompt: "You are a senior financial analyst. Be precise and cite sources.",
 
  // Optional — tools the agent can call
  tools: [new FetchTool(), new WebSearchTool(process.env.TAVILY_API_KEY)],
 
  // Optional — input/output validation guardrails
  guardrails: [
    new ProfanityGuardrail(),          // Block profanity in user input
    new PIIGuardrail(),                // Block PII in user input
    new MaxLengthGuardrail(4000, "output"),  // Cap output length
  ],
 
  // Optional — custom memory implementation (defaults to BufferMemory)
  memory: new BufferMemory(),
 
  // Optional — enable response streaming (default: false)
  stream: false,
 
  // Optional — max agentic loop iterations (default: 5)
  maxSteps: 10,
});

AgentConfig Reference

PropertyTypeDefaultDescription
providerProvider(required)Primary LLM provider
fallbackProvidersProvider[][]Sequential fallback providers
systemPromptstringundefinedSystem instruction prepended to every call
toolsTool[][]Tools available to the agent
guardrailsGuardrails[][]Input/output validation guardrails
memoryMemorynew BufferMemory()Conversation memory backend
streambooleanfalseEnable streaming responses
maxStepsnumber5Max execution loop steps (budget control)

Agents are capable of executing actions automatically. Learn how to add capabilities with Tools.