ChatPlatform trait to integrate any chat system, notification service, or automation tool.
Architecture Overview
All Magpie adapters follow this pattern:Implement ChatPlatform trait
Four required methods:
name(), fetch_history(), send_message(), and close_thread() (optional).Build PipelineConfig from environment
Read configuration from env vars (repo path, CI commands, integrations).
The ChatPlatform Trait
TheChatPlatform trait defines the contract every adapter must implement:
crates/magpie-core/src/platform.rs
Method Details
name() -> &str
Purpose: Platform identifier for logging and debugging. Examples:"discord"— Discord bot"teams"— Microsoft Teams webhook"slack"— Slack bot"cli"— Command-line interface
fetch_history(channel_id: &str) -> Result<String>
Purpose: Retrieve conversation history to provide context to the AI agent. Parameters:channel_id: Platform-specific channel/thread identifier
- Discord: Returns empty string (task is self-contained in mention)
- Teams: Returns empty string (Graph API integration not yet implemented)
- CLI: Returns empty string (no chat history)
- Multi-turn conversations where agent needs full context
- Bug reports with multiple messages of diagnostic info
- Design discussions where agent should understand full thread
send_message
Purpose: Post a message to the chat platform. Parameters:channel_id: Target channel/thread identifiertext: Message content (plain text or platform-specific formatting)
- Acknowledgment: ”⏳ Got it — working on this now…”
- Final result: PR link, CI status, error messages
close_thread
Purpose: Archive/lock a thread after pipeline completion (optional). Default behavior: No-op (returnsOk(())).
Override when:
- Platform supports thread archiving (Discord)
- You want to prevent further interaction after task completion
- Cleanup/notification is needed
Building a Custom Adapter
Let’s build a complete Slack adapter as an example.Project Structure
Cargo.toml
crates/magpie-slack/Cargo.toml
Step 1: Implement ChatPlatform
crates/magpie-slack/src/adapter.rs
Step 2: Event Handling
crates/magpie-slack/src/events.rs
Step 3: Main Entry Point
crates/magpie-slack/src/main.rs
Step 4: Configuration
.env
Step 5: Run & Test
Common Patterns
Webhook Signature Validation
Most platforms sign webhook payloads for security:OAuth Token Management
Cache tokens with expiry handling:Mention Stripping
Each platform has unique mention syntax:Error Handling
Useanyhow for flexible error propagation:
Testing Your Adapter
Unit Tests with Mock Responses
Integration Tests
Deployment
Docker
Kubernetes
Real-World Examples
The Magpie codebase includes three production adapters you can reference:Discord
Full Discord bot with Serenity, thread management, mention stripping
Teams
Azure Bot Framework webhook, OAuth2 token caching, HMAC validation
CLI
Minimal adapter for local testing, demonstrates no-op implementations
Next Steps
Core Architecture
Understand Magpie’s pipeline orchestration and agent system
Blueprint Engine
Learn how blueprints orchestrate multi-step workflows
Environment Variables
Complete reference for all configuration options
Contributing
Submit your adapter to the Magpie repository