Expand description
flux-sdk — the high-level library API.
Wraps the flux-flow engine, built-in tools, the safety envelope, and a session into a small
Client. You supply a Provider (from flux-providers) and a workspace
root; the SDK wires the rest.
There are three front doors: Client (an adaptive agent turn driven by an authored Flux-Lang
outer loop, returning a TurnOutput), FlowClient (the authored Flux-Lang
parse → analyze → execute lifecycle), and the dsl (author the AST in Rust).
Client assembles flux_flow::engine::FlowEngine; FlowClient delegates directly to the same
flux-flow runtime adapter, store, and safety envelope for one-flow execution. Each
door has a runnable, no-API-key example: examples/client_basic.rs,
examples/parameterized_flow.rs, and examples/dsl_loops.rs respectively. On top of the DSL,
recipes is a cookbook of reusable, parameterized flow builders (routing, lookup, the loop
family, resilience).
// Runnable hermetic version: `cargo run -p codewandler-flux-sdk --example client_basic`.
use flux_sdk::Client;
let provider = Box::new(flux_providers::anthropic::anthropic_from_env()?);
let client = Client::builder().auto_approve(true).build(provider, ".")?;
let out = client.run("Summarize the README").await?;
println!("{}", out.text);Re-exports§
pub use events::AgentEvent;pub use events::FlowStream;pub use events::TurnStream;pub use flow::assemble_registry;pub use flow::ExecutionResult;pub use flow::FlowClient;pub use flow::FlowClientBuilder;pub use session::Fork;pub use session::Session;pub use storage::Storage;
Modules§
- approval
- Approval policy. Implement
Approverand pass it to a builder’sapprover(...)to gate ops with your own logic;ApprovalChoiceis your verdict,IntentSetis the per-call intent yourrequestreceives, andRiskApproveris a ready-made risk-tiered policy. - authorization
- Authorization floor. Every SDK executor carries an [
ExecutionAuthorization] profile. Builders use [ExecutionAuthorization::local] by default; embedding services should install a resolved policy and identity withwith_authorization(...). - dsl
- The Rust embedded DSL for authoring flows — builder primitives that construct the Flux-Lang
AST. Build a
flux_lang::ast::DraftAstwithdsl::Flow/dsl::Block(loops and control-flow are first-class), then drive it throughFlowClient::analyze+FlowClient::execute. Re-exported fromflux-langso consumers can stay insideflux_sdk. Seeexamples/dsl_loops.rs. A Rust embedded DSL for authoring Flux-Lang flows — builder primitives that compile straight down to thecrate::asttree, so a Rust programmer can write a flow natively instead of emitting JSON or natural language. - events
- Owned streaming events — the async-iterator shape of a turn.
- flow
- The Flux-Lang lifecycle surface — the SDK front door for authored deterministic flows.
- observe
- Session observability. The projection types
Sessionreaders return —Message(history),TurnSummary(turns),RunEvent(run_trace),ModelCost(cost), andEfficiencySummary(efficiency) — plus the storesStorage::customaccepts and the evidence-gated surfacing typesClientBuilder::groupstakes. - recipes
- Reusable Flux-Lang flow recipes — a cookbook of small, parameterized builders that compile to a
DraftAstout of the DSL primitives. - session
- The resumable session handle.
- storage
- Where a client’s sessions live — the storage seam.
- subagents
- Sub-agents. Attach named roles to a conversational client with
ClientBuilder::with_sub_agents(or to a flow client withFlowClient::with_sub_agents); a turn whose native stage callstask(role, …)then delegates to a role’s child agent through the same authorization → approval → guarded-IO envelope.SubAgentsis the bundle (roles + the child tool surface + aProviderFactory+ limits),SpawnLimitsbounds each child (tokens, wall-clock, …), andRole/RoleRegistryname the roles ataskmay target (try_parse_rolebuilds aRolefrom a markdown definition while rejecting malformed capability metadata). - tools
- Custom tools. Implement
Tool— or build one from a closure withtool_fn/FnTool— and register it withClientBuilder::register_op/FlowClient::register_op. A registered tool dispatches through the same authorization → approval → guarded-IO envelope as every built-in.ToolSpec(withRisk) describes the tool to the model and the envelope;ToolContext/ToolResultare the dispatch types;ToolRegistryis what aregister_packclosure receives. - voice
- Voice. The types the two voice front doors take —
Session::run_voice_flow(flow-driven: the flow leads, the model is speech I/O) andFlowClient::run_voice_session(model-driven: the model leads and calls tools). ImplementVoiceSinkto receive audio / transcripts / lifecycle;VoiceReplyis a flow turn’s spoken reply (Continue/Complete);RealtimeProvider+RealtimeConfigare the full-duplex provider seam (a concrete one lives behindflux-providers’realtimefeature).
Structs§
- Adaptive
Loop Policy - The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. Cognition policy for one logical adaptive run. The total call ceiling spans intent repair, exploration, and every durable decision resume. - Agent
Executor Config Deprecated - Surface-owned inputs used when
AgentSpecconstructs its guardedExecutor. - Agent
Spec - The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. A first-class agent definition: model, persona, skills, tool selection, permissions, and the turn settings — everything that distinguishes one agent from another. Assemble it into a runningFlowEnginewithAgentSpec::assemble(the simple path) orAgentSpec::into_engine(when the surface builds its own richly-configuredExecutor). - Agent
Stage Policy - The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. Optional overrides for one built-in adaptive model stage. Missing values inherit the agent’s provider-local model, effort, and token setting. - Cancellation
Token - Cancels a running turn (
Session::send_with) or voice session — re-exported fromtokio-utilso consumers don’t need the direct dependency. A token which can be used to signal a cancellation request to one or more tasks. - Client
- A configured agent (runs on
FlowEngine): the expensive, long-lived half of the SDK’s conversational door. Conversations areSessionhandles — a fresh default one is created at build (soClient::runworks out of the box), andClient::create_session/Client::open_session/Client::latest_sessionmanage the rest. With persistentStorage, sessions — and their suspended flows — survive the process. - Client
Builder - Builder for a
Client. Internally anAgentSpecplus the shared envelope knobs, so every agent-definition field has exactly one home andfrom_specis the full-control escape hatch rather than a parallel path. - Permissions
- The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. Pre-allow/deny rules an agent’s executor starts with (the rest gate through the approver). - Pricing
Table - The model rate table
Session::costprices a session against.PricingTable::builtinis the curated default; the optionalpricingfeature adds [pricing::load_pricing_table] to overlay a user’s~/.flux/pricing.toml. A price book: model id → per-tierRates. Build the curated defaults withPricingTable::builtin, then optionally fold user overrides on top withPricingTable::apply_override. - Replay
Report - The report
Session::replayreturns — the replayed plans, a divergence diagnostic (Noneon a faithful replay), and cassette-cell accounting. Re-exported fromflux-flow. The outcome of a hermetic session replay. - Sandbox
- The OS-sandbox posture types, re-exported so a consumer can inject an explicit sandbox into a
builder via
ClientBuilder::with_sandbox/flow::FlowClientBuilder::with_sandboxwithout taking a directflux-systemdependency. The resolved sandbox for this process: settings plus the backendresolve()picked. The one seamcrate::System::build_commandwraps through. - Sandbox
Settings - The OS-sandbox posture types, re-exported so a consumer can inject an explicit sandbox into a
builder via
ClientBuilder::with_sandbox/flow::FlowClientBuilder::with_sandboxwithout taking a directflux-systemdependency. The resolved sandbox posture for this process: mode, network policy, and any extra writable paths layered on top ofSpawnPolicy::for_workspace’s defaults. - Turn
Output - The result of one turn — a
Client::run, aSession::send, or aSession::start_flow. - Usage
- The per-turn token accounting carried on
TurnOutput. Re-exported fromflux-core. Token accounting for a single provider turn.
Enums§
- Agent
Loop Spec - The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. The outer control program for an agent turn. - Builtin
Agent Loop - The agent definition (
ClientBuilder::from_spec) plus its permission rules. Re-exported so the full-control door needs no directflux-agentdependency. A shipped agent-loop preset. Presets are ordinary Flux-Lang programs selected explicitly by an agent definition; the host does not probe the workspace for an implicit override.
Traits§
- Agent
Sink - The engine’s streaming contract — implement it and pass it to
Session::send_withto receive a turn’s deltas, tool calls, tool results, and observations as they happen (or useSession::streamfor the owned-event shape). Re-exported fromflux-flow. Receives streaming output and tool activity from a turn (the CLI/TUI/SDK implements this). - Provider
- The provider trait — the one construction argument every client’s
buildtakes. The concrete backends live influx-providers(Anthropic/OpenAI/OpenRouter/Ollama/Bedrock + the subscription providers); a consumer implements this for a mock, or addsflux-providersfor a real one. An LLM provider capable of streaming a response.
Functions§
- stage_
fn - Build a typed, closure-backed stage operation.
IandOare independent contracts: both JSON Schemas are derived and registered, the Flux analyzer infersOat call sites, and execution still traverses the ordinary authorization/approval dispatcher. The safe default is a low-risk, idempotent read stage; use a bespoketools::Toolwhen the stage has effects or permission subjects that need a stronger contract.