Skip to main content

Crate agents_kit

Crate agents_kit 

Source
Expand description

Portable agent runtimes over Codex App Server, OpenCode, and a provider-backed Custom implementation.

The hierarchy is Agent → Workspace → Conversation. Implement AgentBackend, WorkspaceBackend and ConversationBackend directly to supply your own concrete associated children. The supplied handles implement those same traits.

§Choose a task

Custom retains its direct Provider and Toolset implementations. Each toolset’s Handler stays associated and need not be Clone. Prompt streams observe accepted work: dropping an observer neither cancels that work nor releases its slot. Use abort or consuming lifecycle operations and keep the runtime alive through cleanup. Native builders retain no provider value; Custom receives one through AgentBuilder::with_provider. Exact Model continuations live only within an active prompt loop; durable history contains provider-neutral text.

§Construct and shut down a Custom agent

This runs locally with memory Lance. Provider construction makes no model request; prompting would require the configured Ollama service and exact model. The result is inspected only after shutdown has been attempted.

use std::{num::NonZeroUsize, time::Duration};
use agents_kit::{AgentBackend, AgentBuilder, AgentStorage};
use agents_kit::config::{AgentConfig, CustomAgentConfig, CustomLoopLimits, CustomToolApproval};
use agents_kit::{model::ModelSelector, tool::ToolSelection};
use providers_kit::{Provider, ProviderConfig};
use providers_kit::config::{OllamaConfig, ProviderKind, TransportConfig};
use storage_kit::{StateStore, state::config::{LanceStateStoreConfig, StateStoreConfig}};
let custom = CustomAgentConfig::new(
    ModelSelector::new("exact-model")?, ToolSelection::None,
    CustomLoopLimits::new(4, 0, 1)?, CustomToolApproval::Deny,
)?;
let config = AgentConfig::new(custom.into(), Duration::from_secs(10), NonZeroUsize::MIN)?;
let store = StateStore::connect(StateStoreConfig::lance(LanceStateStoreConfig::memory())).await?;
let provider = Provider::from_config(ProviderConfig::new(
    ProviderKind::Ollama(OllamaConfig::local()), TransportConfig::default(),
))?;
let agent = AgentBuilder::create(config, AgentStorage::new(store))
    .with_provider(provider).build().await?;
let id = agent.id();
let result = agent.info().await;
let cleanup = agent.shutdown().await;
let info = match (result, cleanup) {
    (Ok(info), Ok(())) => Ok(info),
    (Err(primary), Err(cleanup)) => Err(primary.with_supplementary(cleanup)),
    (Err(error), _) | (_, Err(error)) => Err(error),
}?;
assert_eq!(info.id(), &id);

Re-exports§

pub use crate::conversation::Conversation;
pub use crate::conversation::ConversationBackend;
pub use crate::error::KitError;
pub use crate::workspace::Workspace;
pub use crate::workspace::WorkspaceBackend;

Modules§

config
Agent construction settings and backend runtime policies. Validated passive configuration for Agent construction.
conversation
Conversation handles, backend contracts, and conversation requests and responses. Conversation metadata, accepted prompts, exact file reads and durable interactions.
error
Portable, safely formatted failures for Agent operations.
identity
Validated identities and agent inventory information. Opaque durable identities and descriptive agent inventory.
knowledge
Knowledge sources, scopes, ingestion requests, and retrieval policies. Inputs for privately managed knowledge ingestion and retrieval policy.
model
Model inventory, opaque selectors, and reasoning settings. Backend-advertised model, personality, and reasoning selectors.
notification
Durable notifications, caller resolutions, and notification streams. Durable conversation facts, exclusive delivery, and caller interaction resolutions.
prompt
Prompt requests, responses, and incremental output streams. Prompt inputs, exact terminal responses, and transient output observation.
tool
Portable tool selection and managed tool inventory. Managed tool inventory and per-prompt selection.
workspace
Workspace handles, backend contracts, defaults, and workspace requests. Workspace contexts, durable snapshots, revision-checked requests, and live handles.

Structs§

Agent
A live handle to one durable agent and its workspace inventory.
AgentBuilder
Configures creation or reopening of one durable Agent.
AgentStorage
Coordinates durable agent identities through a caller-supplied state store.

Traits§

AgentBackend
Public implementation contract for a complete portable agent runtime.