Expand description
Public Rust facade for Merry.
This crate is the interface layer for applications embedding Merry. It exposes the high-level semantic agent API plus small components for runtime construction: providers, profiles, tools, lifecycle hooks, events, and stable errors. Lower-level crates still own their domains.
§Context Windows And Lifecycle Hooks
use merry::{
AfterModelDecision, AgentBuilder, BeforeModelDecision, BeforeToolDecision,
CompactionConfig, HookRegistry, SessionId, ToolName, providers::openai_compatible,
};
use std::num::NonZeroU64;
let provider = openai_compatible()
.api_key("sk-...")?
.model_name("gpt-4.1-mini")?
.context_window_tokens(NonZeroU64::new(128_000).expect("non-zero"))
.build()?;
let hooks = HookRegistry::new()
.before_model_step(|ctx| async move {
if ctx.session_usage.is_some_and(|u| u.total.total_tokens >= 100_000) {
return BeforeModelDecision::stop_turn("token budget exceeded", None);
}
BeforeModelDecision::continue_normally()
})
.before_tool_call_for([ToolName::new("run_shell")?], |_ctx| async move {
BeforeToolDecision::deny("shell execution disabled")
})
.after_model_step(|_ctx| async move { AfterModelDecision::accept() });
let agent = AgentBuilder::new(SessionId::new("demo")?)
.provider(provider)
.compaction(CompactionConfig::default())
.hooks(hooks)
.build()?;
let _result = agent.run("Summarize the workspace.").await?;Modules§
- binding
- Owned, provider-neutral contracts for foreign-language bindings.
- coding
- High-level coding session facade shared by terminal UI, headless CLI, WebUI backends, and Rust SDK hosts.
- events
- Public runtime events, session views, plan/todo models, and typed protocol values.
- observability
- Read-only observability and trajectory streaming handles for Merry sessions.
- paths
- Cross-platform host path conventions and shared protected-path contracts.
- permissions
- Runtime permission admission, human review channels, and path-access rules.
- process
- Host-process execution backend and workspace sandbox entrypoints.
- profiles
- Runtime profile components.
- providers
- Provider components for Merry runtime construction.
- tools
- Typed tool construction and declaration contracts for Rust applications.
Structs§
- After
Model Step Context - Read-only context supplied to an
after_model_stephook. - After
Tool Call Context - Read-only context supplied to an
after_tool_callhook. - Agent
- High-level semantic agent handle for one session.
- Agent
Builder - Builder for a high-level semantic Merry agent.
- Agent
Event Stream - Single-consumer event-only stream for a non-interactive agent run.
- Agent
Loop Config - Configuration for
crate::Runtime::run_agent_loop. - Agent
Profile Context - Mutable SDK-owned construction context supplied to an
AgentProfile. - Archive
Config - Configuration for
HistoryRetention::Archive. - Before
Model Step Context - Read-only context supplied to a
before_model_stephook. - Before
Tool Call Context - Read-only context supplied to a
before_tool_callhook. - Citation
Compaction Policy - Summary acceptance limits and preferred raw-history retention.
- Compaction
Config - Runtime-owned policy for checkpoint compaction.
- Compaction
Outcome - Compaction
Prompt - Optional prompt customization for automatic and manual compaction requests.
- File
Session Store - File-backed session storage. Durable session facts append directly to
journal.jsonl. - Final
Output - Structured final output recorded by the runtime.
- Generation
Config - Provider-neutral generation controls.
- Hook
Invocation - One pending host-bridged hook invocation awaiting a decision.
- Hook
Invocation Id - Runtime-assigned identifier for one host-bridged hook invocation.
- Hook
Registry - Composable in-process Rust hook registry with middleware chaining and short-circuiting.
- Hook
Subscriptions - Declarative set of hook points and tool filters active for a handler or bridge.
- Interactive
Event Stream - Single-consumer interactive output stream.
- Interactive
Primary Model - Provider-neutral model selection for subsequent interactive requests.
- Interactive
Process Execution Update - Replacement local-workspace process execution lane for subsequent tool actions in an active interactive run.
- Interactive
Run - Interactive run handle composed from runtime-owned input, control, and output capabilities.
- Interactive
Settings Update - Runtime settings applied by an interactive run at the next model-request boundary.
- Model
Name - Provider model identifier.
- Model
Retry Policy - Provider-neutral retry policy for one model turn.
- Prompt
Block - One stable provider-neutral prompt block supplied by a higher-level policy.
- Prompt
Profile - Stable prompt material and its runtime placement contract.
- Queued
Input Id - Stable runtime-assigned identifier for one pending interactive input.
- Reasoning
Effort - Provider-neutral reasoning-effort value.
- RunResult
- Completed or policy-stopped high-level run result.
- Session
Id - Validated SessionId newtype.
- Structured
Agent Event Stream - Structured-output variant of
AgentEventStream. - Structured
Output Retry Policy - Retry policy for application-level structured final-output decoding.
- Structured
RunResult - Structured-output variant of
RunResult. - Tool
- A typed application tool executed by the Merry runtime.
- Tool
Call Arguments - JSON object arguments supplied with a pending tool call.
- Tool
Name - Provider-portable tool name.
- Tool
Spec - Provider-neutral tool specification.
Enums§
- After
Model Decision - Decision returned by an
after_model_stephook. - After
Tool Decision - Decision returned by an
after_tool_callhook. - Agent
Build Error - Failure while constructing a high-level
crate::Agent. - Agent
Error - Failure while starting or completing a high-level agent operation.
- Agent
Loop Blocked Reason - Reasons a loop can stop without final model completion.
- Agent
Loop Config Error - Invalid agent loop configuration.
- Agent
Loop Status - Terminal or blocked status for an agent loop run.
- Agent
Profile Error - Failure while an application profile configures the SDK-owned context.
- Before
Model Decision - Decision returned by a
before_model_stephook. - Before
Tool Decision - Decision returned by a
before_tool_callhook. - Compaction
Error - Context
Window Source - Source used to resolve a model context window.
- History
Retention - Policy governing how compacted session history is retained in memory and on disk.
- Hook
Decision - Typed hook decision returned over the host bridge.
- Hook
Error - Errors produced by hook execution or invalid hook decisions.
- Hook
Point - Lifecycle boundary where a runtime hook can intercept execution.
- Hook
Request - Typed hook request payload sent over the host bridge when subscribed.
- Interrupt
Reason - Parallel
Tool Calls - Provider-neutral preference for model-generated parallel tool calls.
- Prompt
Error - Invalid typed prompt composition.
- Runtime
Event - SDK-facing runtime event.
- Runtime
Model Role - Runtime model role for a configured provider/model pair.
- Service
Tier - Provider service tier selecting request processing priority and pricing.
- Tool
Build Error - Errors raised while constructing a typed application tool.
- Tool
Hook Filter - Filter selecting which tools trigger a tool-level hook point.
- Tool
Output - Complete public text or JSON output for a tool result.
Constants§
- AUTO_
COMPACT_ THRESHOLD_ PERCENT - Share of the dynamic body budget that starts automatic compaction.
- FINAL_
OUTPUT_ TOOL_ NAME - Reserved provider-visible tool name used for structured terminal output.
Traits§
- Agent
Profile - Application-level composition and loop policy for a Merry agent.
- Model
Provider - Object-safe Merry model provider boundary.
- Runtime
Hook Handler - Object-safe async hook handler evaluated in-process by the Rust runtime.
Functions§
- coding_
agent_ loop_ config - Returns the shared default coding-agent loop configuration.
- generic_
agent_ loop_ config - Returns the default agent-loop config for generic embedded SDK usage.
Type Aliases§
- Hook
Future - Boxed async future returned by object-safe runtime hook handlers.
- Interactive
Control - Stable facade alias for the interactive control handle.
- Interactive
Input - Stable facade alias for the interactive input handle.
- Interactive
Input Item - Stable facade alias for an accepted interactive input item.
- Interactive
Input Snapshot - Stable facade alias for an interactive input snapshot.
Attribute Macros§
- tool
- Declares a typed Merry tool handler or input definition.