Why Traits?
The trait-based design provides several key benefits:Modularity
Modularity
Each component is self-contained and can be developed, tested, and deployed independently.
Extensibility
Extensibility
Add new providers, tools, or channels without modifying core code.
Type Safety
Type Safety
Rust’s type system ensures implementations meet contracts at compile time.
Testability
Testability
Mock implementations make testing straightforward.
Performance
Performance
Zero-cost abstractions with static dispatch where possible.
Core Traits
Corvus defines six primary traits that form the extension surface:Provider Trait
The Provider trait abstracts LLM API interactions. Location:clients/agent-runtime/src/providers/traits.rs
Channel Trait
The Channel trait abstracts messaging platform interactions. Location:clients/agent-runtime/src/channels/traits.rs
Tool Trait
The Tool trait defines agent capabilities. Location:clients/agent-runtime/src/tools/traits.rs
Memory Trait
The Memory trait abstracts persistence backends. Location:clients/agent-runtime/src/memory/traits.rs
RuntimeAdapter Trait
The RuntimeAdapter trait abstracts execution environments. Location:clients/agent-runtime/src/runtime/traits.rs
Observer Trait
The Observer trait enables observability and monitoring. Location:clients/agent-runtime/src/observability/traits.rs
Factory Pattern
Corvus uses factory functions to construct trait implementations from configuration:Best Practices
When implementing Corvus traits:Do:
- Use
async_traitfor async trait methods - Return
anyhow::Resultfor fallible operations - Implement
Send + Syncfor thread safety - Provide default implementations where sensible
- Validate inputs early and return descriptive errors
- Use structured logging (not println!)
- Panic in trait implementations
- Block the async runtime with synchronous I/O
- Log sensitive data (credentials, tokens)
- Ignore error handling
- Make blocking HTTP calls without timeouts
Testing Traits
Mock implementations make testing straightforward:Next Steps
Architecture Overview
See how traits fit into the system
Building Custom Providers
Implement your own LLM provider
Creating Tools
Extend agent capabilities
Runtime Model
Understand execution environments