Learn how to configure the Instruction Assistance feature to automatically inject formatting and behavior instructions into agent prompts, ensuring consistent and well-formatted responses.
What You'll Accomplish
Section titled “What You'll Accomplish”By the end of this guide, you will:
- Enable instruction assistance at site and chat app levels
- Use instruction placeholders in agent prompts
- Integrate tag-based formatting instructions
- Configure component-specific instructions
- Understand the instruction hierarchy
- Debug instruction injection
Prerequisites
Section titled “Prerequisites”- A running Pika installation
- Access to
pika-config.tsfor configuration - Understanding of agent instruction structure
- Familiarity with custom message tags (if using tag instructions)
Understanding Instruction Assistance
Section titled “Understanding Instruction Assistance”Instruction Assistance automatically injects pre-defined formatting and behavior instructions into agent prompts at runtime, eliminating duplication and ensuring consistency.
Why Use Instruction Assistance?
Section titled “Why Use Instruction Assistance?”Without Instruction Assistance:
// Instructions duplicated across multiple agentsconst agent1 = { instructions: ` You are a helpful assistant.
IMPORTANT FORMATTING RULES: - Use <insight> tags for key takeaways - Format code in proper markdown - Use <chart> for data visualization // ... 50 lines of formatting rules `};
const agent2 = { instructions: ` You are a data analyst.
IMPORTANT FORMATTING RULES: - Use <insight> tags for key takeaways - Format code in proper markdown - Use <chart> for data visualization // ... same 50 lines duplicated! `};With Instruction Assistance:
// Instructions defined once, injected automaticallyconst agent1 = { instructions: ` You are a helpful assistant. {formatting-instructions} `};
const agent2 = { instructions: ` You are a data analyst. {formatting-instructions} `};
// Formatting rules defined centrally in pika-config.tsKey Benefits
Section titled “Key Benefits”- Consistency: All agents use same formatting rules
- Maintainability: Update instructions in one place
- Reusability: Share instruction sets across agents
- Flexibility: Different instruction sets for different chat apps
- Scalability: Add new agents without duplicating instructions
Step 1: Enable Instruction Assistance
Section titled “Step 1: Enable Instruction Assistance”Configure the feature in your pika-config.ts.
Location: apps/pika-chat/pika-config.ts
export const pikaConfig: PikaConfig = { siteFeatures: { instructionAssistance: { enabled: true, instructions: { 'formatting-instructions': { content: `## Response Formatting Guidelines
- Use <insight> tags to highlight key takeaways- Use <chart> tags with proper JSON for data visualization- Format code blocks with language identifiers- Use bullet points for lists- Keep paragraphs concise and scannable `.trim() }, 'data-guidelines': { content: `## Data Handling
- Always cite data sources- Use appropriate precision for numbers- Validate calculations before presenting- Provide context for statistics `.trim() } } } }};Step 2: Use Placeholders in Agent Instructions
Section titled “Step 2: Use Placeholders in Agent Instructions”Reference instruction assistance in your agent prompts.
Basic Placeholder Usage
Section titled “Basic Placeholder Usage”const chatApp: ChatApp = { chatAppId: 'data-analyst', title: 'Data Analyst', instructions: `You are an expert data analyst helping users understand their data.
{formatting-instructions}
{data-guidelines}
Always provide clear explanations and actionable insights. `.trim(), // ... other properties};Placeholder Replacement
Section titled “Placeholder Replacement”At runtime, placeholders are replaced:
Before (what you write):
You are an expert data analyst.{formatting-instructions}After (what agent receives):
You are an expert data analyst.
## Response Formatting Guidelines
- Use <insight> tags to highlight key takeaways- Use <chart> tags with proper JSON for data visualization...Step 3: Override Instructions Per Chat App
Section titled “Step 3: Override Instructions Per Chat App”Chat apps can override site-level instructions.
const specialChatApp: ChatApp = { chatAppId: 'executive-reports', title: 'Executive Reports', instructions: `You create executive-level reports.{formatting-instructions}{executive-guidelines} `.trim(), features: { instructionAssistance: { featureId: 'instructionAssistance', enabled: true, instructions: { // Override site-level formatting 'formatting-instructions': { content: `## Executive Formatting
- Use executive summaries- Focus on business impact- Minimize technical jargon- Include clear recommendations `.trim() }, // Add new instruction set 'executive-guidelines': { content: `## Executive Communication
- Start with bottom line- Use metrics that matter to leadership- Provide context for decisions `.trim() } } } }};Step 4: Integrate Tag Instructions (Optional)
Section titled “Step 4: Integrate Tag Instructions (Optional)”Automatically inject instructions for custom message tags.
Define Tag Instructions
Section titled “Define Tag Instructions”Location: apps/pika-chat/pika-config.ts
export const pikaConfig: PikaConfig = { siteFeatures: { tags: { customTags: [ { tagName: 'insight', displayName: 'Key Insight', icon: 'lightbulb', description: 'Highlight important takeaways', // Instruction for agents instructionForAgent: `Use <insight> tags to highlight key takeaways or important points:
<insight type="caution">This is a critical consideration</insight><insight type="success">This is a positive outcome</insight>
Available types: success, warning, info, error `.trim() }, { tagName: 'chart', displayName: 'Data Visualization', instructionForAgent: `Use <chart> tags for data visualization with this JSON structure:
<chart>{ "type": "line", "data": { "labels": ["Jan", "Feb", "Mar"], "datasets": [{ "label": "Revenue", "data": [100, 150, 200] }] }}</chart>
Supported types: line, bar, pie, scatter `.trim() } ] }, instructionAssistance: { enabled: true, // Tag instructions automatically added as placeholders } }};Use Tag Instructions in Agent Prompts
Section titled “Use Tag Instructions in Agent Prompts”const chatApp: ChatApp = { chatAppId: 'analytics', title: 'Analytics Assistant', instructions: `You help users analyze data and create visualizations.
{formatting-instructions}{tag:insight}{tag:chart}
Always provide clear insights and helpful visualizations. `.trim()};The {tag:tagName} placeholder is automatically replaced with the tag's instructionForAgent content.
Step 5: Configure Component Instructions (Optional)
Section titled “Step 5: Configure Component Instructions (Optional)”Automatically inject instructions for custom web components.
Define Component Instructions
Section titled “Define Component Instructions”Location: apps/pika-chat/pika-config.ts
export const pikaConfig: PikaConfig = { siteFeatures: { customComponents: [ { componentName: 'data-table', displayName: 'Data Table', module: 'custom-widgets', instructionForAgent: `Use the data-table component to display tabular data:
<data-table data='[ {"name": "John", "age": 30, "city": "NYC"}, {"name": "Jane", "age": 25, "city": "LA"}]' />
The component automatically formats the table with sorting and filtering. `.trim() } ], instructionAssistance: { enabled: true } }};Use Component Instructions
Section titled “Use Component Instructions”const chatApp: ChatApp = { chatAppId: 'data-reports', title: 'Data Reports', instructions: `You create data reports with tables and charts.
{component:data-table}{component:chart-widget}
Format data appropriately for each component. `.trim()};Configuration Hierarchy
Section titled “Configuration Hierarchy”Instructions are resolved in this order:
- Chat App Override - Highest precedence
- Site-Level Instructions - Default baseline
- Tag Instructions - From custom tags configuration
- Component Instructions - From custom components configuration
// Resolution examplechatApp.instructions: "{formatting-instructions}"
// 1. Check chat app overridechatApp.features.instructionAssistance.instructions['formatting-instructions'] ↓ If not found...
// 2. Check site-levelpikaConfig.siteFeatures.instructionAssistance.instructions['formatting-instructions'] ↓ If not found...
// 3. Check if it's a tag instruction: {tag:insight}pikaConfig.siteFeatures.tags.customTags.find(t => t.tagName === 'insight').instructionForAgent ↓ If not found...
// 4. Check if it's a component: {component:data-table}pikaConfig.siteFeatures.customComponents.find(c => c.componentName === 'data-table').instructionForAgent ↓ If not found...
// 5. Leave placeholder as-is (agent sees literal "{formatting-instructions}")Testing Checklist
Section titled “Testing Checklist”Verify instruction assistance works correctly:
Debugging
Section titled “Debugging”View Resolved Instructions
Section titled “View Resolved Instructions”Enable debug logging to see final instructions sent to agents:
// In your configurationexport const pikaConfig: PikaConfig = { // ... other config debug: { logResolvedInstructions: true }};Check CloudWatch logs:
[InstructionAssistance] Resolved instructions for chat app 'analytics':You help users analyze data and create visualizations.
## Response Formatting Guidelines- Use <insight> tags to highlight key takeaways...Common Issues
Section titled “Common Issues”Issue: Placeholder not replaced
- Verify placeholder name matches instruction key exactly
- Check instruction is defined at site or chat app level
- Review tag/component configuration if using tag/component instructions
- Look for typos in placeholder syntax:
{instruction-name}
Issue: Instructions not appearing in responses
- Confirm agent is receiving instructions (check logs)
- Verify agent model follows instructions (some models ignore formatting rules)
- Test with simpler instructions to isolate issue
- Check if instructions are too long (token limits)
Issue: Chat app override not working
- Verify
featureId: 'instructionAssistance'is correct - Confirm override is complete (enabled + instructions)
- Check chat app is using overridden instruction key
- Review configuration hierarchy
Advanced Patterns
Section titled “Advanced Patterns”Conditional Instructions
Section titled “Conditional Instructions”// Different instructions based on user typeexport function getInstructionAssistance(user: AuthenticatedUser): InstructionAssistance { const baseInstructions = { 'formatting-instructions': { content: '...' } };
if (user.userType === 'internal-user') { return { enabled: true, instructions: { ...baseInstructions, 'internal-guidelines': { content: 'Internal-only instructions...' } } }; }
return { enabled: true, instructions: baseInstructions };}Modular Instruction Sets
Section titled “Modular Instruction Sets”// Define reusable instruction modulesconst formattingModule = { 'formatting-instructions': { content: '...' }};
const dataModule = { 'data-guidelines': { content: '...' }, 'statistics-rules': { content: '...' }};
const executiveModule = { 'executive-guidelines': { content: '...' }};
// Compose for different chat appsconst dataChatApp: ChatApp = { // ... features: { instructionAssistance: { featureId: 'instructionAssistance', enabled: true, instructions: { ...formattingModule, ...dataModule } } }};
const executiveChatApp: ChatApp = { // ... features: { instructionAssistance: { featureId: 'instructionAssistance', enabled: true, instructions: { ...formattingModule, ...executiveModule } } }};Version Management
Section titled “Version Management”// Track instruction versions for A/B testingconst instructionSets = { v1: { 'formatting-instructions': { content: 'Original instructions...' } }, v2: { 'formatting-instructions': { content: 'Improved instructions...' } }};
// Use environment or feature flag to select versionconst currentVersion = process.env.INSTRUCTION_VERSION || 'v1';
export const pikaConfig: PikaConfig = { siteFeatures: { instructionAssistance: { enabled: true, instructions: instructionSets[currentVersion] } }};Best Practices
Section titled “Best Practices”Instruction Design
Section titled “Instruction Design”- Be specific: Clear, actionable instructions work best
- Use examples: Show agents what good output looks like
- Keep focused: Each instruction set should have a clear purpose
- Test iteratively: Refine based on agent responses
- Version control: Track changes to instructions over time
Placeholder Naming
Section titled “Placeholder Naming”- Descriptive names:
formatting-instructionsnotfi - Consistent convention: Use kebab-case throughout
- Logical grouping: Group related instructions with prefixes
- Avoid conflicts: Don't reuse names across different instruction types
Performance Considerations
Section titled “Performance Considerations”- Token usage: Instructions consume prompt tokens
- Instruction length: Keep instructions concise
- Selective injection: Only inject what agents need
- Monitor costs: Track token usage with and without assistance
Next Steps
Section titled “Next Steps”- Use Custom Message Tags - Define custom tags
- Build Custom Web Components - Create custom components
- Implement Instruction Augmentation - Advanced instruction techniques
Related Documentation
Section titled “Related Documentation”- Instruction Assistance Capability - Learn more
- Agent Configuration Reference - Complete agent options
- Custom Tags - Tag configuration guide