1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//! # 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:
//!
//! | Feature | Module | Contents |
//! |---|---|---|
//! | `core` | [`core`] | Shared types: [`core::Item`], [`core::Part`], [`core::SessionId`], [`core::Usage`], cancellation primitives |
//! | `capabilities` | [`capabilities`] | Capability traits: [`capabilities::Invocable`], [`capabilities::CapabilityProvider`] |
//! | `tools` | [`tools`] | Tool abstractions: [`tools::Tool`], [`tools::ToolRegistry`], [`tools::ToolSpec`], permission types |
//! | `loop` | [`loop_`] | Agent loop: [`loop_::Agent`], [`loop_::AgentBuilder`], [`loop_::LoopDriver`], [`loop_::LoopStep`] |
//! | `reporting` | [`reporting`] | Loop observers: [`reporting::StdoutReporter`], [`reporting::JsonlReporter`], [`reporting::UsageReporter`] |
//!
//! ## Optional features
//!
//! | Feature | Module | Contents |
//! |---|---|---|
//! | `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-anthropic` | [`provider_anthropic`] | Anthropic Messages API [`loop_::ModelAdapter`] implementation |
//! | `provider-cerebras` | [`provider_cerebras`] | Cerebras Inference API [`loop_::ModelAdapter`] implementation |
//! | `provider-openrouter` | [`provider_openrouter`] | OpenRouter [`loop_::ModelAdapter`] implementation |
//! | `task-manager` | [`task_manager`] | Tool 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.
//!
//! ```rust,ignore
//! 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.
//!
//! ```rust
//! 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());
//! ```
/// Core types shared by every agentkit crate.
///
/// Provides the fundamental data model: [`core::Item`] and [`core::Part`] for
/// representing conversation content, ID newtypes such as [`core::SessionId`]
/// and [`core::TurnId`], [`core::Usage`] for token/cost tracking, and
/// cancellation primitives ([`core::CancellationController`],
/// [`core::TurnCancellation`]).
pub use agentkit_core as core;
/// Capability abstractions for tools, resources, and prompts.
///
/// Defines the [`capabilities::Invocable`] trait for callable capabilities,
/// [`capabilities::ResourceProvider`] and [`capabilities::PromptProvider`] for
/// serving resources and prompts, and [`capabilities::CapabilityProvider`] for
/// bundling all three into a single object. These traits form the foundation
/// that the [`tools`] module builds on.
pub use agentkit_capabilities as capabilities;
/// Tool definitions, registry, permission checking, and execution.
///
/// Contains the [`tools::Tool`] trait, [`tools::ToolRegistry`] for collecting
/// tools, [`tools::ToolSpec`] for declaring tool schemas, and the permission
/// system ([`tools::PermissionChecker`], [`tools::PermissionPolicy`],
/// [`tools::CompositePermissionChecker`]). The [`tools::BasicToolExecutor`]
/// bridges the registry with the agent loop.
pub use agentkit_tools_core as tools;
/// Agent loop orchestration: sessions, turns, tool dispatch, and interrupts.
///
/// The main entry point is [`loop_::Agent`], built via [`loop_::AgentBuilder`].
/// Calling [`loop_::Agent::start`] yields a [`loop_::LoopDriver`] that
/// produces [`loop_::LoopStep`]s -- either a finished turn or an interrupt
/// (approval, auth, or input request) that the host must resolve before the
/// loop continues. Also defines [`loop_::ModelAdapter`], the trait that
/// provider crates implement.
///
/// Re-exported as `loop_` (with trailing underscore) because `loop` is a
/// reserved keyword in Rust.
pub use agentkit_loop as loop_;
/// Tool task scheduling for loop-integrated tool execution.
///
/// Provides [`task_manager::SimpleTaskManager`] for the existing sequential
/// behavior and [`task_manager::AsyncTaskManager`] for foreground parallelism
/// plus detached background tasks.
///
/// Requires the `task-manager` feature.
pub use agentkit_task_manager as task_manager;
/// Loop observers for logging, usage tracking, and transcript recording.
///
/// Provides [`reporting::StdoutReporter`] for human-readable terminal output,
/// [`reporting::JsonlReporter`] for machine-readable JSONL streams,
/// [`reporting::UsageReporter`] for aggregated token/cost totals,
/// [`reporting::TranscriptReporter`] for a growing snapshot of conversation
/// items, and [`reporting::CompositeReporter`] for fanning out events to
/// multiple observers.
pub use agentkit_reporting as reporting;
/// Transcript compaction triggers, strategies, and pipelines.
///
/// Use this module to keep transcripts from growing without bound. Combine
/// [`compaction::CompactionTrigger`]s (which decide *when* to compact) with
/// [`compaction::CompactionStrategy`]s (which decide *how*) through a
/// [`compaction::CompactionPipeline`], and hand the resulting
/// [`compaction::CompactionConfig`] to the agent builder.
///
/// Requires the `compaction` feature.
pub use agentkit_compaction as compaction;
/// Context loaders for `AGENTS.md` files.
///
/// Discovers and loads project-level agent instructions into
/// [`core::Item`]s with [`core::ItemKind::Context`]. See
/// [`context::ContextLoader`] and [`context::AgentsMd`].
///
/// Requires the `context` feature.
pub use agentkit_context as context;
/// Model Context Protocol (MCP) server connections.
///
/// Connects to MCP servers over stdio or SSE transports, discovers their
/// tools, resources, and prompts, and exposes them as agentkit
/// [`capabilities::CapabilityProvider`]s and [`tools::Tool`] implementations
/// that plug directly into the agent loop.
///
/// Requires the `mcp` feature.
pub use agentkit_mcp as mcp;
/// Generic chat completions adapter base.
///
/// Provides [`adapter_completions::CompletionsProvider`] and
/// [`adapter_completions::CompletionsAdapter`] for building provider crates
/// with minimal boilerplate.
///
/// Requires the `adapter-completions` feature.
pub use agentkit_adapter_completions as adapter_completions;
/// OpenRouter [`loop_::ModelAdapter`] implementation.
///
/// Provides [`provider_openrouter::OpenRouterAdapter`] and
/// [`provider_openrouter::OpenRouterConfig`] for connecting the agent loop to
/// any model available through the [OpenRouter](https://openrouter.ai) API.
///
/// Requires the `provider-openrouter` feature.
pub use agentkit_provider_openrouter as provider_openrouter;
/// Anthropic Messages API [`loop_::ModelAdapter`] implementation.
///
/// Provides [`provider_anthropic::AnthropicAdapter`] and
/// [`provider_anthropic::AnthropicConfig`] for connecting the agent loop to
/// Anthropic's `/v1/messages` endpoint. Supports streaming (default),
/// extended thinking, prompt caching, and server-side tools (web search,
/// web fetch, code execution) via the
/// [`provider_anthropic::ServerTool`] trait. Unlike the other providers this
/// crate does not go through `adapter-completions` — Anthropic's API is not
/// OpenAI-compatible — so the feature depends on `loop` directly.
///
/// Requires the `provider-anthropic` feature.
pub use agentkit_provider_anthropic as provider_anthropic;
/// Cerebras Inference API [`loop_::ModelAdapter`] implementation.
///
/// Provides [`provider_cerebras::CerebrasAdapter`] and
/// [`provider_cerebras::CerebrasConfig`] for connecting the agent loop to
/// Cerebras' `/v1/chat/completions` endpoint. Supports streaming (default),
/// reasoning, strict JSON Schema output, prompt-cache read telemetry, and —
/// behind Cargo features — msgpack/gzip request compression, predicted
/// outputs, service tiers, and the Files + Batch API for async bulk
/// inference. Like `provider-anthropic` this crate implements `ModelAdapter`
/// directly rather than going through `adapter-completions`, so the feature
/// depends on `loop` directly.
///
/// Requires the `provider-cerebras` feature.
pub use agentkit_provider_cerebras as provider_cerebras;
/// OpenAI [`loop_::ModelAdapter`] implementation.
///
/// Requires the `provider-openai` feature.
pub use agentkit_provider_openai as provider_openai;
/// Ollama [`loop_::ModelAdapter`] implementation.
///
/// Requires the `provider-ollama` feature.
pub use agentkit_provider_ollama as provider_ollama;
/// vLLM [`loop_::ModelAdapter`] implementation.
///
/// Requires the `provider-vllm` feature.
pub use agentkit_provider_vllm as provider_vllm;
/// Groq [`loop_::ModelAdapter`] implementation.
///
/// Requires the `provider-groq` feature.
pub use agentkit_provider_groq as provider_groq;
/// Mistral [`loop_::ModelAdapter`] implementation.
///
/// Requires the `provider-mistral` feature.
pub use agentkit_provider_mistral as provider_mistral;
/// Filesystem tools: read, write, edit, move, delete, list, and mkdir.
///
/// Call [`tool_fs::registry()`] to get a [`tools::ToolRegistry`] pre-loaded
/// with all filesystem tools. Each tool integrates with the permission system
/// via [`tools::FileSystemPermissionRequest`].
///
/// Requires the `tool-fs` feature.
pub use agentkit_tool_fs as tool_fs;
/// Shell execution tool (`shell.exec`).
///
/// Call [`tool_shell::registry()`] to get a [`tools::ToolRegistry`] containing
/// the shell execution tool. Supports custom working directories, environment
/// variables, timeouts, and cooperative turn cancellation.
///
/// Requires the `tool-shell` feature.
pub use agentkit_tool_shell as tool_shell;
/// Agent Skills tool for progressive skill discovery and activation.
///
/// Provides [`tool_skills::SkillRegistry`] which discovers `SKILL.md` files
/// and exposes an `activate_skill` tool for on-demand loading. Skills are
/// listed in the tool description (catalog tier) and their full content is
/// returned only when the model activates them.
///
/// Requires the `tool-skills` feature.
pub use agentkit_tool_skills as tool_skills;
/// Convenience re-exports from all enabled feature modules.
///
/// Pulls in every public item from every enabled module via glob imports.
/// Useful for quick prototyping but may cause name collisions in larger
/// projects -- prefer qualified imports (e.g. `agentkit::core::Item`) for
/// production code.