Skip to content

Agents

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.

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.`,
});
PropertyTypeDescription
namestringUnique identifier for the agent
modelstringLLM model identifier (e.g., openai:gpt-4o)
systemPromptstringInstructions defining the agent’s behavior
toolsTool[]Array of tools available to the agent
temperaturenumberCreativity level (0-1)
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);
}
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,
});
  1. Single Responsibility: Each agent should have one clear purpose
  2. Clear Prompts: Write explicit system prompts that define behavior
  3. Appropriate Tools: Only provide tools relevant to the agent’s role
  4. Temperature Tuning: Use lower temperatures for factual tasks, higher for creative ones