Skip to main content

Crate agentkit

Crate agentkit 

Source
Expand description

§agentkit

Composable building blocks for agentic loops.

agentkit is a feature-gated umbrella crate that re-exports every crate in the agentkit workspace. Enable only the features you need and access them through a single dependency.

§Default features

The following modules are available with default features enabled:

§Optional features

FeatureModuleContents
compaction[compaction]Transcript compaction triggers, strategies, and pipelines
context[context]AGENTS.md discovery and context loading
mcp[mcp]Model Context Protocol (MCP) server connections
provider-openrouter[provider_openrouter]OpenRouter loop_::ModelAdapter implementation
task-managertask_managerTool task scheduling: task_manager::SimpleTaskManager, task_manager::AsyncTaskManager
tool-fs[tool_fs]Filesystem tools (read, write, edit, move, delete, list, mkdir)
tool-shell[tool_shell]Shell execution tool (shell.exec)
tool-skills[tool_skills]Progressive Agent Skills discovery and activation

§Example: building and running an agent

This example uses the provider-openrouter and reporting features to build a minimal agent, submit a user message, and drive the loop until the model finishes its turn.

use agentkit::core::{Item, ItemKind};
use agentkit::loop_::{
    Agent, LoopStep, PromptCacheRequest, PromptCacheRetention, SessionConfig,
};
use agentkit::provider_openrouter::{OpenRouterAdapter, OpenRouterConfig};
use agentkit::reporting::StdoutReporter;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let adapter = OpenRouterAdapter::new(OpenRouterConfig::from_env()?)?;

    let agent = Agent::builder()
        .model(adapter)
        .observer(StdoutReporter::new(std::io::stdout()))
        .build()?;

    let mut driver = agent
        .start(
            SessionConfig::new("demo").with_cache(
                PromptCacheRequest::automatic().with_retention(PromptCacheRetention::Short),
            ),
        )
        .await?;

    driver.submit_input(vec![Item::text(
        ItemKind::User,
        "What is the capital of France?",
    )])?;

    loop {
        match driver.next().await? {
            LoopStep::Finished(result) => {
                println!("Finished: {:?}", result.finish_reason);
                break;
            }
            LoopStep::Interrupt(interrupt) => {
                // Resolve the interrupt (approval, auth, or input) then continue.
                println!("Interrupt: {interrupt:?}");
                break; // a real app would resolve and loop
            }
        }
    }
    Ok(())
}

§Example: composing reporters

Multiple loop_::LoopObserver implementations can be combined through reporting::CompositeReporter so that a single loop feeds several observers at once.

use agentkit::reporting::{
    CompositeReporter, JsonlReporter, UsageReporter, TranscriptReporter,
};

let reporter = CompositeReporter::new()
    .with_observer(JsonlReporter::new(Vec::new()))
    .with_observer(UsageReporter::new())
    .with_observer(TranscriptReporter::new());

Re-exports§

pub use agentkit_core as core;
pub use agentkit_capabilities as capabilities;
pub use agentkit_tools_core as tools;
pub use agentkit_loop as loop_;
pub use agentkit_task_manager as task_manager;
pub use agentkit_reporting as reporting;

Modules§

prelude
Convenience re-exports from all enabled feature modules.