Rust API
Native Rust integration for maximum performance.
Installation
Add to your Cargo.toml:
[dependencies]
reasonkit = "0.1"
tokio = { version = "1", features = ["full"] }
Quick Start
use reasonkit::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize with API key from environment
let rk = ReasonKit::from_env()?;
// Run analysis
let result = rk
.think("Should I take this job offer?")
.profile(Profile::Balanced)
.execute()
.await?;
// Access results
println!("Synthesis: {}", result.synthesis);
Ok(())
}
ReasonKit Builder
#![allow(unused)]
fn main() {
use reasonkit::{ReasonKit, Provider, Model};
// Configure explicitly
let rk = ReasonKit::builder()
.provider(Provider::Anthropic)
.model(Model::Claude3Sonnet)
.api_key("sk-ant-...")
.timeout(Duration::from_secs(120))
.build()?;
// Or from config file
let rk = ReasonKit::from_config("~/.config/reasonkit/config.toml")?;
// Or from environment
let rk = ReasonKit::from_env()?;
}
Individual ThinkTools
GigaThink
#![allow(unused)]
fn main() {
use reasonkit::thinktools::GigaThink;
let gt = GigaThink::new()
.perspectives(15)
.include_contrarian(true);
let result = gt.analyze("Should I start a business?").await?;
for perspective in result.perspectives {
println!("{}: {}", perspective.category, perspective.content);
}
}
LaserLogic
#![allow(unused)]
fn main() {
use reasonkit::thinktools::LaserLogic;
let ll = LaserLogic::new()
.depth(Depth::Deep)
.fallacy_detection(true)
.assumption_analysis(true);
let result = ll.analyze("Renting is throwing money away").await?;
for flaw in result.flaws {
println!("FLAW: {}", flaw.claim);
println!(" Issue: {}", flaw.issue);
println!(" Evidence: {}", flaw.evidence);
}
}
BedRock
#![allow(unused)]
fn main() {
use reasonkit::thinktools::BedRock;
let br = BedRock::new()
.decomposition_depth(3)
.show_80_20(true);
let result = br.analyze("How should I think about this decision?").await?;
println!("Core question: {}", result.core_question);
println!("First principles: {:?}", result.first_principles);
println!("80/20: {}", result.eighty_twenty);
}
ProofGuard
#![allow(unused)]
fn main() {
use reasonkit::thinktools::ProofGuard;
let pg = ProofGuard::new()
.min_sources(3)
.require_citation(true)
.source_tier_threshold(SourceTier::Tier2);
let result = pg.analyze("8 glasses of water a day is necessary").await?;
println!("Verdict: {:?}", result.verdict);
for claim in result.verified {
println!("✓ {}: {}", claim.claim, claim.evidence);
}
for claim in result.unverified {
println!("? {}", claim.claim);
}
}
BrutalHonesty
#![allow(unused)]
fn main() {
use reasonkit::thinktools::BrutalHonesty;
let bh = BrutalHonesty::new()
.severity(Severity::High)
.include_alternatives(true);
let result = bh.analyze("I'm going to become a day trader").await?;
for truth in result.uncomfortable_truths {
println!("🔥 {}", truth);
}
for question in result.questions {
println!("❓ {}", question);
}
}
PowerCombo
#![allow(unused)]
fn main() {
use reasonkit::thinktools::PowerCombo;
use reasonkit::profiles::Profile;
let combo = PowerCombo::new()
.profile(Profile::Balanced);
let result = combo.analyze("Should I buy a house?").await?;
// Access individual tool results
println!("GigaThink: {} perspectives", result.gigathink.perspectives.len());
println!("LaserLogic: {} flaws", result.laserlogic.flaws.len());
println!("BedRock: {}", result.bedrock.core_question);
println!("ProofGuard: {:?}", result.proofguard.verdict);
println!("BrutalHonesty: {} truths", result.brutalhonesty.uncomfortable_truths.len());
// Or the synthesis
println!("Synthesis: {}", result.synthesis);
}
Profiles
#![allow(unused)]
fn main() {
use reasonkit::profiles::Profile;
// Built-in profiles
let profile = Profile::Quick; // Fast, 2 tools
let profile = Profile::Balanced; // Standard, 5 tools
let profile = Profile::Deep; // Thorough, 6 tools
let profile = Profile::Paranoid; // Maximum, all tools
// Custom profile
let profile = Profile::custom()
.tools(vec![Tool::GigaThink, Tool::BrutalHonesty])
.gigathink_perspectives(8)
.brutalhonesty_severity(Severity::High)
.timeout(Duration::from_secs(60))
.build();
}
Output Formats
#![allow(unused)]
fn main() {
use reasonkit::output::{Format, OutputOptions};
let result = rk.think("question")
.execute()
.await?;
// Pretty print
println!("{}", result.format(Format::Pretty));
// JSON
let json = result.format(Format::Json);
std::fs::write("analysis.json", json)?;
// Markdown
let md = result.format(Format::Markdown);
// Custom formatting
let options = OutputOptions::builder()
.include_metadata(true)
.max_length(1000)
.build();
let output = result.format_with(Format::Pretty, options);
}
Error Handling
#![allow(unused)]
fn main() {
use reasonkit::error::ReasonKitError;
match rk.think("question").execute().await {
Ok(result) => println!("{}", result.synthesis),
Err(ReasonKitError::ApiError(e)) => eprintln!("API error: {}", e),
Err(ReasonKitError::ConfigError(e)) => eprintln!("Config error: {}", e),
Err(ReasonKitError::Timeout) => eprintln!("Analysis timed out"),
Err(e) => eprintln!("Error: {}", e),
}
}
Async Streaming
#![allow(unused)]
fn main() {
use futures::StreamExt;
let mut stream = rk.think("question")
.stream()
.await?;
while let Some(chunk) = stream.next().await {
match chunk {
Ok(ToolResult::GigaThink(gt)) => {
println!("GigaThink complete: {} perspectives", gt.perspectives.len());
}
Ok(ToolResult::LaserLogic(ll)) => {
println!("LaserLogic complete: {} flaws", ll.flaws.len());
}
// ... other tools
Err(e) => eprintln!("Error: {}", e),
}
}
}
Concurrent Analysis
#![allow(unused)]
fn main() {
use futures::future::join_all;
let questions = vec![
"Should we launch feature A?",
"Should we launch feature B?",
"Should we launch feature C?",
];
let analyses: Vec<_> = questions
.iter()
.map(|q| rk.think(q).execute())
.collect();
let results = join_all(analyses).await;
for (question, result) in questions.iter().zip(results) {
match result {
Ok(r) => println!("{}: {}", question, r.synthesis),
Err(e) => eprintln!("{}: Error - {}", question, e),
}
}
}
Full Example
use reasonkit::prelude::*;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize
let rk = ReasonKit::builder()
.provider(Provider::Anthropic)
.model(Model::Claude3Sonnet)
.timeout(Duration::from_secs(300))
.from_env()?
.build()?;
// Run deep analysis
let result = rk
.think("Should I quit my job to start a business?")
.profile(Profile::Deep)
.execute()
.await?;
// Process results
println!("=== Analysis Complete ===\n");
println!("Perspectives:");
for p in &result.gigathink.perspectives {
println!(" - {}: {}", p.category, p.content);
}
println!("\nLogical Flaws:");
for f in &result.laserlogic.flaws {
println!(" - {}", f.claim);
}
println!("\nCore Question: {}", result.bedrock.core_question);
println!("\nUncomfortable Truths:");
for t in &result.brutalhonesty.uncomfortable_truths {
println!(" 🔥 {}", t);
}
println!("\n=== Synthesis ===");
println!("{}", result.synthesis);
// Export as JSON
std::fs::write(
"analysis.json",
result.format(Format::Json)
)?;
Ok(())
}