Tutorial: Creating Custom Agents

Create your own specialized AI agents that integrate with Bootspring's orchestration system.

What You'll Build#

  • A custom "code-reviewer" agent
  • Custom prompts and personas
  • Integration with Bootspring orchestrator
  • Agent collaboration patterns

Prerequisites#

  • Bootspring Pro or higher
  • Basic understanding of agent concepts
  • Project with bootspring.config.js

Understanding Custom Agents#

Custom agents allow you to:

  • Create domain-specific expertise
  • Define custom prompts and behaviors
  • Add project-specific knowledge
  • Extend Bootspring's capabilities

Step 1: Agent Configuration#

Create a custom agent in your Bootspring configuration:

1// bootspring.config.js 2module.exports = { 3 project: { 4 name: 'my-saas', 5 type: 'web', 6 framework: 'nextjs', 7 }, 8 9 // Custom agents 10 agents: { 11 custom: [ 12 { 13 name: 'code-reviewer', 14 description: 'Reviews code for quality, security, and best practices', 15 persona: `You are an expert code reviewer with 15+ years of experience. 16You focus on: 17- Code quality and maintainability 18- Security vulnerabilities 19- Performance implications 20- Best practices and patterns 21- Test coverage gaps 22 23You provide constructive feedback with specific suggestions.`, 24 capabilities: [ 25 'code_review', 26 'security_analysis', 27 'performance_review', 28 'best_practices', 29 ], 30 defaultContext: [ 31 'eslintrc', 32 'tsconfig', 33 'prettier', 34 ], 35 }, 36 ], 37 }, 38};

Step 2: Create the Agent Definition#

Create a more detailed agent definition file:

1// agents/code-reviewer.ts 2export const codeReviewerAgent = { 3 name: 'code-reviewer', 4 displayName: 'Code Reviewer', 5 category: 'quality', 6 7 description: `Expert code reviewer that analyzes code for quality, 8security vulnerabilities, performance issues, and adherence to best practices.`, 9 10 persona: `You are a senior software engineer with extensive experience in 11code review. You've worked at top tech companies and have developed a keen 12eye for code quality. 13 14Your review style is: 15- **Constructive**: Always offer solutions, not just criticism 16- **Prioritized**: Focus on high-impact issues first 17- **Educational**: Explain the "why" behind suggestions 18- **Pragmatic**: Balance perfection with shipping 19 20You categorize feedback as: 21- 🚨 CRITICAL: Must fix before merge (security, bugs) 22- ⚠️ IMPORTANT: Should fix (performance, maintainability) 23- 💡 SUGGESTION: Nice to have (style, minor improvements) 24- ✅ GOOD: Positive feedback on well-written code`, 25 26 systemPrompt: `When reviewing code, follow this structure: 27 28## Summary 29Brief overview of the changes and overall assessment. 30 31## Critical Issues 🚨 32Security vulnerabilities, bugs, or breaking changes. 33 34## Important Improvements ⚠️ 35Performance issues, maintainability concerns. 36 37## Suggestions 💡 38Style improvements, alternative approaches. 39 40## What's Good ✅ 41Highlight well-written code to reinforce good practices. 42 43## Test Coverage 44Assessment of test coverage for the changes. 45 46Always provide specific line references and code examples for fixes.`, 47 48 capabilities: [ 49 'analyze_code_quality', 50 'identify_security_issues', 51 'suggest_performance_improvements', 52 'check_test_coverage', 53 'verify_best_practices', 54 ], 55 56 tools: [ 57 'file_read', 58 'file_search', 59 'git_diff', 60 'eslint_check', 61 ], 62 63 contextSources: [ 64 { 65 type: 'file', 66 pattern: '.eslintrc*', 67 description: 'ESLint configuration', 68 }, 69 { 70 type: 'file', 71 pattern: 'tsconfig.json', 72 description: 'TypeScript configuration', 73 }, 74 { 75 type: 'file', 76 pattern: '.prettierrc*', 77 description: 'Prettier configuration', 78 }, 79 { 80 type: 'directory', 81 pattern: '__tests__/**', 82 description: 'Test files', 83 }, 84 ], 85 86 examplePrompts: [ 87 'Review the changes in the last commit', 88 'Review app/api/users/route.ts for security issues', 89 'Check if the authentication changes are secure', 90 'Review the database queries for performance', 91 ], 92 93 collaborators: [ 94 'security-expert', 95 'testing-expert', 96 'performance-expert', 97 ], 98};

Step 3: Register the Agent#

Register your custom agent with Bootspring:

1// agents/index.ts 2import { codeReviewerAgent } from './code-reviewer'; 3 4export const customAgents = [ 5 codeReviewerAgent, 6]; 7 8// Register with Bootspring 9export function registerCustomAgents() { 10 return customAgents.map(agent => ({ 11 ...agent, 12 invoke: createAgentInvoker(agent), 13 })); 14} 15 16function createAgentInvoker(agent: typeof codeReviewerAgent) { 17 return async (prompt: string, context?: any) => { 18 // Build the full prompt with persona and system instructions 19 const fullPrompt = ` 20${agent.persona} 21 22${agent.systemPrompt} 23 24--- 25 26User Request: ${prompt} 27`; 28 29 // Return the structured prompt for the orchestrator 30 return { 31 agent: agent.name, 32 prompt: fullPrompt, 33 context: { 34 ...context, 35 capabilities: agent.capabilities, 36 tools: agent.tools, 37 }, 38 }; 39 }; 40}

Step 4: Use the Custom Agent#

Via CLI#

# Invoke the custom agent bootspring agent invoke code-reviewer "Review the changes in my last commit" # Review specific files bootspring agent invoke code-reviewer "Review app/api/auth/route.ts"

Via MCP#

In Claude or your AI assistant:

Use the code-reviewer agent to review the authentication changes

Programmatically#

1// lib/review.ts 2import { invokeAgent } from '@/lib/bootspring'; 3 4export async function reviewPullRequest(prNumber: number) { 5 const diff = await getPRDiff(prNumber); 6 7 const review = await invokeAgent('code-reviewer', { 8 prompt: `Review this pull request: 9 10## Changed Files 11${diff.files.map(f => `- ${f.path}`).join('\n')} 12 13## Diff 14${diff.patch} 15 16Focus on security and breaking changes.`, 17 context: { 18 prNumber, 19 author: diff.author, 20 baseBranch: diff.base, 21 }, 22 }); 23 24 return review; 25}

Step 5: Create Specialized Variants#

Create variants for specific use cases:

1// bootspring.config.js 2module.exports = { 3 agents: { 4 custom: [ 5 // Base code reviewer 6 { 7 name: 'code-reviewer', 8 description: 'General code review', 9 // ... base config 10 }, 11 12 // Security-focused variant 13 { 14 name: 'security-reviewer', 15 extends: 'code-reviewer', 16 description: 'Security-focused code review', 17 persona: `You are a security expert who reviews code for vulnerabilities. 18You specialize in: 19- OWASP Top 10 vulnerabilities 20- Authentication/authorization flaws 21- Input validation issues 22- Cryptography problems 23- Injection attacks 24 25You are thorough and paranoid about security.`, 26 capabilities: [ 27 'security_analysis', 28 'vulnerability_detection', 29 'auth_review', 30 'input_validation_check', 31 ], 32 }, 33 34 // Performance-focused variant 35 { 36 name: 'performance-reviewer', 37 extends: 'code-reviewer', 38 description: 'Performance-focused code review', 39 persona: `You are a performance engineer who reviews code for efficiency. 40You focus on: 41- Algorithm complexity (Big O) 42- Database query efficiency 43- Memory usage 44- Bundle size impact 45- Caching opportunities 46 47You think about scale and production impact.`, 48 capabilities: [ 49 'performance_analysis', 50 'query_optimization', 51 'bundle_analysis', 52 'caching_recommendations', 53 ], 54 }, 55 ], 56 }, 57};

Step 6: Agent Collaboration#

Configure how your custom agent collaborates with others:

1// agents/code-reviewer.ts 2export const codeReviewerAgent = { 3 // ... previous config 4 5 collaboration: { 6 // Automatic handoffs based on findings 7 handoffs: [ 8 { 9 condition: 'security_issue_found', 10 agent: 'security-expert', 11 prompt: 'Deep dive into this security issue: {issue}', 12 }, 13 { 14 condition: 'performance_issue_found', 15 agent: 'performance-expert', 16 prompt: 'Analyze this performance concern: {issue}', 17 }, 18 { 19 condition: 'test_coverage_low', 20 agent: 'testing-expert', 21 prompt: 'Suggest tests for: {uncovered_code}', 22 }, 23 ], 24 25 // Consultation for specific topics 26 consultations: [ 27 { 28 topic: 'database', 29 agent: 'database-expert', 30 }, 31 { 32 topic: 'api_design', 33 agent: 'api-expert', 34 }, 35 ], 36 }, 37};

Step 7: Add Custom Tools#

Create custom tools for your agent:

1// agents/tools/git-diff.ts 2export const gitDiffTool = { 3 name: 'git_diff', 4 description: 'Get git diff for specified commits or files', 5 6 parameters: { 7 type: 'object', 8 properties: { 9 ref: { 10 type: 'string', 11 description: 'Git reference (commit, branch, or HEAD~n)', 12 default: 'HEAD~1', 13 }, 14 files: { 15 type: 'array', 16 items: { type: 'string' }, 17 description: 'Specific files to diff', 18 }, 19 context: { 20 type: 'number', 21 description: 'Lines of context around changes', 22 default: 3, 23 }, 24 }, 25 }, 26 27 execute: async (params: { 28 ref?: string; 29 files?: string[]; 30 context?: number; 31 }) => { 32 const { ref = 'HEAD~1', files = [], context = 3 } = params; 33 const { execSync } = require('child_process'); 34 35 const fileArgs = files.length > 0 ? `-- ${files.join(' ')}` : ''; 36 const command = `git diff -U${context} ${ref} ${fileArgs}`; 37 38 try { 39 const diff = execSync(command, { encoding: 'utf-8' }); 40 return { 41 success: true, 42 diff, 43 summary: parseDiffSummary(diff), 44 }; 45 } catch (error) { 46 return { 47 success: false, 48 error: error.message, 49 }; 50 } 51 }, 52}; 53 54function parseDiffSummary(diff: string) { 55 const files = diff.match(/diff --git a\/(.+) b\/.+/g) || []; 56 const additions = (diff.match(/^\+[^+]/gm) || []).length; 57 const deletions = (diff.match(/^-[^-]/gm) || []).length; 58 59 return { 60 filesChanged: files.length, 61 additions, 62 deletions, 63 }; 64}

Register the tool:

1// agents/code-reviewer.ts 2import { gitDiffTool } from './tools/git-diff'; 3 4export const codeReviewerAgent = { 5 // ... previous config 6 7 customTools: [ 8 gitDiffTool, 9 ], 10};

Step 8: Add Context Providers#

Create custom context providers:

1// agents/context/eslint-issues.ts 2export const eslintIssuesProvider = { 3 name: 'eslint_issues', 4 description: 'Current ESLint issues in the project', 5 6 provide: async (options: { files?: string[] }) => { 7 const { execSync } = require('child_process'); 8 const { files = ['.'] } = options; 9 10 try { 11 const result = execSync( 12 `npx eslint ${files.join(' ')} --format json`, 13 { encoding: 'utf-8' } 14 ); 15 16 const issues = JSON.parse(result); 17 18 return { 19 totalIssues: issues.reduce( 20 (acc: number, file: any) => acc + file.errorCount + file.warningCount, 21 0 22 ), 23 errors: issues.reduce( 24 (acc: number, file: any) => acc + file.errorCount, 25 0 26 ), 27 warnings: issues.reduce( 28 (acc: number, file: any) => acc + file.warningCount, 29 0 30 ), 31 byFile: issues.map((file: any) => ({ 32 path: file.filePath, 33 errors: file.errorCount, 34 warnings: file.warningCount, 35 messages: file.messages.slice(0, 5), // Top 5 issues 36 })), 37 }; 38 } catch (error) { 39 return { 40 error: 'Failed to run ESLint', 41 details: error.message, 42 }; 43 } 44 }, 45};

Step 9: Test Your Agent#

Create tests for your custom agent:

1// __tests__/agents/code-reviewer.test.ts 2import { describe, it, expect } from 'vitest'; 3import { codeReviewerAgent } from '@/agents/code-reviewer'; 4 5describe('Code Reviewer Agent', () => { 6 it('has required configuration', () => { 7 expect(codeReviewerAgent.name).toBe('code-reviewer'); 8 expect(codeReviewerAgent.persona).toBeDefined(); 9 expect(codeReviewerAgent.capabilities).toContain('code_review'); 10 }); 11 12 it('generates proper system prompt', () => { 13 expect(codeReviewerAgent.systemPrompt).toContain('Summary'); 14 expect(codeReviewerAgent.systemPrompt).toContain('Critical Issues'); 15 }); 16 17 it('has valid context sources', () => { 18 const sources = codeReviewerAgent.contextSources; 19 expect(sources.some(s => s.pattern.includes('eslint'))).toBe(true); 20 expect(sources.some(s => s.pattern.includes('tsconfig'))).toBe(true); 21 }); 22 23 it('lists collaborators', () => { 24 expect(codeReviewerAgent.collaborators).toContain('security-expert'); 25 }); 26});

Step 10: Document Your Agent#

Create documentation for your custom agent:

1<!-- docs/agents/code-reviewer.md --> 2# Code Reviewer Agent 3 4Custom agent for automated code review. 5 6## Capabilities 7 8- **Code Quality Analysis**: Reviews code for maintainability and readability 9- **Security Review**: Identifies potential security vulnerabilities 10- **Performance Review**: Spots performance anti-patterns 11- **Test Coverage**: Checks for adequate test coverage 12 13## Usage 14 15### Basic Review 16 17```bash 18bootspring agent invoke code-reviewer "Review app/api/users/route.ts"

PR Review#

bootspring agent invoke code-reviewer "Review the changes in PR #123"

Security Focus#

bootspring agent invoke security-reviewer "Review authentication changes"

Example Output#

1## Summary 2This PR adds user authentication with Clerk. Overall good implementation 3with a few security considerations. 4 5## Critical Issues 🚨 6 7### 1. Missing CSRF Protection 8**File**: `app/api/auth/callback/route.ts:15` 9 10The callback endpoint doesn't verify the state parameter... 11 12## Important Improvements ⚠️ 13 14### 1. Rate Limiting 15**File**: `app/api/auth/login/route.ts` 16 17Consider adding rate limiting to prevent brute force... 18 19## What's Good ✅ 20 21- Clean separation of concerns 22- Proper error handling 23- Good TypeScript types

Collaboration#

This agent automatically consults:

  • security-expert for security issues
  • performance-expert for performance concerns
  • testing-expert for test coverage gaps
## Verification Checklist - [ ] Agent configuration added to `bootspring.config.js` - [ ] Agent definition file created - [ ] Custom tools implemented (optional) - [ ] Context providers configured (optional) - [ ] Agent tests written - [ ] Documentation created - [ ] Agent accessible via CLI - [ ] Collaboration patterns working ## What You Learned - Creating custom agent configurations - Defining agent personas and prompts - Building custom tools - Configuring context providers - Setting up agent collaboration - Testing custom agents ## Next Steps - [Create domain-specific agents](/docs/tutorials/domain-agents) - [Build agent workflows](/docs/tutorials/custom-workflows) - [Integrate with external services](/docs/tutorials/agent-integrations)