Constitution Rules
Overviewβ
Constitution Rules provide per-session rules and constraints for workflow execution. They allow you to set guidelines that agents should follow during a specific session, which are then included in oversight requests and agent prompts.
What are Constitution Rules?β
Constitution Rules are session-scoped rules that:
- Apply only to the current session (identified by session ID)
- Are automatically cleaned up after 1 hour of inactivity (TTL-based)
- Are limited to 50 rules per session
- Are included in oversight requests for context-aware feedback
- Can be used to enforce coding standards, preferences, or constraints
Usageβ
Setting Constitution Rulesβ
Constitution rules are managed programmatically through the ConstitutionManager API. In practice, they're typically set:
- During workflow execution: Rules can be set at the start of a workflow
- Via oversight integration: Rules are automatically included in oversight requests
- Through session management: Rules are tied to session IDs
Example Rulesβ
Common use cases for constitution rules:
// No external API calls
constitution_manager.update_constitution("session-123", "No external API calls".to_string());
// Prefer unit tests
constitution_manager.update_constitution("session-123", "Prefer unit tests over integration tests".to_string());
// Coding standards
constitution_manager.update_constitution("session-123", "Use Result types for error handling".to_string());
// Performance constraints
constitution_manager.update_constitution("session-123", "Optimize for readability over performance".to_string());
Integration with Vibe Checkβ
Constitution rules are automatically included in vibe check oversight requests:
- When a vibe check is triggered, the current session's constitution rules are gathered
- Rules are included in the oversight request context
- The oversight LLM considers these rules when providing feedback
- Feedback may reference rule violations or suggest rule-compliant approaches
Session Managementβ
Session IDsβ
Constitution rules are scoped to session IDs:
- Each workflow execution typically has a unique session ID
- Rules set for one session don't affect other sessions
- Session IDs are typically UUIDs or workflow identifiers
TTL and Cleanupβ
- Rules are automatically cleaned up after 1 hour of inactivity
- This prevents memory leaks from stale sessions
- Active sessions keep their rules until the session ends
Rule Limitsβ
- Maximum 50 rules per session
- This prevents context bloat in oversight requests
- If you need more rules, consider consolidating them
Best Practicesβ
- Be specific: Write clear, actionable rules
- Keep it focused: Limit rules to what's truly important for the session
- Use for constraints: Rules work best for constraints and preferences
- Review regularly: Check that rules are being followed via oversight feedback
- Session-specific: Use different rules for different types of workflows
Examplesβ
Example 1: Development Session Rulesβ
// Set rules for a development session
constitution_manager.update_constitution("dev-session", "No external API calls during development".to_string());
constitution_manager.update_constitution("dev-session", "Use mock data for testing".to_string());
constitution_manager.update_constitution("dev-session", "Follow existing code style".to_string());
Example 2: Code Review Session Rulesβ
// Set rules for a code review session
constitution_manager.update_constitution("review-session", "Focus on security vulnerabilities".to_string());
constitution_manager.update_constitution("review-session", "Check for performance issues".to_string());
constitution_manager.update_constitution("review-session", "Verify error handling".to_string());
Troubleshootingβ
Rules not being appliedβ
- Verify the session ID matches the one used in oversight requests
- Check that rules were set before the oversight request
- Ensure the ConstitutionManager is properly initialized
Rules disappearingβ
- Rules are cleaned up after 1 hour of inactivity
- Ensure the session is still active
- Re-set rules if the session has been inactive
Too many rulesβ
- Limit is 50 rules per session
- Consolidate related rules into single entries
- Remove rules that are no longer needed