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#![deny(unsafe_code)]
67
68// ── Modules ──────────────────────────────────────────────────────────
69
70pub mod channel;
71pub mod character;
72pub mod context_trimmer;
73pub mod error;
74pub mod error_classifier;
75pub mod instrumenter;
76pub mod journal;
77pub mod native;
78pub mod ports;
79pub mod resilience;
80pub mod secrets;
81pub mod tape;
82pub mod tool_policy;
83pub mod typed_tool;
84pub mod types;
85
86// ── Re-exports ───────────────────────────────────────────────────────
87
88pub use character::Character;
89pub use error::{AgentError, CostError, LlmError, StoreError, ToolError};
90pub use error_classifier::{
91    FailoverConfig, FailoverResult, classify_agent_error, classify_llm_error,
92};
93pub use instrumenter::{
94    Instrumenter, ModelErrorInfo, ModelRequestInfo, ModelResponseInfo, NoopInstrumenter,
95    OutputValidationErrorInfo, RunEndInfo, RunErrorInfo, RunStartInfo, ToolCallInfo,
96    ToolDiscoveredInfo, ToolEndInfo, ToolErrorInfo,
97};
98pub use journal::{JournalEntry, ToolJournalPort};
99pub use native::{NativeLlmPort, NativeSessionStore, NativeToolPort};
100pub use ports::{
101    AccessControlPort, ActivityJournalPort, ApprovalPort, ArtifactStorePort, CostMeterPort,
102    EventSink, LlmPort, MessageBusPort, SessionStore, SubagentPort, TapeStorePort, ToolCatalogPort,
103    ToolExecutorPort, ToolPolicyPort, ToolPort, TurnCheckpointStorePort,
104};
105pub use resilience::{
106    CircuitBreaker, CircuitBreakerConfig, CircuitBreakerError, CircuitState, ComponentHealth,
107    HealthStatus, RetryConfig,
108};
109pub use tool_policy::{
110    intersect_allowlists, is_tool_allowed, merge_allowlists, normalize_tool_list, tools_match,
111};
112pub use typed_tool::{
113    ChainedToolPorts, Complete, Described, FilteredToolPort, Incomplete, ToolKind, ToolPortExt,
114    ToolSource, TypedToolAdapter, TypedToolBuilder, TypedToolExt, TypedToolPort,
115};
116pub use types::*;