Advanced Patterns
This chapter collects practical patterns using the core library APIs.
1) Shared Tools Across Agents
Use SharedTool or shared_tools_to_boxes to reuse Arc<dyn ToolT> across many agents without cloning tool instances.
2) Memory Strategies
- Start with
SlidingWindowMemoryfor compact histories. - Persist memory using your own storage if you want durable conversations.
- Mix recalled messages from memory with system instructions in
Context.
3) Streaming UI Integration
- Prefer
execute_streamand consume stream items directly. - Subscribe to protocol
Events for fine-grained updates likeTurnStarted,ToolCallRequested, andStreamChunk.
4) Multi-Agent Topologies (Pub/Sub)
- Use
Topic<M>to broadcast tasks to a group of actor agents. - Combine with
Environment+Runtimeto route events and messages.