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 Mozaik. 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
1import { MozaikAgent, MozaikRequest } from '@mozaik-ai/core'23// Define the command configuration4const request: MozaikRequest = {5 model: 'claude-sonnet-4.5'6}78// Create the agent9const agent = new MozaikAgent(request)1011// Execute a task12const response = await agent.act('Write a React component for a todo list')1314console.log(response)
Command Configuration
The Command object lets you configure various aspects of the agent's behavior:
command-config.ts
1import { Agent, Command } from '@mozaik-ai/core'23const command: Command = {4 // Required: specify the model5 model: 'gpt-5',67 // Optional: initial task for the agent8 task: 'Analyze this codebase and suggest improvements',910 // Optional: conversation history11 messages: [12 { role: 'system', content: 'You are a helpful coding assistant' },13 { role: 'user', content: 'Previous context...' }14 ],1516 // Optional: tools for function calling17 tools: [...],1819 // Optional: structured output schema20 structuredOutput: myZodSchema21}2223const agent = new Agent(command)
Provider Comparison
Easily compare outputs from different providers:
compare-providers.ts
1import { Agent } from '@mozaik-ai/core'23const task = 'Explain the concept of closures in JavaScript'45// Create agents for different providers6const gptAgent = new Agent({ model: 'gpt-5' })7const claudeAgent = new Agent({ model: 'claude-sonnet-4.5' })89// Get responses from both10const [gptResponse, claudeResponse] = await Promise.all([11 gptAgent.act(task),12 claudeAgent.act(task)13])1415console.log('GPT-5:', gptResponse)16console.log('Claude:', claudeResponse)
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.