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