AGENTS

Agents

Learn how to create, configure, and manage AI agents in Zod.

Creating Agents

Agents are created by instantiating the Agent class with configuration options.

Basic Agent

import { Agent } from 'zod-framework';

const assistant = new Agent({
  name: 'Assistant',
  description: 'A helpful AI assistant',
  model: 'gpt-4',
  skills: ['conversation', 'reasoning'],
  tools: ['filesystem'],
  systemPrompt: `You are a helpful assistant.`,
});

Advanced Agent Configuration

import { Agent } from 'zod-framework';

const codeReviewer = new Agent({
  name: 'CodeReviewer',
  description: 'Reviews code for bugs and security issues',
  model: 'gpt-4-turbo',
  skills: ['coding', 'reasoning', 'vision'],
  tools: ['filesystem', 'terminal', 'web-search'],
  systemPrompt: `You are an expert code reviewer. Focus on:
    - Security vulnerabilities
    - Performance issues
    - Code quality
    - Best practices`,
  maxTokens: 4096,
  temperature: 0.2,
  timeout: 60000,
});

Agent Properties

PropertyTypeDescription
namestringUnique identifier for the agent
descriptionstringHuman-readable description
modelstringThe AI model to use
skillsarrayList of skills to enable
toolsarrayList of tools to enable
systemPromptstringSystem prompt for the agent
maxTokensnumberMaximum tokens in response
temperaturenumberCreativity level (0-1)
timeoutnumberRequest timeout in ms

Agent Methods

message()

Send a conversational message to an agent:

const response = await agent.message('What is the capital of France?');
console.log(response.content);

task()

Assign a specific task to an agent:

const result = await agent.task('Review the code in src/auth.js');
console.log(result.feedback);

chat()

Start an interactive chat session:

const chat = agent.chat();
await chat.send('Hello!');
const reply = await chat.receive();

Agent State

Agents maintain internal state that can be accessed and modified:

// Get agent state
const state = agent.getState();
console.log(state.messageCount);

// Update state
agent.setState({ customData: 'value' });

Agent Events

Listen to agent events for monitoring and debugging:

agent.on('message', (msg) => {
  console.log('Agent received:', msg);
});

agent.on('response', (res) => {
  console.log('Agent responded:', res);
});

agent.on('error', (err) => {
  console.error('Agent error:', err);
});

Agent Lifecycle Hooks

Define custom behavior at different lifecycle stages:

const agent = new Agent({
  name: 'CustomAgent',
  model: 'gpt-4',
  skills: ['conversation'],
  hooks: {
    async onReceive(message) {
      console.log('Processing message:', message);
    },
    async onRespond(response) {
      console.log('Generated response:', response);
    },
    async onError(error) {
      console.error('Error occurred:', error);
    },
  },
});

Best Practices

  1. Keep system prompts specific: More specific prompts lead to better results
  2. Limit tool access: Only give agents the tools they need
  3. Set appropriate timeouts: Balance between waiting and failing fast
  4. Monitor agent state: Use events and state to debug issues
  5. Use skills wisely: More skills aren’t always better - choose relevant ones

Continue to Multi-Agent Systems to learn how to coordinate multiple agents.

Copyright © 2026 Zod · GitHub