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
const writer = new Agent({
name: 'Writer',
model: 'openai:gpt-4o',
systemPrompt: `You are a professional writer who creates
high-quality, engaging content.`,
}); 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
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
Tip
Agents can hand off tasks to each other using natural language, enabling complex workflows.
const team = [writer, reviewer];
// The lead agent coordinates the team
const lead = new Agent({
name: 'Lead',
model: 'openai:gpt-4o',
systemPrompt: 'Coordinate the writer and reviewer to produce quality content.',
team,
}); 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