Agents
Overview
Section titled “Overview”Agents are the core building blocks of Viber. Each agent is a specialized entity designed to perform specific tasks, with its own role, tools, and configuration.
Creating an Agent
Section titled “Creating an Agent”import { Agent } from 'viber';
const writer = new Agent({ name: 'Writer', model: 'openai:gpt-4o', systemPrompt: `You are a professional writer who creates high-quality, engaging content.`,});Agent Configuration
Section titled “Agent Configuration”| Property | Type | Description |
|---|---|---|
name | string | Unique identifier for the agent |
model | string | LLM model identifier (e.g., openai:gpt-4o) |
systemPrompt | string | Instructions defining the agent’s behavior |
tools | Tool[] | Array of tools available to the agent |
temperature | number | Creativity level (0-1) |
Streaming Responses
Section titled “Streaming Responses”const result = await agent.streamText({ messages: [ { role: 'user', content: 'Write a haiku about coding' } ],});
for await (const chunk of result.textStream) { process.stdout.write(chunk);}Multi-Agent Collaboration
Section titled “Multi-Agent Collaboration”const team = [writer, reviewer];
// The lead agent coordinates the teamconst lead = new Agent({ name: 'Lead', model: 'openai:gpt-4o', systemPrompt: 'Coordinate the writer and reviewer to produce quality content.', team,});Best Practices
Section titled “Best Practices”- Single Responsibility: Each agent should have one clear purpose
- Clear Prompts: Write explicit system prompts that define behavior
- Appropriate Tools: Only provide tools relevant to the agent’s role
- Temperature Tuning: Use lower temperatures for factual tasks, higher for creative ones