Stoneforge provides three built-in agent roles (Director, Worker, Steward), but you can customize them with role definitions and prompt overrides to create specialized agents tailored to your team’s workflow.
Role definitions let you create worker variants with specific skills and behaviors:
import { createRoleDefinitionService } from '@stoneforge/smithy';import type { QuarryAPI } from '@stoneforge/quarry';const roleDefService = createRoleDefinitionService(api);// Frontend specialistconst frontendWorker = await roleDefService.createRoleDefinition({ role: 'worker', name: 'Frontend Developer', systemPrompt: `You specialize in React, TypeScript, and modern web development.## Technology Stack- React 18 with hooks- TypeScript with strict mode- TanStack Query for data fetching- Tailwind CSS for styling- Vitest for testing## Coding Standards- Use functional components only- Prefer named exports over default- Write unit tests for all components- Follow accessibility best practices (WCAG 2.1 AA)`, workerMode: 'ephemeral', createdBy: directorId, tags: ['frontend', 'react', 'typescript'], behaviors: { onStartup: 'Review the component library documentation before starting', onTaskAssigned: 'Check for existing similar components to reuse patterns', onStuck: 'Review the design system docs, then ask for help after 30 min', onError: 'Check browser console, network tab, and React DevTools', },});// Backend specialist const backendWorker = await roleDefService.createRoleDefinitionForAgent({ role: 'worker', name: 'Backend Developer', systemPrompt: `You specialize in Node.js, databases, and API development.## Technology Stack- Node.js with TypeScript- PostgreSQL with Drizzle ORM- tRPC for type-safe APIs- Zod for validation## Best Practices- Use transactions for multi-step database operations- Validate all inputs with Zod schemas- Write integration tests for all endpoints- Document API endpoints with JSDoc`, workerMode: 'ephemeral', createdBy: directorId, tags: ['backend', 'api', 'database'], behaviors: { onStartup: 'Check database migration status', onTaskAssigned: 'Review API schema and database models', onStuck: 'Check logs, query explain plans, then escalate after 30 min', onError: 'Capture full stack trace and database error codes', },});
# Your Role: WorkerYou are a worker agent in the Stoneforge orchestration system.## Security-First DevelopmentThis project handles sensitive user data. Security is your top priority.### Before Any Code Change1. **Input Validation** - Never trust user input - Use Zod schemas for all API inputs - Sanitize data before storage or display - Validate file uploads (type, size, content)2. **Authentication & Authorization** - Verify auth on every protected endpoint - Use principle of least privilege - Never expose user IDs in URLs3. **Data Protection** - Never log sensitive data (passwords, tokens, PII) - Use parameterized queries (never string concat) - Encrypt sensitive fields at rest### Security Red FlagsIf you encounter ANY of these, report immediately to the security channel:- Hardcoded credentials or API keys- SQL injection vulnerabilities - XSS attack vectors- Missing authentication checks- Insecure direct object references- Sensitive data in logs or error messages## Your Responsibilities- Execute tasks assigned to you- Report progress and blockers...
Define agent behaviors for specific lifecycle events:
const roleDef = await roleDefService.createRoleDefinition({ role: 'worker', name: 'Testing-Focused Worker', systemPrompt: 'You prioritize test-driven development...', workerMode: 'ephemeral', createdBy: directorId, behaviors: { // Runs when agent session starts onStartup: ` 1. Check git status and pull latest changes 2. Run tests to verify clean baseline: npm test 3. Review the Documentation Directory: sf docs dir --content `, // Runs when task is assigned onTaskAssigned: ` 1. Read the full task description and acceptance criteria 2. Search for related documentation: sf document search <topic> 3. Check for similar existing implementations `, // Guidance when stuck onStuck: ` 1. Review error messages and stack traces carefully 2. Search documentation for the error/concept 3. Try breaking the task into smaller steps 4. If stuck for >30 min, handoff with context: sf task handoff <task-id> --message "..." `, // Error handling procedure onError: ` 1. Capture the full error output and context 2. Check logs for additional information 3. Verify the error is reproducible 4. Report with full details to the Director `, },});