klieo 0.41.3

Open-source Rust agent framework — typed agents, durable inter-agent comms, local-first.
Documentation
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]

//! `klieo` — open-source Rust agent framework.
//!
//! This umbrella crate re-exports [`klieo_core`] unconditionally and
//! exposes each implementation crate behind a Cargo feature flag so
//! users can start with just the trait surfaces and opt into concrete
//! implementations one at a time.
//!
//! # Quickstart
//!
//! Add to `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! klieo = { version = "0.9", features = ["all-foundation"] }
//! ```
//!
//! Then build an agent:
//!
//! ```no_run
//! use klieo::{RunOptions, Error};
//! let opts = RunOptions::default();
//! let _ = opts;
//! ```
//!
//! # Feature flags
//!
//! ## Foundation
//!
//! | Feature | Crate enabled |
//! |---------|---------------|
//! | *(none)* | `klieo-core` trait surfaces only |
//! | `tools` | `klieo-tools` — `ChainedInvoker`, schema validation |
//! | `macros` | `klieo-macros` — `#[tool]` proc-macro |
//! | `llm-ollama` | `klieo-llm-ollama` — Ollama HTTP client |
//! | `memory-sqlite` | `klieo-memory-sqlite` — SQLite-backed memory |
//! | `bus-memory` | `klieo-bus-memory` — in-process bus |
//! | `bus-nats` | `klieo-bus-nats` — NATS JetStream bus |
//! | `mcp` | `klieo-tools-mcp` — MCP adapter (implies `tools`) |
//! | `all-foundation` | All foundation features above |
//!
//! ## LLM providers
//!
//! | Feature | Crate enabled |
//! |---------|---------------|
//! | `llm-openai` | `klieo-llm-openai` |
//! | `llm-anthropic` | `klieo-llm-anthropic` |
//! | `llm-gemini` | `klieo-llm-gemini` (Google Gemini) |
//! | `all-llm` | All LLM providers (incl. Ollama) |
//!
//! ## Memory backends
//!
//! | Feature | Crate enabled |
//! |---------|---------------|
//! | `memory-neo4j` | `klieo-memory-neo4j` |
//! | `memory-qdrant` | `klieo-memory-qdrant` |
//! | `embed-common` | `klieo-embed-common` — shared `Embedder` trait |
//! | `memory-fastembed` | `memory-sqlite` + real CPU embeddings |
//! | `memory-sqlite-vec` | `memory-sqlite` + k-NN sqlite-vec index |
//! | `all-memory` | All memory backends |
//!
//! ## Composition + protocol
//!
//! | Feature | Crate enabled |
//! |---------|---------------|
//! | `flows` | `klieo-flows` — Sequential/Parallel/Loop/Graph |
//! | `a2a` | `klieo-a2a` — durable Agent-to-Agent v1.0 |
//! | `spec` | `klieo-spec` — quality-loop runner |
//!
//! ## Observability + provenance
//!
//! | Feature | Crate enabled |
//! |---------|---------------|
//! | `runlog` | `klieo-runlog` — RunLog projection + replay |
//! | `runlog-sqlite` | `runlog` + SQLite store |
//! | `runlog-compaction-llm` | `runlog` + LLM-summarise compaction |
//! | `provenance` | `klieo-provenance` — Merkle hash chain |
//! | `otel` | `klieo-otel` — OpenTelemetry OTLP exporter |
//! | `all-observability` | `runlog` + `provenance` + `otel` |
//!
//! ## Aggregates
//!
//! | Feature | Enables |
//! |---------|---------|
//! | `full` | Every impl crate — heavy build, for integration tests |
//! | `test-utils` | `klieo-core/test-utils` for downstream test deps |

// ── core ──────────────────────────────────────────────────────────────────────

/// Re-exports every public item from `klieo-core`.
pub use klieo_core::*;

/// Re-exports the runtime crates that `klieo-macros`-emitted code
/// references via absolute paths. Marked `#[doc(hidden)]`: end-user
/// code should never reference these by hand.
///
/// The `#[klieo::tool]` proc-macro emits paths like
/// `::klieo::__private::klieo_core::__macro_support::Tool`, so
/// downstream crates need only `klieo` as a direct dependency —
/// `klieo-core` is no longer required in the user's `Cargo.toml`.
#[doc(hidden)]
pub mod __private {
    pub use klieo_core;
}

/// Re-exported `klieo_core::test_utils` (in-memory fakes for the
/// memory traits, fake LLM client, fake tool invoker).
///
/// Enabled by the `test-utils` feature flag. The glob re-export
/// above transitively exposes this module, but an explicit `pub use`
/// pins the contract so future `klieo-core` reorganisations cannot
/// accidentally hide it from downstream consumers.
#[cfg(feature = "test-utils")]
pub use klieo_core::test_utils;

/// Common imports for klieo agent authors.
///
/// `use klieo::prelude::*;` brings in `Agent`, `AgentContext`,
/// `Error`, `LlmClient`, `Message`, `Role`, `RunId`, `ThreadId`,
/// `ToolDef`, `ToolInvoker`, `Tool`, `ToolCtx`, `Episode`,
/// `ToolResult`, `RunOptions`.
pub mod prelude;

/// Fluent assembler that collapses the 13-field `AgentContext` into
/// a one-call wiring surface. See [`App`] for the entry point.
pub mod app;
pub use app::{App, AppBuilder};

/// Re-exported `secrecy::SecretString`. Activated by the `secrecy`
/// feature, which `bus-nats`, `llm-anthropic`, `llm-openai`,
/// `llm-genai`, `memory-neo4j`, and `memory-qdrant` auto-enable.
///
/// Downstream consumers that interact with any klieo crate accepting
/// credentials can `use klieo::SecretString;` instead of pinning the
/// `secrecy` crate directly — preventing version skew like the
/// 0.8 ↔ 0.10 incompatibility surfaced in adoption eval Plan 02.
#[cfg(feature = "secrecy")]
pub use secrecy::SecretString;

/// Re-exported `bytes` crate. Activated by the `bytes` feature,
/// which `bus-nats` auto-enables (klieo-bus-nats's `Job` payload is
/// `bytes::Bytes`).
#[cfg(feature = "bytes")]
pub use bytes;

// ── tools ─────────────────────────────────────────────────────────────────────

/// Tool dispatch: [`tools::ChainedInvoker`], [`tools::validate_args`].
///
/// Enabled by the `tools` feature flag.
#[cfg(feature = "tools")]
pub mod tools {
    pub use klieo_tools::*;
}

// ── macros ────────────────────────────────────────────────────────────────────

/// Procedural macros: the `#[macros::tool]` attribute.
///
/// Enabled by the `macros` feature flag.
#[cfg(feature = "macros")]
pub mod macros {
    pub use klieo_macros::*;
}

/// Re-export of the [`#[tool]`][macros::tool] attribute at crate root
/// so `#[klieo::tool(...)]` works without an extra `use`. The full
/// `klieo::macros::tool` path remains valid.
#[cfg(feature = "macros")]
pub use klieo_macros::tool;

/// Re-export of the [`#[derive(KlieoResponse)]`][macros::KlieoResponse]
/// derive at crate root so `#[derive(klieo::KlieoResponse)]` works
/// without an extra `use`.
#[cfg(feature = "macros")]
pub use klieo_macros::KlieoResponse;

// ── llm ───────────────────────────────────────────────────────────────────────

/// Ollama LLM client: [`llm::OllamaClient`].
///
/// Enabled by the `llm-ollama` feature flag.
///
/// For symmetric access alongside other providers, see
/// [`llm_openai`], [`llm_anthropic`], [`llm_gemini`].
#[cfg(feature = "llm-ollama")]
pub mod llm {
    pub use klieo_llm_ollama::*;
}

/// OpenAI Chat Completions client.
///
/// Enabled by the `llm-openai` feature flag.
#[cfg(feature = "llm-openai")]
pub mod llm_openai {
    pub use klieo_llm_openai::*;
}

/// Anthropic Messages client.
///
/// Enabled by the `llm-anthropic` feature flag.
#[cfg(feature = "llm-anthropic")]
pub mod llm_anthropic {
    pub use klieo_llm_anthropic::*;
}

/// Google Gemini client.
///
/// Enabled by the `llm-gemini` feature flag.
#[cfg(feature = "llm-gemini")]
pub mod llm_gemini {
    pub use klieo_llm_gemini::*;
}

// ── memory ────────────────────────────────────────────────────────────────────

/// SQLite-backed memory: [`memory_sqlite::MemorySqlite`], [`memory_sqlite::DummyEmbedder`].
///
/// Enabled by the `memory-sqlite` feature flag.
#[cfg(feature = "memory-sqlite")]
pub mod memory_sqlite {
    pub use klieo_memory_sqlite::*;
}

/// Neo4j-backed memory: short-term + episodic.
///
/// Enabled by the `memory-neo4j` feature flag.
#[cfg(feature = "memory-neo4j")]
pub mod memory_neo4j {
    pub use klieo_memory_neo4j::*;
}

/// Qdrant-backed long-term memory (vector recall).
///
/// Enabled by the `memory-qdrant` feature flag.
#[cfg(feature = "memory-qdrant")]
pub mod memory_qdrant {
    pub use klieo_memory_qdrant::*;
}

/// Shared `Embedder` trait + dummy/fake impls.
///
/// Enabled by the `embed-common` feature flag.
#[cfg(feature = "embed-common")]
pub mod embed_common {
    pub use klieo_embed_common::*;
}

// ── bus ───────────────────────────────────────────────────────────────────────

/// In-process bus: [`bus_memory::MemoryBus`].
///
/// Enabled by the `bus-memory` feature flag.
#[cfg(feature = "bus-memory")]
pub mod bus_memory {
    pub use klieo_bus_memory::*;
}

/// NATS JetStream bus: [`bus_nats::NatsBus`], [`bus_nats::NatsBusConfig`].
///
/// Enabled by the `bus-nats` feature flag.
#[cfg(feature = "bus-nats")]
pub mod bus_nats {
    pub use klieo_bus_nats::*;
}

// ── mcp ───────────────────────────────────────────────────────────────────────

/// MCP adapter: [`mcp::McpToolset`], [`mcp::StdioTransport`].
///
/// Enabled by the `mcp` feature flag (implies `tools`).
#[cfg(feature = "mcp")]
pub mod mcp {
    pub use klieo_tools_mcp::*;
}

// ── composition + protocol ────────────────────────────────────────────────────

/// Multi-agent composition shapes: `Sequential` / `Parallel` / `Loop` / `Graph`.
///
/// Enabled by the `flows` feature flag.
#[cfg(feature = "flows")]
pub mod flows {
    pub use klieo_flows::*;
}

/// Durable Agent-to-Agent v1.0 protocol layer.
///
/// Enabled by the `a2a` feature flag.
#[cfg(feature = "a2a")]
pub mod a2a {
    pub use klieo_a2a::*;
}

/// Generic decompose / critique / refine traits + `QualityLoop` runner.
///
/// Enabled by the `spec` feature flag.
#[cfg(feature = "spec")]
pub mod spec {
    pub use klieo_spec::*;
}

// ── auth ──────────────────────────────────────────────────────────────────────

/// OAuth 2.0 bearer-token Authenticator for klieo HTTP transports.
///
/// Enabled by the `oauth` feature flag.
#[cfg(feature = "oauth")]
pub mod auth_oauth {
    pub use klieo_auth_oauth::*;
}

// ── observability + provenance ────────────────────────────────────────────────

/// Tier 2 observability — RunLog projection + replay engine.
///
/// Enabled by the `runlog` feature flag.
#[cfg(feature = "runlog")]
pub mod runlog {
    pub use klieo_runlog::*;
}

/// Append-only Merkle hash chain + signed evidence bundles.
///
/// Enabled by the `provenance` feature flag.
#[cfg(feature = "provenance")]
pub mod provenance {
    pub use klieo_provenance::*;
}

/// OpenTelemetry OTLP exporter wired to `tracing` spans.
///
/// Enabled by the `otel` feature flag.
#[cfg(feature = "otel")]
pub mod otel {
    pub use klieo_otel::*;
}

// ── lib tests ─────────────────────────────────────────────────────────────────

#[cfg(test)]
mod lib_tests {
    use super::*;

    #[test]
    fn core_types_always_visible() {
        // RunOptions and Error::Cancelled must resolve through the crate root.
        let opts = RunOptions::default();
        assert_eq!(opts.max_steps, 16);

        let err = Error::Cancelled;
        assert!(matches!(err, Error::Cancelled));
    }
}