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::normalize_tool_name;
pub use agent::Agent;
pub use agent::Event;
pub use agent::ToolCall;
pub use agent::ToolContext;
pub use agent::ToolDefinition;
pub use agent::ToolEffect;
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 compaction::apply_compaction;
pub use compaction::compact_messages;
pub use compaction::CompactionConfig;
pub use compaction::CompactionMarker;
pub use compaction::CompactionResult;
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 extract::extract_knowledge_loose;
pub use extract::extract_proactive_loose;
pub use extract::parse_knowledge;
pub use extract::parse_proactive;
pub use extract::ExtractedKnowledge;
pub use extract::ProactiveItem;
pub use guardrails::classify_tool;
pub use guardrails::GuardrailConfig;
pub use guardrails::GuardrailDecision;
pub use guardrails::SelfHealingRetry;
pub use guardrails::ToolClass;
pub use guardrails::ToolGuardrails;
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 model_router::ModelRouter;
pub use model_router::ModelRouterError;
pub use model_router::ModelTier;
pub use model_router::ProactiveMonitor;
pub use model_router::RouterConfig;
pub use model_router::SkillSuggestion;
pub use model_router::SubagentModelSelector;
pub use model_router::TaskTier;
pub use model_router::TaskType;
pub use models::CompatConfig;
pub use models::ModelInfo;
pub use models::ModelRegistry;
pub use multiagent::CoordinatorEvent;
pub use multiagent::AgentProfile;
pub use multiagent::AgentRole;
pub use multiagent::MultiAgentCoordinator;
pub use multiagent::MultiAgentError;
pub use multiagent::TeamResult;
pub use multiagent::TeamTask;
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::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::Decision;
pub use permissions::PermissionMode;
pub use permissions::Policy;
pub use permissions::PolicyAuthorizer;
pub use permissions::ShellNode;
pub use permissions::ShellSimple;
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 ranking::rank;
pub use ranking::rank_with_query;
pub use ranking::top_n;
pub use repomap::RepoMap;
pub use repomap::RepoMapError;
pub use rollout::RolloutEntry;
pub use rollout::RolloutManager;
pub use rollout::TraceWriter;
pub use routing::AgentRoute;
pub use routing::AgentRouter;
pub use routing::RoutingConfig;
pub use routing::RoutingStats;
pub use routing::SmartRouter;
pub use routing::TurnComplexity;
pub use sandbox::detect_sandbox;
pub use sandbox::OsSandbox;
pub use sandbox::OsSandboxConfig;
pub use sandbox::OsSandboxRunner;
pub use sandbox::SandboxConfig;
pub use sandbox::SandboxError;
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 slash::help_text as slash_help_text;
pub use slash::parse as parse_slash;
pub use slash::Command as SlashCommand;
pub use sse::SseError;
pub use sse::SseEvent;
pub use sse::SseParser;
pub use subagent::SubagentConfig;
pub use subagent::SubagentError;
pub use subagent::SubagentHandle;
pub use subagent::SubagentManager;
pub use subagent::SubagentResult;
pub use subagent::SubagentStatus;
pub use tools::register_builtin_tools;
pub use tools::register_spawn_agent_tool;
pub use work_pack::WorkPack;
pub use work_pack::WorkPackError;
pub use acp::AcpHost;
pub use acp::AcpSession;
pub use marketplace::verify_plugin_integrity;
pub use marketplace::InstalledPlugin;
pub use marketplace::MarketplaceError;
pub use marketplace::MarketplaceIndex;
pub use marketplace::McpServerConfig;
pub use marketplace::McpTransportKind;
pub use marketplace::PluginBlocklist;
pub use marketplace::PluginInstaller;
pub use marketplace::PluginManifest;
pub use lsp::Diagnostic;
pub use lsp::DiagnosticSeverity;
pub use lsp::Location;
pub use lsp::LspManager;
pub use lsp::LspServer;

Modules§

acp
ACP (Agent Client Protocol) host — JSON-RPC session surface over an embedded agent.
agent
Agent loop: event-driven turn cycling with tool execution, permissions, scopes, cancellation, caching, and parallel tool dispatch.
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).
extract
Structured extraction: JSON contracts for knowledge/proactive extraction.
guardrails
Guardrails: empty-turn detection, repeated tool failure, loop hygiene, bounded tool recursion, abort signaling, and tool effect batching.
hooks
Lifecycle hooks: real async dispatch with parking_lot (grok pattern).
ipc
JSON-RPC IPC server over Unix socket.
lsp
LSP client manager — JSON-RPC 2.0 over stdio with Content-Length framing.
marketplace
Marketplace: plugin discovery, installation, and lifecycle management.
mode
Work scopes (not named agents). Profiles shape tools, policy, and prompt tone.
model_router
Intelligent model routing: map task tiers to model preferences, with prompt heuristics, fallback resolution, and low-power proactive monitoring inspired by Hermes/omi.
models
Model registry: built-in model metadata, user overrides, capability detection, and per-provider compatibility configuration.
multiagent
Multi-agent coordination: role-based agent profiles, team spawning, and an optional in-memory event bus.
permissions
Permissions: policy modes, allow/deny lists, host Approver / Authorizer (pi beforeToolCall).
plugin
Plugin registry: host extension points loaded from marketplace installs.
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.
ranking
Proactive ranking: score and rank items by relevance.
repomap
Repository map: structural summary of a codebase ranked by importance.
rollout
Rollout persistence: durable JSONL event logging with buffered I/O.
routing
Smart routing: classify each user turn as simple or strong and route to different models (OpenClaude pattern), plus per-agent model routing.
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).
slash
Slash command parser.
sse
Optimized SSE (Server-Sent Events) parser.
subagent
Subagent: isolated agent execution contexts with optional git worktree isolation.
tools
Built-in coding tools: read, write, edit, bash, grep, find, ls + extended tools. Uses rayon for parallel search (grok pattern).
work_pack
Specialist work packs as markdown data (not hard-coded agent names).

Constants§

VERSION

Functions§

print_banner