-
Notifications
You must be signed in to change notification settings - Fork 4
Understanding Agents
Complete guide to aistack's 11 specialized agent types.
An agent in aistack is a specialized AI entity with:
- Unique purpose - Specific role (coder, tester, reviewer, etc.)
- System prompt - Specialized instructions that define behavior
- Capabilities - Declared skills and expertise
- State - Lifecycle status (idle, running, completed, failed, stopped)
- Context - Optional session and metadata association
Agents are ephemeral - they exist in memory during runtime and are spawned on-demand.
| Agent Type | Primary Role | Best For |
|---|---|---|
| Coder | Write and modify code | Implementation tasks |
| Researcher | Gather information | Code exploration, documentation review |
| Tester | Write and run tests | Test creation, quality assurance |
| Reviewer | Code review | Quality checks, best practices |
| Adversarial | Break code | Security testing, edge case discovery |
| Architect | System design | Technical decisions, architecture |
| Coordinator | Orchestrate agents | Multi-agent workflows |
| Analyst | Analyze data | Performance analysis, metrics |
| DevOps | Infrastructure | CI/CD, containers, deployment |
| Documentation | Write docs | API docs, guides, tutorials |
| Security Auditor | Security audit | Vulnerability scanning, compliance |
stateDiagram-v2
[*] --> Spawned: agent_spawn()
Spawned --> Idle: Ready for work
Idle --> Running: Task assigned
Running --> Idle: Task complete
Running --> Failed: Error occurred
Running --> Stopped: agent_stop()
Idle --> Stopped: agent_stop()
Failed --> [*]
Stopped --> [*]
- Spawned: Agent created, initializing
- Idle: Ready to accept tasks
- Running: Actively processing a task
- Completed: Task finished successfully
- Failed: Task encountered an error
- Stopped: Agent manually terminated
// Via MCP
{
"tool": "agent_spawn",
"arguments": {
"type": "coder",
"name": "my-coder",
"sessionId": "optional-session-id",
"metadata": { "project": "awesome-app" }
}
}
// Via TypeScript API
import { spawnAgent } from '@blackms/aistack';
const agent = spawnAgent('coder', {
name: 'my-coder',
sessionId: 'session-123',
metadata: { project: 'awesome-app' }
});What Happens:
- Agent definition loaded from registry
- Unique ID generated (UUID v4)
- System prompt prepared
- Agent added to active agents pool
- Status set to 'idle'
When an agent receives a task:
sequenceDiagram
participant User
participant Agent
participant LLM
participant Memory
User->>Agent: Execute task
Agent->>Agent: Set status: running
Agent->>Memory: Retrieve context
Memory-->>Agent: Relevant data
Agent->>LLM: Send prompt + context
LLM-->>Agent: Response
Agent->>Memory: Store results
Agent->>Agent: Set status: idle
Agent-->>User: Return results
Agents can access:
- Session context - Shared with other agents in same session
- Memory entries - Persistent storage via SQLite + FTS5
- Metadata - Custom data passed at spawn time
Each agent declares capabilities:
// Example: Coder agent
{
type: 'coder',
capabilities: [
'write-code',
'edit-code',
'refactor',
'debug',
'implement-features'
]
}- Self-documentation - Agents declare what they can do
- Task routing - Coordinators assign tasks based on capabilities
- User guidance - Users know what to expect from each agent
Purpose: Write, edit, and refactor code
Capabilities:
- Write new code from specifications
- Edit existing code
- Refactor for better quality
- Debug issues
- Implement features
Best Practices:
// Good: Specific task
"Implement a JWT validation function with TypeScript"
// Bad: Vague request
"Do some coding"Example Use Cases:
- Implement new features
- Fix bugs
- Refactor legacy code
- Add error handling
- Optimize algorithms
Purpose: Gather information from code and docs
Capabilities:
- Search codebase
- Read documentation
- Analyze patterns
- Gather requirements
- Explore architecture
Best Practices:
// Good: Focused research
"Find all authentication-related functions in the codebase"
// Bad: Unfocused
"Tell me about the code"Example Use Cases:
- Understand existing code
- Find usage patterns
- Gather requirements
- Identify dependencies
- Map system architecture
Purpose: Write and run tests
Capabilities:
- Write unit tests
- Write integration tests
- Run test suites
- Identify edge cases
- Coverage analysis
- Test debugging
Best Practices:
// Good: Complete test request
"Write comprehensive tests for the JWT validation function, including edge cases"
// Bad: Incomplete
"Write tests"Example Use Cases:
- Create test suites
- Improve coverage
- Test edge cases
- Debug failing tests
- Performance testing
Purpose: Review code for quality and best practices
Capabilities:
- Code review
- Security review
- Performance review
- Best practices check
- Provide feedback
Best Practices:
// Good: Specific review scope
"Review the authentication module for security and best practices"
// Bad: Too broad
"Review everything"Example Use Cases:
- Pre-commit reviews
- Pull request reviews
- Security checks
- Performance optimization
- Code quality audits
Purpose: Aggressively try to break code
Capabilities:
- Adversarial review
- Security audit
- Edge case analysis
- Attack vector identification
Best Practices:
// Used in review loops
{
"tool": "review_loop_start",
"arguments": {
"code": "function authenticate(user, pass) { ... }",
"maxIterations": 3
}
}Example Use Cases:
- Security-critical code
- API endpoints
- Authentication systems
- Data validation
- Payment processing
Purpose: Design systems and make technical decisions
Capabilities:
- System design
- Technical decisions
- Architecture review
- Documentation
- Trade-off analysis
Best Practices:
// Good: Clear design problem
"Design a scalable user notification system supporting email, SMS, and push notifications"
// Bad: Unclear scope
"Design a system"Example Use Cases:
- New feature architecture
- System design reviews
- Technology selection
- Scalability planning
- Migration strategies
Purpose: Orchestrate multi-agent workflows
Capabilities:
- Task decomposition
- Agent coordination
- Progress tracking
- Result synthesis
- Workflow management
Best Practices:
// Good: Complex multi-step task
"Build a complete user registration system with tests and documentation"
// Coordinator decomposes:
// 1. Architect: Design the system
// 2. Coder: Implement registration
// 3. Tester: Create tests
// 4. Security Auditor: Security review
// 5. Documentation: Write API docsExample Use Cases:
- Complex features
- End-to-end workflows
- Multi-component systems
- Large refactorings
- System migrations
Purpose: Analyze data and performance
Capabilities:
- Data analysis
- Performance profiling
- Metrics collection
- Trend analysis
- Reporting
Best Practices:
// Good: Specific analysis
"Analyze API response times over the last week and identify bottlenecks"
// Bad: Vague
"Analyze performance"Example Use Cases:
- Performance profiling
- Code complexity analysis
- Usage pattern analysis
- Benchmark comparison
- Trend identification
Purpose: Manage infrastructure and deployment
Capabilities:
- CI/CD setup
- Containerization
- Kubernetes deployment
- Infrastructure automation
- Monitoring setup
- Security hardening
- Cloud deployment
- Performance optimization
Best Practices:
// Good: Specific infrastructure task
"Create a GitHub Actions CI/CD pipeline with testing, build, and deploy stages"
// Bad: Too broad
"Set up DevOps"Example Use Cases:
- Docker containerization
- Kubernetes manifests
- CI/CD pipelines
- Infrastructure as code
- Monitoring configuration
- Cloud deployment
Purpose: Create comprehensive documentation
Capabilities:
- API documentation
- User guides
- Tutorials
- Code documentation
- Architecture docs
- Runbooks
- README creation
- Documentation review
Best Practices:
// Good: Specific doc type
"Create API documentation for the user authentication endpoints with examples"
// Bad: Generic
"Write docs"Example Use Cases:
- API reference docs
- Getting started guides
- Architecture documentation
- Inline code comments
- README files
- Tutorial creation
Purpose: Comprehensive security analysis
Capabilities:
- Vulnerability scanning
- Code security review
- Penetration testing
- Compliance checking
- Dependency audit
- Threat modeling
- Security documentation
- Remediation planning
Best Practices:
// Good: Specific security scope
"Audit the user authentication system for OWASP Top 10 vulnerabilities"
// Bad: Too vague
"Check security"Example Use Cases:
- OWASP compliance checks
- Dependency vulnerability scans
- Security code reviews
- Threat modeling
- PCI DSS compliance
- HIPAA compliance
Researcher → Coder → Tester → Reviewer
Use Case: Feature implementation
- Researcher gathers requirements
- Coder implements feature
- Tester creates tests
- Reviewer validates quality
┌─ Coder (Frontend)
Task ──┼─ Coder (Backend)
└─ Documentation
Use Case: Full-stack feature
- Frontend and backend developed in parallel
- Documentation written concurrently
Coder ←→ Adversarial
Use Case: Security-critical code
- Coder implements
- Adversarial finds issues
- Coder fixes
- Repeat until approved
Coordinator
├─ Architect (Design)
├─ Coder (Implement)
├─ Tester (Test)
└─ Security Auditor (Audit)
Use Case: Complex system
- Coordinator manages overall workflow
- Specialized agents handle specific tasks
// User directly interacts with agent
spawnAgent('coder', { name: 'my-coder' });
// Give task to my-coderimport { getMessageBus } from '@blackms/aistack';
const bus = getMessageBus();
// Agent A sends message to Agent B
bus.send(agentA.id, agentB.id, 'task:assign', {
task: { /* task data */ }
});
// Agent B receives and processes
bus.subscribe(agentB.id, (message) => {
if (message.type === 'task:assign') {
// Handle task
}
});// Coordinator orchestrates multiple agents
const coordinator = new HierarchicalCoordinator({
maxWorkers: 5,
sessionId: 'session-123'
});
await coordinator.submitTask({
type: 'build-feature',
description: 'Complete user authentication'
});
// Coordinator breaks down and assigns to agents✓ GOOD:
"auth-coder"
"api-tester"
"security-reviewer"
✗ BAD:
"agent1"
"test"
"temp"
✓ GOOD:
"Implement JWT token validation with error handling"
✗ BAD:
"Build authentication system"
Break complex tasks into smaller, focused tasks.
Use sessions for shared context:
// Start session
const session = await memory.createSession({
project: 'user-auth'
});
// Spawn agents in same session
const coder = spawnAgent('coder', { sessionId: session.id });
const tester = spawnAgent('tester', { sessionId: session.id });
// Both agents share session contextAlways handle agent failures:
try {
const result = await agent.execute(task);
} catch (error) {
console.error('Agent failed:', error);
// Retry or use alternative agent
}{
"agents": {
"maxConcurrent": 10 // Adjust based on resources
}
}- More agents = more parallelism
- But: Higher memory and API costs
// ✓ GOOD: Reuse agent for multiple tasks
const coder = spawnAgent('coder', { name: 'persistent-coder' });
await coder.execute(task1);
await coder.execute(task2);
await coder.execute(task3);
// ✗ BAD: Spawn new agent for each task
for (const task of tasks) {
const coder = spawnAgent('coder');
await coder.execute(task);
}// Stop agents when done
await stopAgent(agent.id);
// End sessions to free resources
await memory.endSession(session.id);While agents are ephemeral by default (existing only in memory during runtime), Agent Identity provides persistent, trackable identities that survive across sessions.
| Aspect | Ephemeral Agent | Agent Identity |
|---|---|---|
| Lifetime | Single session | Permanent |
| State | In-memory only | Persisted to SQLite |
| Tracking | Runtime only | Full audit trail |
| Versioning | None | Capabilities versioned |
stateDiagram-v2
[*] --> Created: identity_create()
Created --> Active: identity_activate()
Created --> Active: autoActivate=true
Active --> Dormant: identity_deactivate()
Dormant --> Active: identity_activate()
Active --> Retired: identity_retire()
Dormant --> Retired: identity_retire()
Retired --> [*]
// Via MCP
{
"tool": "identity_create",
"arguments": {
"agentType": "coder",
"displayName": "Primary Backend Coder",
"description": "Handles all backend feature development",
"capabilities": [
{ "name": "write-typescript", "version": "5.0", "enabled": true },
{ "name": "write-tests", "version": "1.0", "enabled": true }
],
"metadata": { "team": "backend", "project": "api" },
"autoActivate": true
}
}| Status | Description | Transitions |
|---|---|---|
created |
Just created, not yet active | → active
|
active |
Available for use | → dormant, retired
|
dormant |
Temporarily deactivated | → active, retired
|
retired |
Permanently retired | (terminal) |
// List active identities
{
"tool": "identity_list",
"arguments": { "status": "active", "agentType": "coder" }
}
// Get identity by name
{
"tool": "identity_get",
"arguments": { "displayName": "Primary Backend Coder" }
}
// Deactivate during maintenance
{
"tool": "identity_deactivate",
"arguments": {
"agentId": "uuid",
"reason": "Scheduled maintenance"
}
}
// View audit trail
{
"tool": "identity_audit",
"arguments": { "agentId": "uuid", "limit": 50 }
}All identity changes are logged:
{
"entries": [
{
"action": "status_change",
"previousStatus": "created",
"newStatus": "active",
"actorId": "user-123",
"timestamp": "2026-01-29T10:00:00Z"
},
{
"action": "metadata_update",
"actorId": "user-456",
"metadata": { "changedFields": ["capabilities"] },
"timestamp": "2026-01-29T11:00:00Z"
}
]
}Use Identities When:
- You need persistent tracking across sessions
- Audit compliance is required
- Managing a team of specialized agents
- Capabilities need versioning
Use Ephemeral Agents When:
- Quick one-off tasks
- Temporary exploratory work
- No audit requirements
See Identity Tools for complete tool reference.
Create your own specialized agents:
import { registerAgent } from '@blackms/aistack';
registerAgent({
type: 'my-custom-agent',
name: 'Custom Agent',
description: 'Does custom things',
systemPrompt: `You are a specialized agent that...`,
capabilities: ['custom-capability']
});See Custom Agent Types for details.
Plugins can register new agent types:
// In plugin
export function initialize(config) {
registerAgent({
type: 'plugin-agent',
// ... definition
});
}- Memory System - Learn about persistent storage
- Task Coordination - Multi-agent orchestration
- Sessions and Context - Context management
- Agent Guides - Detailed agent documentation
Related:
Getting Started
Core Concepts
Agent Guides
- Overview
- Coder
- Researcher
- Tester
- Reviewer
- Adversarial
- Architect
- Coordinator
- Analyst
- DevOps
- Documentation
- Security Auditor
MCP Tools
- Overview
- Agent Tools
- Memory Tools
- Task Tools
- Session Tools
- System Tools
- GitHub Tools
- Review Loop Tools
- Identity Tools
Recipes
- Index
- Code Review
- Doc Sync
- Multi-Agent
- Adversarial Testing
- Full-Stack Feature
- Memory Patterns
- GitHub Integration
Advanced
- Plugin Development
- Custom Agent Types
- Workflow Engine
- Vector Search Setup
- Web Dashboard
- Programmatic API
- Resource Monitoring
Reference