Skip to main content

Crate merry

Crate merry 

Source
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§

AfterModelStepContext
Read-only context supplied to an after_model_step hook.
AfterToolCallContext
Read-only context supplied to an after_tool_call hook.
Agent
High-level semantic agent handle for one session.
AgentBuilder
Builder for a high-level semantic Merry agent.
AgentEventStream
Single-consumer event-only stream for a non-interactive agent run.
AgentLoopConfig
Configuration for crate::Runtime::run_agent_loop.
AgentProfileContext
Mutable SDK-owned construction context supplied to an AgentProfile.
ArchiveConfig
Configuration for HistoryRetention::Archive.
BeforeModelStepContext
Read-only context supplied to a before_model_step hook.
BeforeToolCallContext
Read-only context supplied to a before_tool_call hook.
CitationCompactionPolicy
Summary acceptance limits and preferred raw-history retention.
CompactionConfig
Runtime-owned policy for checkpoint compaction.
CompactionOutcome
CompactionPrompt
Optional prompt customization for automatic and manual compaction requests.
FileSessionStore
File-backed session storage. Durable session facts append directly to journal.jsonl.
FinalOutput
Structured final output recorded by the runtime.
GenerationConfig
Provider-neutral generation controls.
HookInvocation
One pending host-bridged hook invocation awaiting a decision.
HookInvocationId
Runtime-assigned identifier for one host-bridged hook invocation.
HookRegistry
Composable in-process Rust hook registry with middleware chaining and short-circuiting.
HookSubscriptions
Declarative set of hook points and tool filters active for a handler or bridge.
InteractiveEventStream
Single-consumer interactive output stream.
InteractivePrimaryModel
Provider-neutral model selection for subsequent interactive requests.
InteractiveProcessExecutionUpdate
Replacement local-workspace process execution lane for subsequent tool actions in an active interactive run.
InteractiveRun
Interactive run handle composed from runtime-owned input, control, and output capabilities.
InteractiveSettingsUpdate
Runtime settings applied by an interactive run at the next model-request boundary.
ModelName
Provider model identifier.
ModelRetryPolicy
Provider-neutral retry policy for one model turn.
PromptBlock
One stable provider-neutral prompt block supplied by a higher-level policy.
PromptProfile
Stable prompt material and its runtime placement contract.
QueuedInputId
Stable runtime-assigned identifier for one pending interactive input.
ReasoningEffort
Provider-neutral reasoning-effort value.
RunResult
Completed or policy-stopped high-level run result.
SessionId
Validated SessionId newtype.
StructuredAgentEventStream
Structured-output variant of AgentEventStream.
StructuredOutputRetryPolicy
Retry policy for application-level structured final-output decoding.
StructuredRunResult
Structured-output variant of RunResult.
Tool
A typed application tool executed by the Merry runtime.
ToolCallArguments
JSON object arguments supplied with a pending tool call.
ToolName
Provider-portable tool name.
ToolSpec
Provider-neutral tool specification.

Enums§

AfterModelDecision
Decision returned by an after_model_step hook.
AfterToolDecision
Decision returned by an after_tool_call hook.
AgentBuildError
Failure while constructing a high-level crate::Agent.
AgentError
Failure while starting or completing a high-level agent operation.
AgentLoopBlockedReason
Reasons a loop can stop without final model completion.
AgentLoopConfigError
Invalid agent loop configuration.
AgentLoopStatus
Terminal or blocked status for an agent loop run.
AgentProfileError
Failure while an application profile configures the SDK-owned context.
BeforeModelDecision
Decision returned by a before_model_step hook.
BeforeToolDecision
Decision returned by a before_tool_call hook.
CompactionError
ContextWindowSource
Source used to resolve a model context window.
HistoryRetention
Policy governing how compacted session history is retained in memory and on disk.
HookDecision
Typed hook decision returned over the host bridge.
HookError
Errors produced by hook execution or invalid hook decisions.
HookPoint
Lifecycle boundary where a runtime hook can intercept execution.
HookRequest
Typed hook request payload sent over the host bridge when subscribed.
InterruptReason
ParallelToolCalls
Provider-neutral preference for model-generated parallel tool calls.
PromptError
Invalid typed prompt composition.
RuntimeEvent
SDK-facing runtime event.
RuntimeModelRole
Runtime model role for a configured provider/model pair.
ServiceTier
Provider service tier selecting request processing priority and pricing.
ToolBuildError
Errors raised while constructing a typed application tool.
ToolHookFilter
Filter selecting which tools trigger a tool-level hook point.
ToolOutput
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§

AgentProfile
Application-level composition and loop policy for a Merry agent.
ModelProvider
Object-safe Merry model provider boundary.
RuntimeHookHandler
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§

HookFuture
Boxed async future returned by object-safe runtime hook handlers.
InteractiveControl
Stable facade alias for the interactive control handle.
InteractiveInput
Stable facade alias for the interactive input handle.
InteractiveInputItem
Stable facade alias for an accepted interactive input item.
InteractiveInputSnapshot
Stable facade alias for an interactive input snapshot.

Attribute Macros§

tool
Declares a typed Merry tool handler or input definition.