Skip to content

Build an AI Agent

This tutorial walks you through building an AI agent with Minions, starting simple and growing in complexity.

The simplest possible agent is a single minion:

import { TypeRegistry, createMinion } from 'minions-sdk';
const registry = new TypeRegistry();
const agentType = registry.getBySlug('agent')!;
const { minion: agent } = createMinion({
title: 'Research Assistant',
fields: {
role: 'researcher',
model: 'gpt-4',
systemPrompt: 'You are a research assistant that finds and summarizes papers.',
temperature: 0.3,
tools: ['web-search', 'summarize'],
},
}, agentType);

That’s it. A complete, validated agent definition.

Agents need to remember things. Create a thought minion and link it:

const thoughtType = registry.getBySlug('thought')!;
const { minion: styleGuide } = createMinion({
title: 'Research Style Guide',
fields: {
content: 'Always cite sources. Prefer peer-reviewed papers. Summarize in 3 paragraphs.',
confidence: 0.95,
source: 'internal-guidelines',
},
}, thoughtType);

Define how the agent structures its output:

const promptType = registry.getBySlug('prompt-template')!;
const { minion: template } = createMinion({
title: 'Research Summary Template',
fields: {
template: 'Research topic: {{topic}}\n\nSummarize the top {{count}} papers.',
variables: ['topic', 'count'],
outputFormat: 'markdown',
},
}, promptType);

Use relations to build the tree:

import { RelationGraph } from 'minions-sdk';
const graph = new RelationGraph();
graph.add({ sourceId: agent.id, targetId: styleGuide.id, type: 'parent_of' });
graph.add({ sourceId: agent.id, targetId: template.id, type: 'parent_of' });
const children = graph.getChildren(agent.id);
// => [styleGuide.id, template.id]

Create a test case to verify agent quality:

const testType = registry.getBySlug('test-case')!;
const { minion: test } = createMinion({
title: 'Research Quality Test',
fields: {
input: { topic: 'transformer architectures', count: 3 },
assertions: { containsCitations: true, minPapers: 3 },
timeout: 30000,
},
}, testType);
graph.add({ sourceId: agent.id, targetId: test.id, type: 'parent_of' });
Research Assistant (agent)
├── Research Style Guide (thought) ← memory layer
├── Research Summary Template (prompt) ← interface layer
└── Research Quality Test (test-case) ← evaluation layer

Your agent started as a single flat minion and now has memory, templates, and tests — all validated, all queryable, all linked.