# BedRock Module API Documentation
Version: 3.0.0
The BedRock module reduces problems to fundamental axioms through recursive analysis,
then rebuilds understanding using Tree-of-Thoughts exploration.
## Table of Contents
1. [Module Overview](#module-overview)
2. [Configuration](#configuration)
3. [Core Types](#core-types)
4. [Methods](#methods)
5. [Usage Examples](#usage-examples)
6. [Error Handling](#error-handling)
## Module Overview
BedRock applies Elon Musk-style first principles thinking to decompose complex
problems into fundamental components, identify axiomatic truths, surface hidden
assumptions, and reconstruct understanding from verified foundations.
Key capabilities:
- Recursive problem decomposition to fundamental principles
- Axiom identification with confidence scoring
- Hidden assumption exposure and analysis
- Tree-of-Thoughts exploration for optimal reasoning paths
- Confidence-weighted reconstruction from fundamentals
## Configuration
### BedRockConfig
Configuration struct controlling BedRock analysis depth and behavior.
```rust
pub struct BedRockConfig {
pub max_depth: usize,
pub axiom_threshold: f64,
pub branching_factor: usize,
pub min_confidence: f64,
pub strict_assumptions: bool,
pub max_principles: usize,
}
```
#### Fields
| `max_depth` | `usize` | Yes | `3` | Maximum decomposition depth. Controls recursion depth. |
| `axiom_threshold` | `f64` | Yes | `0.85` | Minimum fundamentality score for axioms. Range: 0.0-1.0. |
| `branching_factor` | `usize` | Yes | `3` | Parallel thought branches per principle. Enables exploration. |
| `min_confidence` | `f64` | Yes | `0.5` | Minimum confidence threshold for principles. Range: 0.0-1.0. |
| `strict_assumptions` | `bool` | Yes | `true` | Require all assumptions to be explicitly stated. Ensures completeness. |
| `max_principles` | `usize` | Yes | `20` | Maximum principles to identify. Prevents combinatorial explosion. |
#### Implementation
```rust
impl Default for BedRockConfig {
fn default() -> Self {
Self {
max_depth: 3,
axiom_threshold: 0.85,
branching_factor: 3,
min_confidence: 0.5,
strict_assumptions: true,
max_principles: 20,
}
}
}
impl BedRockConfig {
/// Fast decomposition mode - shallow analysis
pub fn fast() -> Self {
Self {
max_depth: 2,
axiom_threshold: 0.7,
branching_factor: 2,
min_confidence: 0.4,
strict_assumptions: false,
max_principles: 10,
}
}
/// Deep analysis mode - comprehensive decomposition
pub fn deep() -> Self {
Self {
max_depth: 5,
axiom_threshold: 0.9,
branching_factor: 5,
min_confidence: 0.6,
strict_assumptions: true,
max_principles: 30,
}
}
}
```
## Core Types
### BedRock
Main module struct implementing the ThinkToolModule trait.
```rust
pub struct BedRock {
config: ThinkToolModuleConfig,
bedrock_config: BedRockConfig,
}
```
#### Fields
| `config` | `ThinkToolModuleConfig` | Standard module configuration metadata |
| `bedrock_config` | `BedRockConfig` | BedRock-specific configuration parameters |
### BedRockResult
Structured output from BedRock execution containing decomposition analysis.
```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BedRockResult {
pub principles: Vec<Principle>,
pub axioms: Vec<Principle>,
pub assumptions: Vec<Principle>,
pub reconstruction: String,
pub confidence: f64,
pub decomposition_tree: Option<DecompositionNode>,
pub exploration_paths: Vec<ExplorationPath>,
}
```
#### Fields
| `principles` | `Vec<Principle>` | Identified fundamental principles |
| `axioms` | `Vec<Principle>` | Verified axiomatic principles |
| `assumptions` | `Vec<Principle>` | Exposed assumptions |
| `reconstruction` | `String` | Rebuilt understanding from fundamentals |
| `confidence` | `f64` | Overall confidence in decomposition |
| `decomposition_tree` | `Option<DecompositionNode>` | Hierarchical decomposition structure |
| `exploration_paths` | `Vec<ExplorationPath>` | Tree-of-Thoughts exploration paths |
### Principle
Fundamental principle identified during decomposition.
```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Principle {
pub id: usize,
pub statement: String,
pub r#type: PrincipleType,
pub confidence: f64,
pub dependencies: Vec<usize>,
pub evidence: String,
pub challenges: Vec<String>,
pub reliability_weight: f64,
pub depth: usize,
}
```
#### Fields
| `id` | `usize` | Unique identifier within this analysis |
| `statement` | `String` | The principle statement |
| `type` | `PrincipleType` | Classification of principle |
| `confidence` | `f64` | Confidence in principle accuracy |
| `dependencies` | `Vec<usize>` | IDs of dependent principles |
| `evidence` | `String` | Supporting evidence |
| `challenges` | `Vec<String>` | Potential counter-arguments |
| `reliability_weight` | `f64` | Weight based on principle type |
| `depth` | `usize` | Decomposition depth level |
### PrincipleType
Classification of principle nature affecting reliability.
```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PrincipleType {
Axiom, // Self-evident truth requiring no proof
Derived, // Logically derived from axioms
Assumption, // Assumed for the sake of argument
Empirical, // Based on empirical observation/data
Definition, // Definitional statement clarifying terminology
Contested, // Claim requiring verification
}
```
#### Reliability Weights
| `Axiom` | 1.0 | Highest reliability |
| `Definition` | 0.95 | Very high reliability |
| `Empirical` | 0.80 | High reliability |
| `Derived` | 0.75 | Moderate reliability |
| `Assumption` | 0.50 | Low reliability |
| `Contested` | 0.30 | Lowest reliability |
### DecompositionNode
Node in the hierarchical decomposition tree.
```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DecompositionNode {
pub principle_id: usize,
pub children: Vec<DecompositionNode>,
pub level: usize,
pub exploration_score: f64,
}
```
#### Fields
| `principle_id` | `usize` | ID of principle at this node |
| `children` | `Vec<DecompositionNode>` | Child decomposition nodes |
| `level` | `usize` | Depth level in decomposition |
| `exploration_score` | `f64` | Score for Tree-of-Thoughts exploration |
### ExplorationPath
Path explored during Tree-of-Thoughts analysis.
```rust
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExplorationPath {
pub path_id: usize,
pub principles: Vec<usize>,
pub confidence_trajectory: Vec<f64>,
pub exploration_score: f64,
pub optimal: bool,
}
```
#### Fields
| `path_id` | `usize` | Unique identifier for this path |
| `principles` | `Vec<usize>` | Principle IDs in exploration order |
| `confidence_trajectory` | `Vec<f64>` | Confidence evolution along path |
| `exploration_score` | `f64` | Overall path quality score |
| `optimal` | `bool` | Whether this is an optimal path |
## Methods
### BedRock::new()
Create a new BedRock module with default configuration.
```rust
pub fn new() -> Self
```
Returns: `BedRock` instance with default settings.
Example:
```rust
let module = BedRock::new();
assert_eq!(module.name(), "BedRock");
assert_eq!(module.version(), "3.0.0");
```
### BedRock::with_config()
Create a new BedRock module with custom configuration.
```rust
pub fn with_config(config: BedRockConfig) -> Self
```
Parameters:
- `config`: `BedRockConfig` - Custom configuration parameters
Returns: `BedRock` instance with specified configuration.
Example:
```rust
let config = BedRockConfig::deep();
let module = BedRock::with_config(config);
```
### BedRock::decompose()
Direct decomposition of a problem statement.
```rust
pub fn decompose(&self, problem: &str) -> Result<BedRockResult>
```
Parameters:
- `problem`: `&str` - Problem statement to decompose
Returns: `Result<BedRockResult>` - Decomposition results or error.
Example:
```rust
let module = BedRock::new();
let result = module.decompose("Why are electric vehicles better than gas cars?")?;
```
### BedRock::execute()
Execute the BedRock module synchronously.
```rust
impl ThinkToolModule for BedRock {
fn execute(&self, context: &ThinkToolContext) -> Result<ThinkToolOutput>
}
```
Parameters:
- `context`: `&ThinkToolContext` - Execution context with problem statement
Returns: `Result<ThinkToolOutput>` - Structured output or error.
Example:
```rust
let module = BedRock::new();
let context = ThinkToolContext::new("Analyze the root causes of climate change");
let result = module.execute(&context)?;
```
### BedRock::config()
Get the module configuration.
```rust
pub fn config(&self) -> &BedRockConfig
```
Returns: `&BedRockConfig` - Reference to current configuration.
Example:
```rust
let module = BedRock::new();
let config = module.config();
assert_eq!(config.max_depth, 3);
```
## Usage Examples
### Basic Decomposition
```rust
use reasonkit::thinktool::modules::{BedRock, ThinkToolContext, ThinkToolModule};
// Create module with default settings
let module = BedRock::new();
// Direct decomposition
let result = module.decompose("Why do startups fail?")?;
// Access identified axioms
let axioms = &result.axioms;
println!("Found {} axiomatic principles:", axioms.len());
for axiom in axioms {
println!("- {} (confidence: {:.2})", axiom.statement, axiom.confidence);
}
// Access exposed assumptions
let assumptions = &result.assumptions;
println!("\nExposed {} assumptions:", assumptions.len());
for assumption in assumptions {
println!("- {} (challenges: {:?})", assumption.statement, assumption.challenges);
}
```
### Context-Based Execution
```rust
use reasonkit::thinktool::modules::{BedRock, ThinkToolContext, ThinkToolModule};
// Create module with custom configuration
let module = BedRock::with_config(
BedRockConfig {
max_depth: 4,
axiom_threshold: 0.9,
..Default::default()
}
);
// Prepare context
let context = ThinkToolContext::new("What are the fundamental barriers to fusion power?");
// Execute decomposition
let result = module.execute(&context)?;
// Access reconstruction
let reconstruction = result.get_str("reconstruction").unwrap();
println!("Reconstructed understanding:\n{}", reconstruction);
// Access decomposition tree
if let Some(tree) = result.get("decomposition_tree") {
println!("Hierarchical decomposition completed");
}
```
### Deep Analysis Configuration
```rust
use reasonkit::thinktool::modules::{BedRock, BedRockConfig, ThinkToolContext};
// Configure for comprehensive decomposition
let config = BedRockConfig::deep();
let module = BedRock::with_config(config);
// Complex problem analysis
let context = ThinkToolContext::new(
"Analyze the fundamental economic principles underlying cryptocurrency valuation"
);
let result = module.execute(&context)?;
// Access exploration paths
let paths = result.get_array("exploration_paths").unwrap();
println!("Explored {} reasoning paths", paths.len());
// Find optimal path
for path in paths {
let optimal = path.get("optimal").and_then(|v| v.as_bool()).unwrap_or(false);
if optimal {
println!("Found optimal reasoning path");
break;
}
}
```
## Error Handling
BedRock defines specific error types for decomposition failures:
### BedRockError
Enumeration of all possible module-specific errors.
```rust
#[derive(Error, Debug, Clone)]
pub enum BedRockError {
DecompositionFailed { reason: String },
AxiomIdentificationFailed { reason: String },
CircularDependency { principles: Vec<usize> },
ReconstructionFailed { reason: String },
TreeExplorationTimeout { duration_ms: u64 },
PrincipleLimitExceeded { count: usize, max: usize },
}
```
### Error Descriptions
| `DecompositionFailed` | `reason` | Unable to decompose the problem |
| `AxiomIdentificationFailed` | `reason` | Could not identify fundamental axioms |
| `CircularDependency` | `principles` | Found circular reasoning in principles |
| `ReconstructionFailed` | `reason` | Unable to rebuild from fundamentals |
| `TreeExplorationTimeout` | `duration_ms` | Tree-of-Thoughts exploration timed out |
| `PrincipleLimitExceeded` | `count`, `max` | Exceeded maximum principle limit |
### Error Conversion
All BedRockError variants are automatically converted to the standard Error type:
```rust
impl From<BedRockError> for Error {
fn from(err: BedRockError) -> Self {
Error::ThinkToolExecutionError(err.to_string())
}
}
```
### Handling Errors
```rust
use reasonkit::thinktool::modules::{BedRock, ThinkToolContext, BedRockError};
let module = BedRock::new();
let context = ThinkToolContext::new("Complex philosophical question");
match module.execute(&context) {
Ok(result) => {
// Process successful result
println!("Decomposition completed with confidence: {}", result.confidence);
}
Err(e) => {
// Handle specific BedRock errors
if let Some(br_err) = e.downcast_ref::<BedRockError>() {
match br_err {
BedRockError::DecompositionFailed { reason } => {
eprintln!("Decomposition failed: {}", reason);
}
BedRockError::TreeExplorationTimeout { duration_ms } => {
eprintln!("Exploration timed out after {}ms", duration_ms);
}
BedRockError::CircularDependency { principles } => {
eprintln!("Circular dependency in principles: {:?}", principles);
}
_ => eprintln!("BedRock error: {}", br_err),
}
} else {
// Handle other errors
eprintln!("Other error: {}", e);
}
}
}
```
## Performance Considerations
1. **Decomposition Depth**: Control `max_depth` to manage recursion complexity
2. **Branching Factor**: Adjust `branching_factor` for exploration breadth vs. speed
3. **Principle Limit**: Set `max_principles` to prevent combinatorial explosion
4. **Axiom Threshold**: Tune `axiom_threshold` for desired fundamentality rigor
5. **Strict Assumptions**: Disable for faster execution when completeness is less critical
## Integration Notes
When using BedRock in protocol execution:
```rust
use reasonkit::thinktool::{ProtocolExecutor, ProtocolInput};
// ProtocolExecutor handles LLM integration automatically
let executor = ProtocolExecutor::new()?;
let result = executor.execute(
"bedrock",
ProtocolInput::query("Fundamental question about reality")
).await?;
```
The protocol-based approach provides:
- Automatic LLM selection for complex decomposition tasks
- Streaming output for real-time progress monitoring
- Built-in retry logic for failed decomposition steps
- Comprehensive execution tracing and audit capabilities