Skip to main content

OxicodeBuilder

Struct OxicodeBuilder 

Source
pub struct OxicodeBuilder { /* private fields */ }
Expand description

Builder for creating an Oxicode instance.

Implementations§

Source§

impl OxicodeBuilder

Source

pub fn new() -> Self

Create a new empty builder (no builtins, no providers, no models).

Source

pub fn with_builtins(self) -> Self

Register all built-in models and enable built-in provider creation.

This loads 50+ model definitions from the oxicode-ai static database and enables create_builtin_provider() fallback in Oxicode::create_provider.

Source

pub fn provider(self, name: &str, p: impl Provider + 'static) -> Self

Register a custom provider.

Source

pub fn tool(self, tool: impl AgentTool + 'static) -> Self

Register a custom tool in the shared tool registry.

Source

pub fn provider_factory( self, name: &str, factory: impl Fn() -> Result<Arc<dyn Provider>> + Send + Sync + 'static, ) -> Self

Register a provider factory — a closure that lazily creates a provider.

Unlike Self::provider(), which takes an already-constructed instance, this stores a factory closure. The factory is invoked the first time Oxicode::create_provider(name) is called, and the resulting provider is cached for subsequent calls.

This is useful when provider construction requires credential resolution or network configuration that should happen at first use, not at build time.

§Example
use std::sync::Arc;
use oxicode_sdk::{OxicodeBuilder, OpenAiProvider};

let oxicode = OxicodeBuilder::new()
    .with_builtins()
    .provider_factory("custom", || {
        Ok(Arc::new(OpenAiProvider::with_base_url_and_key(
            "https://api.example.com",
            Some("key".into()),
        )))
    })
    .build();
Source

pub fn api_key(self, provider_name: &str, key: impl Into<String>) -> Self

Register an API key for a specific provider.

When create_provider(name) is called, the key is injected into the provider’s constructor automatically. Keys registered here take precedence over environment variables.

§Example
use oxicode_sdk::OxicodeBuilder;

let oxicode = OxicodeBuilder::new()
    .with_builtins()
    .api_key("anthropic", "sk-ant-test-key")
    .api_key("openai", "sk-test-key")
    .build();
Source

pub fn base_url(self, provider_name: &str, url: impl Into<String>) -> Self

Register a base URL override for a specific provider.

Useful for OpenAI-compatible providers (ZAI, Groq, etc.) that use a different endpoint.

§Example
use oxicode_sdk::OxicodeBuilder;

let oxicode = OxicodeBuilder::new()
    .with_builtins()
    .base_url("openai", "https://my-proxy.example.com/v1")
    .build();
Source

pub fn credential( self, provider_name: &str, api_key: impl Into<String>, base_url: Option<&str>, ) -> Self

Register a full credential set for a provider.

Convenience method combining api_key() and base_url().

§Example
use oxicode_sdk::OxicodeBuilder;

let oxicode = OxicodeBuilder::new()
    .with_builtins()
    .credential("openai", "sk-test", Some("https://proxy.example.com/v1"))
    .build();
Source

pub fn model(self, model: Model) -> Self

Register a custom model.

Source

pub fn with_ports(self, ports: PortRegistry) -> Self

Register a complete PortRegistry at once.

Use this when you have a fully-built registry (e.g. loaded from a directory of file-based adapters). For piecemeal registration, use the with_port_* methods below.

Source

pub fn with_catalog(self, catalog: Arc<dyn ModelCatalog>) -> Self

Register the model catalog port.

The catalog is the source of truth for provider/model metadata. If not called, the SDK uses NoopModelCatalog (empty results — all lookups return None/vec![]).

§Example
use oxicode_sdk::{OxicodeBuilder, NoopModelCatalog};

// `NoopModelCatalog` is the empty default used when no catalog is
// registered — pass any `Arc<dyn ModelCatalog>` here instead.
let catalog = NoopModelCatalog::new();
let oxicode = OxicodeBuilder::new()
    .with_catalog(catalog)
    .build();
Source

pub fn with_state(self, store: Arc<dyn StateStore>) -> Self

Register the state store.

Source

pub fn with_config(self, store: Arc<dyn ConfigStore>) -> Self

Register the config store.

Source

pub fn with_auth(self, auth: Arc<dyn AuthProvider>) -> Self

Register the auth provider.

Source

pub fn with_event_bus(self, bus: Arc<dyn EventBus>) -> Self

Register the event bus.

Source

pub fn with_skills(self, loader: Arc<dyn SkillLoader>) -> Self

Register the skill loader.

Source

pub fn with_personas(self, provider: Arc<dyn PersonaProvider>) -> Self

Register the persona provider.

Source

pub fn with_access(self, gate: Arc<dyn AccessGate>) -> Self

Register the access gate.

Source

pub fn with_capabilities(self, resolver: Arc<dyn CapabilityResolver>) -> Self

Register the capability resolver.

Source

pub fn with_memory(self, store: Arc<dyn MemoryStore>) -> Self

Register the memory store.

Source

pub fn with_cron(self, scheduler: Arc<dyn CronScheduler>) -> Self

Register the cron scheduler.

Source

pub fn with_resources(self, monitor: Arc<dyn ResourceMonitor>) -> Self

Register the resource monitor.

Source

pub fn with_url_router(self, router: Arc<dyn InternalUrlRouter>) -> Self

Register the internal URL router.

Source

pub fn with_rules(self, rules: Arc<dyn RuleRegistry>) -> Self

Register the rule registry (TTSR).

Source

pub fn with_embeddings(self, embeddings: Arc<dyn EmbeddingProvider>) -> Self

Register the embedding provider.

Source

pub fn with_hooks(self, runner: Arc<dyn HookRunner>) -> Self

Register the hook runner port.

When set, crate::AgentBuilder::with_port_hooks composes a HookMiddleware backed by this runner into the agent’s hook pipeline. When unset, the port stays at NoopHookRunner and the middleware short-circuits to a no-op.

Source

pub fn supervisor(self) -> SupervisorBuilder

Create a supervisor builder for managing agent lifecycles.

§Example
use oxicode_sdk::OxicodeBuilder;

let (oxicode, supervisor) = OxicodeBuilder::new()
    .with_builtins()
    .supervisor()
    .snapshot_dir("/data/snapshots")
    .build()?;
Source

pub fn build(self) -> Oxicode

Build the Oxicode engine. This consumes the builder.

Source

pub fn with_mcp_config(self, config: McpConfig) -> Self

Inject a programmatic MCP configuration. This overrides the on-disk ~/.config/oxicode/mcp.json and .mcp.json discovery.

§Example
use oxicode_sdk::{OxicodeBuilder, McpConfig, ServerEntry, LifecycleMode};

let mut mcp = McpConfig::default();
mcp.mcp_servers.insert(
    "my-server".into(),
    ServerEntry {
        command: Some("npx".into()),
        args: Some(vec!["-y".into(), "@my-org/mcp-server".into()]),
        lifecycle: Some(LifecycleMode::Lazy),
        ..Default::default()
    },
);

let oxicode = OxicodeBuilder::new()
    .with_builtins()
    .with_mcp_config(mcp)
    .build();
Source

pub fn with_mcp_paths(self, cache_path: PathBuf, consent_path: PathBuf) -> Self

Set custom disk paths for the MCP metadata cache and consent store.

Only takes effect when MCP is enabled (see with_mcp). When unset, oxicode uses its default paths (~/.config/oxicode/). Intended for SDK consumers that self-host MCP state under their own config directory (e.g. oxios under ~/.oxios/).

Combine with with_mcp_config to also inject a programmatic config. If only paths are supplied (no config), oxicode auto-discovers its config from the standard file locations and writes cache/consent to the supplied paths.

Source

pub fn with_mcp(self, enabled: bool) -> Self

Enable or disable MCP. When disabled, no McpManager is spawned and the mcp proxy tool / direct tools are not registered.

Defaults to true.

Trait Implementations§

Source§

impl Default for OxicodeBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more