Create AI Agent
Step-by-step guide to add a new AI agent to packages/ai/.
1. Define Agent Config
In packages/ai/src/agents/index.ts, add a new AgentConfig:
export const myNewAgent: AgentConfig = {
name: 'My New Agent',
systemPrompt: `You are a helpful agent that specializes in...
Be concise, technical, and provide examples when relevant. Use TypeScript for code samples.`,
tools: {}, // optional: tools for the agent
};
AgentConfig interface:
interface AgentConfig {
name: string;
systemPrompt: string;
tools?: Record<string, unknown>;
}
2. Register Agent
In the same file:
- Add to
AgentNameSchema:
export const AgentNameSchema = z.enum(['blog-assistant', 'code-explainer', 'my-new-agent']);
- Add to
getAgentmapping:
const agents: Record<AgentName, AgentConfig> = {
'blog-assistant': blogAssistant,
'code-explainer': codeExplainer,
'my-new-agent': myNewAgent,
};
3. Agent Name Convention
- Schema value: kebab-case (e.g.
my-new-agent) - Display name: Title Case (e.g. "My New Agent")
4. API Endpoint (if needed)
The AI chat endpoint is at apps/api/src/routes/ai.ts:
POST /api/ai/chat– streaming chat (usesChatRequestSchema)GET /api/ai/providers– list providers
To add agent selection, extend ChatRequestSchema in packages/types/src/ai.ts:
export const ChatRequestSchema = z.object({
messages: z.array(ChatMessageSchema),
provider: AiProviderSchema.default('openai'),
agent: AgentNameSchema.optional(), // add if needed
model: z.string().optional(),
temperature: z.number().min(0).max(2).default(0.7),
maxTokens: z.number().int().positive().max(4096).default(1024),
});
Then in the route, use getAgent(agentName) to fetch the system prompt for the selected agent.
5. Checklist
-
AgentConfigadded inpackages/ai/src/agents/index.ts - Added to
AgentNameSchemaenum - Added to
getAgentmapping - System prompt is clear and specific
- API updated if agent selection is required
Reference
- Agents:
packages/ai/src/agents/index.ts - AI routes:
apps/api/src/routes/ai.ts - Types:
packages/types/src/ai.ts
Source: adrianlopez-ia/adrianlopez-ia-blog — distributed by TomeVault.