pub struct RuntimeBuilder { /* private fields */ }Expand description
Builder for a Merry runtime.
The builder wires provider-neutral runtime configuration: event buffering,
one optional model provider, and zero or more runtime-owned tool executors.
Provider integrations stay outside this crate behind ModelProvider.
Implementations§
Source§impl RuntimeBuilder
impl RuntimeBuilder
Sourcepub fn permission_actor(self, actor: PermissionActor) -> Self
pub fn permission_actor(self, actor: PermissionActor) -> Self
Sets the actor identity attached to outgoing host permission review requests.
Sourcepub fn event_buffer_size(self, event_buffer_size: NonZeroUsize) -> Self
pub fn event_buffer_size(self, event_buffer_size: NonZeroUsize) -> Self
Sets the bounded event channel buffer size.
Runtime event production uses a bounded channel. Capacity counts internal emission batches rather than individual public events, so one slot may carry consecutive events whose state must be committed and enqueued together. Backpressure is part of the state-before-event contract: producers reserve a batch slot before mutating durable session state for the corresponding events.
Sourcepub fn max_parallel_tool_calls(self, limit: NonZeroUsize) -> Self
pub fn max_parallel_tool_calls(self, limit: NonZeroUsize) -> Self
Sets the maximum number of adjacent parallel-safe calls executed together.
Sourcepub fn prompt_cache_key(self, prompt_cache_key: SessionId) -> Self
pub fn prompt_cache_key(self, prompt_cache_key: SessionId) -> Self
Overrides the deterministic provider prompt-cache key used for model requests in this runtime.
When omitted, model requests default to this runtime’s own session_id.
Child runtimes use this to share a deterministic cache partition across
sibling subagents running the same role under one parent session.
Sourcepub fn model_provider(
self,
provider: Arc<dyn ModelProvider>,
model: ModelName,
) -> Self
pub fn model_provider( self, provider: Arc<dyn ModelProvider>, model: ModelName, ) -> Self
Sets the provider and model used by runtime steps.
The provider receives normalized model requests and returns normalized
model events from merry-llm. Provider response formats are not stored
in runtime state.
Sourcepub fn model_provider_for_role(
self,
role: RuntimeModelRole,
provider: Arc<dyn ModelProvider>,
model: ModelName,
) -> Self
pub fn model_provider_for_role( self, role: RuntimeModelRole, provider: Arc<dyn ModelProvider>, model: ModelName, ) -> Self
Sets the provider and model for a runtime model role.
Only RuntimeModelRole::Primary is used by normal runtime steps today.
Non-primary roles are stored as runtime-owned configuration for future
review gates and do not alter provider request compilation.
Sourcepub fn model_provider_for_role_with_reasoning(
self,
role: RuntimeModelRole,
provider: Arc<dyn ModelProvider>,
model: ModelName,
reasoning_effort: Option<ReasoningEffort>,
) -> Self
pub fn model_provider_for_role_with_reasoning( self, role: RuntimeModelRole, provider: Arc<dyn ModelProvider>, model: ModelName, reasoning_effort: Option<ReasoningEffort>, ) -> Self
Sets the provider, model, and optional reasoning-effort override for a runtime model role.
Sourcepub fn model_provider_for_role_with_retry(
self,
role: RuntimeModelRole,
provider: Arc<dyn ModelProvider>,
model: ModelName,
retry_policy: ModelRetryPolicy,
) -> Self
pub fn model_provider_for_role_with_retry( self, role: RuntimeModelRole, provider: Arc<dyn ModelProvider>, model: ModelName, retry_policy: ModelRetryPolicy, ) -> Self
Sets the provider, model, and retry policy for a runtime model role.
This is useful for higher-level construction layers that treat provider
config as a component. Unlike RuntimeBuilder::model_retry_policy,
this method does not alter already configured providers.
Sourcepub fn model_retry_policy(self, policy: ModelRetryPolicy) -> Self
pub fn model_retry_policy(self, policy: ModelRetryPolicy) -> Self
Sets the retry policy applied to configured and subsequently configured model providers.
Sourcepub fn automatic_compaction(self, config: CompactionConfig) -> Self
pub fn automatic_compaction(self, config: CompactionConfig) -> Self
Sets the runtime policy for automatic compaction.
Automatic compaction runs only when a compiled provider request crosses the compaction threshold. The current step input is still outside the compaction input and is projected raw after any installed checkpoint.
Sourcepub fn context_window_tokens(self, tokens: NonZeroU64) -> Self
pub fn context_window_tokens(self, tokens: NonZeroU64) -> Self
Sets an explicit context-window override in tokens for budget and compaction calculations.
Sourcepub fn hooks(self, handler: Arc<dyn RuntimeHookHandler>) -> Self
pub fn hooks(self, handler: Arc<dyn RuntimeHookHandler>) -> Self
Installs an in-process Rust lifecycle hook handler.
Sourcepub fn bridge_hook_subscriptions(self, subscriptions: HookSubscriptions) -> Self
pub fn bridge_hook_subscriptions(self, subscriptions: HookSubscriptions) -> Self
Declares which lifecycle hook points should be bridged to the embedding host.
Hook points not present in subscriptions are never sent over the stream.
Sourcepub fn prompt_profile(self, profile: PromptProfile) -> Self
pub fn prompt_profile(self, profile: PromptProfile) -> Self
Sets the stable prompt composition used by runtime request compilation.
Sourcepub fn progress_commentary(self, enabled: bool) -> Self
pub fn progress_commentary(self, enabled: bool) -> Self
Controls whether the runtime asks the model to emit brief tool-progress commentary.
Sourcepub fn register_tool(self, tool: RegisteredTool) -> Self
pub fn register_tool(self, tool: RegisteredTool) -> Self
Registers a runtime-owned tool executor.
Registering a tool makes its spec available to provider requests and
lets Runtime::execute_tool_call resolve matching pending calls. It
does not start an automatic tool loop.
Sourcepub fn tool_admission(self, admission: ToolAdmission) -> Self
pub fn tool_admission(self, admission: ToolAdmission) -> Self
Installs runtime admission for tool execution without changing the provider-visible tool catalog.
Sourcepub fn coordinator_plan_tools(self) -> Self
pub fn coordinator_plan_tools(self) -> Self
Installs the stable coordinator Plan Mode and Todo tool surface.
Sourcepub fn with_profile(self, profile: RuntimeProfile) -> Result<Self, RuntimeError>
pub fn with_profile(self, profile: RuntimeProfile) -> Result<Self, RuntimeError>
Applies a complete runtime profile while keeping this builder as the construction owner.
Sourcepub fn allow_bridge_tools(self) -> Self
pub fn allow_bridge_tools(self) -> Self
Allows bridge tools to be registered for this runtime.
Bridge handlers run in host code outside Merry-managed sandboxing. This
opt-in is separate from RuntimeCapabilities policy.
Sourcepub fn initial_context_summary(self, id: &str, text: &str) -> Self
pub fn initial_context_summary(self, id: &str, text: &str) -> Self
Reconciles deterministic runtime context without emitting observable events.
This is for startup-owned facts such as a compact project capability summary. The supplied id becomes the current construction-owned seed on both new and resumed sessions; construction seeds omitted from this builder are left untouched. It is not a substitute for runtime artifacts produced during a step, and repeated builder ids are replaced before build-time validation.
Sourcepub fn project_rules(self, project_rules: ProjectRules) -> Self
pub fn project_rules(self, project_rules: ProjectRules) -> Self
Adds explicit project rules to the cacheable stable request prefix.
This is a construction-time projection for durable project instructions
such as AGENTS.md. It does not scan the filesystem and is separate
from context summaries, ledger facts, and artifact payloads.
Sourcepub fn skill_catalog(self, skill_catalog: SkillCatalog) -> Self
pub fn skill_catalog(self, skill_catalog: SkillCatalog) -> Self
Adds available skill metadata to the cacheable stable request prefix.
This projects only SKILL.md frontmatter metadata. Full skill bodies
remain on disk and must be read through registered workspace file tools.
Sourcepub fn task_anchor(self, task_anchor: TaskAnchor) -> Self
pub fn task_anchor(self, task_anchor: TaskAnchor) -> Self
Sets the current task objective control-plane anchor.
This reserves the runtime context slot for future /task commands. It
is rendered as dynamic request context, not as project rules, ledger
projection, or ordered transcript history.
Sourcepub fn compacted_checkpoint(self, checkpoint: CompactedCheckpoint) -> Self
pub fn compacted_checkpoint(self, checkpoint: CompactedCheckpoint) -> Self
Sets compacted checkpoint context for dynamic provider requests.
This is selected by a checkpoint/compaction boundary. It does not
project ordinary ledger facts, artifact payloads, or tool-result
observations. The checkpoint is prose. Resume a real runtime checkpoint
with RuntimeBuilder::resume_from_store so its transcript and archived
tool refs are restored together.
Sourcepub fn allow_low_risk_apply_patches(self) -> Self
pub fn allow_low_risk_apply_patches(self) -> Self
Opts in to executing validated low-risk workspace patch proposals.
This keeps the default policy conservative: workspace writes remain denied unless the tool provides valid workspace patch proposal evidence and runtime construction explicitly enables this lane.
Sourcepub fn allow_permissioned_network_tools(self) -> Self
pub fn allow_permissioned_network_tools(self) -> Self
Opts in to executing registered crate::ToolActionKind::Network tools
marked with crate::RegisteredTool::with_permissioned_network_lane.
Sourcepub fn allow_low_risk_process_actions(
self,
runner: Arc<dyn ProcessRunner>,
) -> Self
pub fn allow_low_risk_process_actions( self, runner: Arc<dyn ProcessRunner>, ) -> Self
Opts in to executing validated low-risk process action proposals.
The default policy remains deny. This lane is available only for command execution proposals with provider-neutral process evidence, an injected runtime runner, and the narrow SP2 low-risk predicate.
Sourcepub fn allow_read_only_shell_process_actions(
self,
runner: Arc<dyn ProcessRunner>,
) -> Self
pub fn allow_read_only_shell_process_actions( self, runner: Arc<dyn ProcessRunner>, ) -> Self
Opts in to executing validated read-only shell wrapper proposals.
This lane is intentionally separate from the structured low-risk argv
lane. It accepts only a narrow bash/sh/zsh -c|-lc plain command
sequence classifier and requires an injected runner selected for the
shell read-only profile. It does not authorize arbitrary shell syntax.
Sourcepub fn allow_accepted_local_workspace_process_actions(
self,
admission: AcceptedLocalWorkspaceProcessAdmission,
runner: Arc<dyn ProcessRunner>,
) -> Self
pub fn allow_accepted_local_workspace_process_actions( self, admission: AcceptedLocalWorkspaceProcessAdmission, runner: Arc<dyn ProcessRunner>, ) -> Self
Opts in to executing validated local workspace effect process proposals.
Runner injection alone is not a sandbox or an authorization source. This lane requires explicit runtime construction-time admission that declares the sandbox profile and accepted local workspace process risk for the narrow classified process intent.
Sourcepub fn runtime_trust_level(self, trust_level: RuntimeTrustLevel) -> Self
pub fn runtime_trust_level(self, trust_level: RuntimeTrustLevel) -> Self
Sets the trust level used by permission request admission defaults.
Agentic/coding-agent runtimes require review by default. Trusted SDK hosts may explicitly choose host-only admission for business workflows where the host already owns the action policy.
Sourcepub fn permission_review_mode(self, mode: PermissionReviewMode) -> Self
pub fn permission_review_mode(self, mode: PermissionReviewMode) -> Self
Sets how permission requests are reviewed before execution.
Sourcepub fn permission_review_rules(self, rules: PermissionReviewRules) -> Self
pub fn permission_review_rules(self, rules: PermissionReviewRules) -> Self
Sets user-trusted custom rules for AI permission review.
Sourcepub fn session_review_guidance(self, guidance: SessionReviewGuidance) -> Self
pub fn session_review_guidance(self, guidance: SessionReviewGuidance) -> Self
Attaches a shared session-scoped human review guidance store so parent and child subagent runtimes inherit and share interactive review notes.
Sourcepub fn workspace_review_notes(self, notes: WorkspaceReviewNotes) -> Self
pub fn workspace_review_notes(self, notes: WorkspaceReviewNotes) -> Self
Attaches a shared live workspace review notes handle so parent and child subagent runtimes observe saved workspace review notes dynamically without mutating the static cacheable system prompt prefix.
Sourcepub fn permission_review_workspace_root(self, root: impl Into<PathBuf>) -> Self
pub fn permission_review_workspace_root(self, root: impl Into<PathBuf>) -> Self
Sets the workspace root used for read-only harness environment probes
(such as git status cleanliness) during AI permission review.
Sourcepub fn fully_trusted_tools(self) -> Self
pub fn fully_trusted_tools(self) -> Self
Explicitly enables fully trusted SDK/host execution for registered tools. Runtime schema validation, tool executor boundaries, sandboxing, and cancellation remain active. Proposal-based commit lifecycle checks are intentionally bypassed at this explicit trust boundary.
Sourcepub fn permission_admission_source(
self,
source: Arc<dyn PermissionAdmissionSource>,
) -> Self
pub fn permission_admission_source( self, source: Arc<dyn PermissionAdmissionSource>, ) -> Self
Installs a host-owned permission admission source.
This is used for trusted SDK hosts or tests. Agentic runtimes should
normally use the model-backed review selected from
RuntimeModelRole::ApprovalReview with primary fallback.
Sourcepub fn allow_permissioned_process_actions(
self,
runner: Arc<dyn ProcessRunner>,
) -> Self
pub fn allow_permissioned_process_actions( self, runner: Arc<dyn ProcessRunner>, ) -> Self
Opts in to executing process actions approved by request_permissions.
The runner should represent the backend/profile used for approved permission requests. Runtime admission approves only the exact planned action, while a concrete backend may retain the approved capabilities for later actions in the same runtime session.
Sourcepub fn permissioned_process_runner_factory(
self,
factory: Arc<dyn PermissionedProcessRunnerFactory>,
) -> Self
pub fn permissioned_process_runner_factory( self, factory: Arc<dyn PermissionedProcessRunnerFactory>, ) -> Self
Opts in to constructing a process runner per approved permission request.
This is the preferred path when approved capabilities must be materialized into each new action while remaining active for the current runtime session.
Sourcepub fn session_permissions(self, permissions: ProcessSessionPermissions) -> Self
pub fn session_permissions(self, permissions: ProcessSessionPermissions) -> Self
Attaches the shared session-scoped capability store used across process runners, in-process workspace tools, and runtime admission.
Sourcepub fn background_process_control(
self,
control: Arc<dyn BackgroundProcessControl>,
) -> Self
pub fn background_process_control( self, control: Arc<dyn BackgroundProcessControl>, ) -> Self
Installs the board that lists, reads, and stops background processes.
Sourcepub fn subagent_manager(self, manager: SubagentManager) -> Self
pub fn subagent_manager(self, manager: SubagentManager) -> Self
Installs a runtime-owned subagent manager for future subagent tools.
Sourcepub fn subagent_activity_hub(self, hub: Arc<SubagentActivityHub>) -> Self
pub fn subagent_activity_hub(self, hub: Arc<SubagentActivityHub>) -> Self
Reuses a runtime-owned activity hub for this runtime and its children.
Sourcepub fn subagent_parent_scope(self, scope: ChildWorkspaceScope) -> Self
pub fn subagent_parent_scope(self, scope: ChildWorkspaceScope) -> Self
Sets the effective workspace scope inherited by nested subagent tasks.
Sourcepub fn session_store(self, store: FileSessionStore) -> Self
pub fn session_store(self, store: FileSessionStore) -> Self
Installs the filesystem store used by explicit and automatic session savepoints.
Sourcepub fn session_lock(self, enabled: bool) -> Self
pub fn session_lock(self, enabled: bool) -> Self
Controls whether this runtime acquires and holds an exclusive OS-level
crate::SessionReservation lock on its configured FileSessionStore
for the lifetime of the session.
Applies to Self::build and Self::resume_from_store (and does not
affect read-only loading helpers without automatic savepoints). When
enabled, concurrent processes (and duplicate handles in the same
process) attempting to open or resume the same session_id fail fast
with crate::SessionStoreError::SessionAlreadyReserved. Call
Runtime::close to release the lock deterministically and remove an
untouched empty session directory.
Sourcepub fn history_retention(self, retention: HistoryRetention) -> Self
pub fn history_retention(self, retention: HistoryRetention) -> Self
Configures how compacted session history is retained in memory and on disk.
Sourcepub fn with_loaded_session(self, loaded: LoadedSession) -> Self
pub fn with_loaded_session(self, loaded: LoadedSession) -> Self
Installs a session that was already loaded by the runtime boundary.
Sourcepub async fn resume_from_store(
self,
store: FileSessionStore,
) -> Result<Runtime, RuntimeError>
pub async fn resume_from_store( self, store: FileSessionStore, ) -> Result<Runtime, RuntimeError>
Loads persisted session state from an injected filesystem store, then builds a runtime.
Sourcepub async fn resume_from_store_without_automatic_savepoints(
self,
store: FileSessionStore,
) -> Result<Runtime, RuntimeError>
pub async fn resume_from_store_without_automatic_savepoints( self, store: FileSessionStore, ) -> Result<Runtime, RuntimeError>
Loads persisted state without replaying or restarting Plan execution.
Sourcepub async fn load_session_from_store(
self,
store: FileSessionStore,
) -> Result<Self, RuntimeError>
pub async fn load_session_from_store( self, store: FileSessionStore, ) -> Result<Self, RuntimeError>
Loads persisted session state without enabling automatic savepoints.
Sourcepub fn durable_memory(self, memory: Arc<DurableMemory>, maintain: bool) -> Self
pub fn durable_memory(self, memory: Arc<DurableMemory>, maintain: bool) -> Self
Attaches durable memory and freezes its index for this runtime.
maintain schedules capture and one-shot dream after a completed parent
turn. Child runtimes keep the same store with maintenance disabled.
Sourcepub fn build(self) -> Result<Runtime, RuntimeError>
pub fn build(self) -> Result<Runtime, RuntimeError>
Builds the runtime.
Duplicate tool names are rejected before the runtime is constructed.
Sourcepub fn build_with_reservation(
self,
reservation: &mut Option<SessionReservation>,
) -> Result<Runtime, RuntimeError>
pub fn build_with_reservation( self, reservation: &mut Option<SessionReservation>, ) -> Result<Runtime, RuntimeError>
Builds the runtime, transferring an already-acquired exclusive
crate::SessionReservation into the constructed runtime only after
all configuration and session validation succeeds.