Skip to main content

Crate rx4

Crate rx4 

Source
Expand description

rx4 — the agent harness engine.

Models write. rx4 gives them tools, memory, loops, permissions, sessions, and control planes. Hosts (CLIs, TUIs, IDEs) embed rx4.

§Safety

This crate is #![forbid(unsafe_code)] — no unsafe code is allowed anywhere.

use rx4::Agent;

let mut agent = Agent::new();
agent.set_scope(rx4::Scope::Coding);
agent.prompt("fix the failing test").await?;

Re-exports§

pub use agent::is_planning_content;
pub use agent::normalize_tool_name;
pub use agent::wipe_planning_tokens;
pub use agent::Agent;
pub use agent::AgentBudget;
pub use agent::CacheAudit;
pub use agent::CacheDivergence;
pub use agent::Event;
pub use agent::GateResult;
pub use agent::MemoryRecall;
pub use agent::PatchHunkNotice;
pub use agent::PermissionAsk;
pub use agent::QualityGateConfig;
pub use agent::RecoveryKind;
pub use agent::SemanticEmbedder;
pub use agent::SemanticRecallConfig;
pub use agent::ToolCall;
pub use agent::ToolContext;
pub use agent::ToolDefinition;
pub use agent::ToolEffect;
pub use agent::ToolErrorKind;
pub use agent::ToolExecuteBox;
pub use agent::ToolExecuteFn;
pub use agent::ToolExecutor;
pub use agent::ToolFuture;
pub use agent::ToolRegistry;
pub use agent::ToolResult;
pub use agent::TurnEndMetadata;
pub use avo::commit_if_better;
pub use avo::is_protected_branch;
pub use avo::lineage_p_t;
pub use avo::objective_f;
pub use avo::CommitDecision;
pub use avo::LineageScore;
pub use avo::StallDetector;
pub use capsule::ContextCapsule;
pub use cassette::detect_divergence;
pub use cassette::detect_tool_divergence;
pub use cassette::simulate_tool;
pub use cassette::CassetteTurn;
pub use cassette::Divergence;
pub use cassette::ReplayProvider;
pub use compaction::apply_compaction;
pub use compaction::compact_messages;
pub use compaction::compact_messages_semantically;
pub use compaction::project_compact;
pub use compaction::prune_messages;
pub use compaction::CompactionConfig;
pub use compaction::CompactionMarker;
pub use compaction::CompactionResult;
pub use compaction::PrefixShape;
pub use compaction::ProjectionResult;
pub use compaction::ProjectionStep;
pub use compaction::RavenArchive;
pub use context::compose_system_prompt;
pub use context::load_project_instructions;
pub use context::ProjectInstructions;
pub use cost::CostEntry;
pub use cost::ModelPricing;
pub use cost::PricingRegistry;
pub use cost::SessionCost;
pub use cost::TokenUsage;
pub use guardrails::classify_tool;
pub use guardrails::reclassify_effect;
pub use guardrails::recover_empty_turn;
pub use guardrails::recover_stuck_tool;
pub use guardrails::schedule_tool_calls;
pub use guardrails::GuardrailConfig;
pub use guardrails::GuardrailDecision;
pub use guardrails::RecoveryAction;
pub use guardrails::SelfHealingRetry;
pub use guardrails::ToolClass;
pub use guardrails::ToolGuardrails;
pub use hashline::apply as apply_hashline;
pub use hashline::format_read as format_hashline_read;
pub use hashline::tag_for as hashline_tag_for;
pub use hashline::HashlineError;
pub use hashline::HashlineSight;
pub use hashline::HunkCheckpoint;
pub use hashline::HunkLog;
pub use hashline::ModelFamily as HashlineModelFamily;
pub use hashline::ParseMode as HashlineParseMode;
pub use hashline::ReadOptions as HashlineReadOptions;
pub use hashline::RewindError;
pub use hashline::RewindMode;
pub use hashline::TaggedRead;
pub use hashline::VisibleSet;
pub use hooks::HookDecision;
pub use hooks::HookEvent;
pub use hooks::HookFn;
pub use hooks::HookRegistry;
pub use mode::Profile;
pub use mode::Scope;
pub use models::CompatConfig;
pub use models::ModelBinding;
pub use models::ModelInfo;
pub use models::ModelRegistry;
pub use permissions::authorize;
pub use permissions::authorize_with_workspace;
pub use permissions::command_from_args;
pub use permissions::is_dangerous_shell_command;
pub use permissions::is_process_tool;
pub use permissions::is_read_only_tool;
pub use permissions::is_write_tool;
pub use permissions::path_outside_workspace;
pub use permissions::shell_argv;
pub use permissions::shell_ast;
pub use permissions::shell_command_allowed;
pub use permissions::shell_command_matches_all;
pub use permissions::shell_command_matches_any;
pub use permissions::shell_rule_matches;
pub use permissions::shell_segments;
pub use permissions::shell_simples;
pub use permissions::AlwaysAllow;
pub use permissions::AlwaysApprovePlan;
pub use permissions::AlwaysDeny;
pub use permissions::ApprovalRequest;
pub use permissions::Approver;
pub use permissions::AsyncApprover;
pub use permissions::Authorizer;
pub use permissions::ChannelApprover;
pub use permissions::ChannelAsyncApprover;
pub use permissions::ChannelPlanApprover;
pub use permissions::Decision;
pub use permissions::ExecPrefixRule;
pub use permissions::GuardianAuthorizer;
pub use permissions::GuardianReview;
pub use permissions::PermissionMode;
pub use permissions::PlanApprover;
pub use permissions::PlanDecision;
pub use permissions::PlanProposal;
pub use permissions::Policy;
pub use permissions::PolicyAuthorizer;
pub use permissions::ShellNode;
pub use permissions::ShellSimple;
pub use permissions::WorktreeAuthorizer;
pub use permissions::WorktreeClaim;
pub use permissions::WritePathSchedule;
pub use prewalk::is_mutating_call;
pub use prewalk::Prewalk;
pub use prompt_cache::apply_cache_control;
pub use prompt_cache::CachePoint;
pub use prompt_cache::CachePosition;
pub use prompt_cache::CacheProvider;
pub use prompt_cache::CacheStats;
pub use prompt_cache::CacheStatsTracker;
pub use prompt_cache::CacheTtl;
pub use prompt_cache::PromptCacheConfig;
pub use provider::Message;
pub use provider::Provider;
pub use provider::ProviderRegistry;
pub use provider::Role;
pub use provider::StreamEvent;
pub use repomap::RepoMap;
pub use repomap::RepoMapError;
pub use rollout::RolloutEntry;
pub use rollout::RolloutManager;
pub use rollout::TraceWriter;
pub use sandbox::detect_sandbox;
pub use sandbox::escalate_on_deny;
pub use sandbox::OsSandbox;
pub use sandbox::OsSandboxConfig;
pub use sandbox::OsSandboxRunner;
pub use sandbox::SandboxConfig;
pub use sandbox::SandboxError;
pub use sandbox::SandboxLayer;
pub use sandbox::SandboxManager;
pub use sandbox::SandboxProfile;
pub use sandbox::SandboxViolation;
pub use secrets::filter_env_vars;
pub use secrets::is_sensitive_env_var;
pub use secrets::RedactionConfig;
pub use secrets::Redactor;
pub use secrets::SecretMatch;
pub use secrets::SecretPattern;
pub use session::Session;
pub use session::SessionProjection;
pub use shadow_git::ShadowGit;
pub use shadow_git::ShadowGitError;
pub use slash::help_text as slash_help_text;
pub use slash::parse as parse_slash;
pub use slash::Command as SlashCommand;
pub use snapshot::FileSnapshot;
pub use snapshot::FileVersionGuard;
pub use snapshot::SnapshotStore;
pub use subagent::SubagentBudget;
pub use subagent::SubagentConfig;
pub use subagent::SubagentError;
pub use subagent::SubagentEvent;
pub use subagent::SubagentHandle;
pub use subagent::SubagentLimits;
pub use subagent::SubagentManager;
pub use subagent::SubagentResult;
pub use subagent::SubagentStatus;
pub use subagent::SubagentSubscriber;
pub use subtask::claim_complete;
pub use subtask::ClaimOutcome;
pub use subtask::Evidence;
pub use subtask::EvidenceLedger;
pub use subtask::HostAdjudication;
pub use subtask::Subtask;
pub use subtask::SubtaskClaim;
pub use subtask::SubtaskStatus;
pub use todo::TodoConfig;
pub use todo::TodoItem;
pub use todo::TodoState;
pub use todo::TodoStatus;
pub use tools::exec::ExecOutput;
pub use tools::exec::ExecProcess;
pub use tools::exec::ExecRegistry;
pub use tools::spill::SpillNotice;
pub use tools::spill::SpillStatus;
pub use tools::spill::SpilledResult;
pub use tools::register_apply_patch_tool;
pub use tools::register_builtin_tools;
pub use tools::register_complete_subtask_tool;
pub use tools::register_spawn_agent_tool;

Modules§

agent
Agent loop: event-driven turn cycling with tool execution, permissions, scopes, cancellation, caching, and parallel tool dispatch.
avo
AVO helpers: scored lineage, two-part objective, commit-if-better, stall.
capsule
cassette
compaction
Semantic context compaction: token estimation, compaction markers, and oldest-first message removal that preserves the system prompt and a recent token window.
config
Configuration: load config from file + env.
context
Context: project instruction files (AGENTS.md), system prompt composition, compaction.
cost
Cost tracking per-model and per-session (Crush pattern).
guardrails
Guardrails: empty-turn detection, repeated tool failure, loop hygiene, bounded tool recursion, abort signaling, and tool effect batching.
hashline
Hashline edit protocol: tagged reads and fail-closed PUT/CUT/MV/REM.
hooks
Lifecycle hooks: real async dispatch with parking_lot (grok pattern).
mode
Work scopes (not named agents). Profiles shape tools, policy, and prompt tone.
models
Consumer-supplied model metadata and provider compatibility.
permissions
Permissions: policy modes, allow/deny lists, host Approver / Authorizer (pi beforeToolCall).
prewalk
Prewalk / plan-yolo: investigate on the big model, apply on smol.
prompt_cache
Prompt caching support for Anthropic and OpenAI providers.
provider
Provider abstraction with async streaming (pi_agent_rust pattern). Real SSE streaming via reqwest + eventsource-stream.
repomap
Repository map: structural summary of a codebase ranked by importance.
rollout
Rollout persistence: durable JSONL event logging with buffered I/O.
sandbox
Sandbox: userspace filesystem, command, and environment validation layer.
secrets
Secrets: detection and redaction of common credential patterns in text and environment variables.
session
Session: conversation tree with fork/merge/persist (JSONL).
shadow_git
Per-turn shadow-git checkpoints. The user’s .git is never touched.
slash
Slash command parser.
snapshot
Pre-edit file snapshots and observed-file version guards (not git).
subagent
Subagent: isolated agent execution contexts with optional git worktree isolation.
subtask
todo
Session-scoped task tracking with confidence-gated completion.
tools
Built-in coding tools: read, write, edit, bash, grep, find, ls + extended tools. Uses fff for fast indexed file search.

Constants§

VERSION