AI Agents

Create AI agents through a single unified request definition. Mix providers and choose the best model for each task.

Overview

The Agent class is the core building block of Mosaic. It provides a consistent interface for interacting with different AI providers, making it easy to switch models or compare outputs.

Basic Usage

Create an agent by defining a command with your desired model:

basic-agent.ts

Command Configuration

The Command object lets you configure various aspects of the agent's behavior:

command-config.ts

Provider Comparison

Easily compare outputs from different providers:

compare-providers.ts

Tip

Running agents in parallel with Promise.all is a great way to compare model outputs or improve reliability through redundancy.

Best Practices

  • Choose the right model: Use smaller models (gpt-5-nano) for simple tasks and larger models (gpt-5, claude-opus) for complex reasoning.
  • Use system messages: Provide context and instructions via the messages array with role: 'system'.
  • Type your responses: Use structured output with Zod schemas for predictable, typed responses.

Next Steps