Skip to main content

bob_core/
lib.rs

1//! # Bob Core
2//!
3//! Domain types and port traits for the [Bob Agent Framework](https://github.com/longcipher/bob).
4//!
5//! ## Overview
6//!
7//! This crate defines the hexagonal boundary of the Bob Agent Framework using the
8//! ports and adapters (hexagonal) architecture pattern. It contains:
9//!
10//! - **Domain Types**: Core data structures used throughout the framework
11//! - **Port Traits**: Abstract interfaces that adapters must implement
12//! - **Error Types**: Comprehensive error definitions for all components
13//!
14//! **No concrete implementations live here** — only contracts.
15//!
16//! ## Architecture
17//!
18//! The crate defines four primary port traits:
19//!
20//! 1. [`ports::LlmPort`] - Interface for language model interactions
21//! 2. [`ports::ToolPort`] - Interface for tool/system operations
22//! 3. [`ports::SessionStore`] - Interface for session state persistence
23//! 4. [`ports::EventSink`] - Interface for event observation and logging
24//!
25//! ## Example
26//!
27//! ```rust,ignore
28//! use bob_core::{
29//!     ports::LlmPort,
30//!     types::{LlmRequest, LlmResponse},
31//!     error::LlmError,
32//! };
33//! use async_trait::async_trait;
34//!
35//! struct MyCustomLlm;
36//!
37//! #[async_trait]
38//! impl LlmPort for MyCustomLlm {
39//!     async fn complete(&self, req: LlmRequest) -> Result<LlmResponse, LlmError> {
40//!         // Your implementation here
41//!         todo!("implement LLM completion")
42//!     }
43//!
44//!     async fn complete_stream(&self, req: LlmRequest) -> Result<LlmStream, LlmError> {
45//!         // Your implementation here
46//!         todo!("implement streaming completion")
47//!     }
48//! }
49//! ```
50//!
51//! ## Features
52//!
53//! - **Zero-cost abstractions**: All traits use `async_trait` for async support
54//! - **Type-safe**: Strong typing throughout with comprehensive error handling
55//! - **Serializable**: All domain types implement `serde::Serialize` and `Deserialize`
56//! - **Thread-safe**: All traits require `Send + Sync`
57//!
58//! ## Related Crates
59//!
60//! - [`bob_runtime`] - Runtime orchestration layer
61//! - [`bob_adapters`] - Concrete adapter implementations
62//!
63//! [`bob_runtime`]: https://docs.rs/bob-runtime
64//! [`bob_adapters`]: https://docs.rs/bob-adapters
65
66// ── Modules ──────────────────────────────────────────────────────────
67
68pub mod error;
69pub mod ports;
70pub mod tool_policy;
71pub mod types;
72
73// ── Re-exports ───────────────────────────────────────────────────────
74
75pub use error::{AgentError, CostError, LlmError, StoreError, ToolError};
76pub use ports::{
77    ApprovalPort, ArtifactStorePort, CostMeterPort, EventSink, LlmPort, SessionStore,
78    ToolCatalogPort, ToolExecutorPort, ToolPolicyPort, ToolPort, TurnCheckpointStorePort,
79};
80pub use tool_policy::{
81    intersect_allowlists, is_tool_allowed, merge_allowlists, normalize_tool_list, tools_match,
82};
83pub use types::*;