docs/src/course/04-workflows/11-creating-an-ai-agent.md
Learn how to create an Mastra agent that can be used within your workflows for more intelligent content processing.
Create a new file for your agent in the src/mastra/agents directory. Use content-agent.ts as the name of the file with the following contents:
// src/mastra/agents/content-agent.ts
import { Agent } from '@mastra/core/agent'
export const contentAgent = new Agent({
name: 'Content Agent',
description: 'AI agent for analyzing and improving content',
instructions: `
You are a professional content analyst. Your role is to:
1. Analyze content for clarity and engagement
2. Identify the main themes and topics
3. Provide a quality score from 1-10
4. Suggest specific improvements
Always provide constructive, actionable feedback.
`,
model: 'openai/gpt-5.4',
})
Open your src/mastra/index.ts file and add your agent (you may need to append it to the agents object in the Mastra class):
// Import your workflow
import { contentAgent } from './agents/content-agent'
export const mastra = new Mastra({
// Register your agent here
agents: {
contentAgent,
},
// ...Existing code
})
You can test this agent in the Playground by navigating to the Agents tab and selecting content-agent. Use the chat interface to validate the agent is working.
The agent should provide analysis of the content, including themes, quality assessment, and improvement suggestions.
Agents add intelligence to workflows by:
Your AI agent is ready! Next, you'll learn how to integrate it into a workflow step.