Message Processing Flow - Detailed Breakdown
This document provides a step-by-step breakdown of how messages flow through the plugin-bootstrap system.Complete Message Flow Diagram
Detailed Step Descriptions
1. Initial Message Reception
2. Self-Check
3. Response ID Generation
4. Run Tracking
5. Memory Storage
6. Attachment Processing
7. Agent State Check
8. Should Respond Evaluation
Bypass Conditions
LLM Evaluation
9. Response Generation
State Composition with Providers
LLM Response
10. Response Validation
11. Action Processing
Simple Response
Complex Response
12. Evaluator Execution
Reflection Evaluator
Key Decision Points
1. Should Respond Decision Tree
2. Response Type Decision
3. Evaluator Trigger Conditions
Performance Optimizations
1. Response ID Tracking
- Prevents duplicate responses when multiple messages arrive quickly
- Only processes the latest message per room
2. Parallel Operations
3. Timeout Protection
Error Handling
1. Run Lifecycle Events
2. Graceful Degradation
- Missing attachments → Continue without them
- Provider errors → Use default values
- LLM failures → Retry with backoff
- Database errors → Log and continue
Platform-Specific Handling
Discord
- Channels → Rooms with ChannelType
- Servers → Worlds
- Users → Entities
Telegram
- Chats → Rooms
- Groups → Worlds
- Users → Entities
Message Bus
- Topics → Rooms
- Namespaces → Worlds
- Publishers → Entities
Summary
The message flow through plugin-bootstrap is designed to be:- Platform-agnostic - Works with any message source
- Intelligent - Makes context-aware response decisions
- Extensible - Supports custom actions, providers, evaluators
- Resilient - Handles errors gracefully
- Performant - Uses parallel operations and caching
Template Usage in Message Flow
Understanding where templates are used helps you customize the right parts of the flow:1. shouldRespondTemplate - Decision Point
Used at step 8 in the flow when evaluating whether to respond:- When your agent engages in conversations
- What triggers a response
- When to stay silent
2. messageHandlerTemplate - Response Generation
Used at step 9 when generating the actual response:- How responses are formulated
- Which actions are selected
- The agent’s personality and tone
- Which providers to use for context
3. reflectionTemplate - Post-Interaction Analysis
Used at step 12 during evaluator execution:- What the agent learns from interactions
- How facts are extracted
- Relationship tracking logic
- Self-improvement mechanisms
4. postCreationTemplate - Social Media Posts
Used when POST_GENERATED event is triggered:- Post style and tone
- Content generation approach
- Image prompt generation
Template Processing Pipeline
- Template Selection: System picks the appropriate template
- Variable Replacement:
{{agentName}}
,{{providers}}
, etc. are replaced - Provider Injection: Provider data is formatted and inserted
- Prompt Assembly: Complete prompt is constructed
- LLM Processing: Sent to language model
- Response Parsing: XML/JSON response is parsed
- Execution: Actions are executed, callbacks are called
Customization Impact
When you customize templates, you’re modifying these key decision points:- shouldRespond: Change engagement patterns
- messageHandler: Alter personality and response style
- reflection: Modify learning and memory formation
- postCreation: Adjust social media presence