### Check Prerequisites with Shell Commands Source: https://superagenticai.github.io/rlm-code/codemode/utcp Verifies the installation and availability of Node.js, npx, and rlm-code. These commands are run directly in the shell to ensure the development environment is correctly configured before proceeding with the CodeMode setup. ```shell node -v npx -v rlm-code --version ``` -------------------------------- ### Benchmark Comparison Commands Source: https://superagenticai.github.io/rlm-code/getting-started/codemode-quickstart These shell commands are used for benchmarking CodeMode implementations. They run benchmarks for both UTCP and Cloudflare setups and compare the results. ```bash /rlm bench preset=generic_smoke mode=harness strategy=codemode mcp=on mcp_server=utcp-codemode limit=1 steps=3 /rlm bench preset=generic_smoke mode=harness strategy=tool_call mcp=on mcp_server=cloudflare-codemode limit=1 steps=3 /rlm bench compare candidate=latest baseline=previous ``` -------------------------------- ### Daytona Installation and Workspace Setup (Shell) Source: https://superagenticai.github.io/rlm-code/sandbox/cloud Provides instructions for setting up the Daytona CLI and creating a workspace. This is the recommended approach for using Daytona. ```shell # Install Daytona CLI # See https://www.daytona.io/docs/installation curl -sfL https://get.daytona.io | sh # Create a workspace daytona workspace create default ``` -------------------------------- ### Install Docker on macOS Source: https://superagenticai.github.io/rlm-code/sandbox/docker Instructions for installing Docker on macOS using Homebrew. After installation, Docker Desktop needs to be opened to start the Docker daemon. ```shell brew install --cask docker # Then open Docker Desktop ``` -------------------------------- ### Install Docker on Linux Source: https://superagenticai.github.io/rlm-code/sandbox/docker Instructions for installing Docker on Linux using a curl script. It includes starting the Docker service and adding the current user to the docker group for non-root access. ```shell curl -fsSL https://get.docker.com | sh sudo systemctl start docker sudo usermod -aG docker $USER ``` -------------------------------- ### Setup Example: Interactive Development Approval Gate Source: https://superagenticai.github.io/rlm-code/security/approval-gates This example demonstrates setting up an ApprovalGate for interactive development environments. It uses a ConsoleApprovalHandler for immediate feedback and an ApprovalAuditLog for tracking decisions. ```python from rlm_code.rlm.approval import ( ApprovalGate, ApprovalPolicy, ConsoleApprovalHandler, ApprovalAuditLog, ) gate = ApprovalGate( policy=ApprovalPolicy.CONFIRM_HIGH_RISK, approval_handler=ConsoleApprovalHandler(timeout_seconds=120).handle, audit_log=ApprovalAuditLog(log_file="dev_audit.jsonl"), ) # Use in agent loop async def execute_action(action): request = gate.check_action(action) if request.requires_approval: response = await gate.request_approval(request) if not response.approved: return f"Denied: {response.reason}" return run_code(action["code"]) ``` -------------------------------- ### Demo Commands for Recording Source: https://superagenticai.github.io/rlm-code/codemode/utcp A sequence of commands to perform a short demonstration, including listing MCP servers, checking MCP tools, running a harness doctor, and executing a harness run for repository analysis. This flow is designed for creating a concise recording of the CodeMode functionality. ```shell /mcp-servers /mcp-tools utcp-codemode /harness doctor /harness run "analyze this repo, find TODO/FIXME, and create report.json" steps=3 mcp=on strategy=codemode mcp_server=utcp-codemode ``` -------------------------------- ### List Available Benchmarks Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Lists all available built-in benchmark presets for RLM Code. The output includes the preset name, number of cases, and a brief description for each. ```bash /rlm bench list ``` -------------------------------- ### Install Docker on Windows Source: https://superagenticai.github.io/rlm-code/sandbox/docker Instructions for installing Docker on Windows. This involves downloading and installing Docker Desktop. ```text Download and install Docker Desktop. ``` -------------------------------- ### Benchmark with CodeMode Strategy Source: https://superagenticai.github.io/rlm-code/codemode/utcp A command to run a benchmark test using the 'generic_smoke' preset, harness mode, CodeMode strategy, and specifying the MCP server. This is used to evaluate the performance and behavior of the CodeMode setup under specific conditions. ```shell /rlm bench preset=generic_smoke mode=harness strategy=codemode mcp=on mcp_server=utcp-codemode limit=1 steps=3 ``` -------------------------------- ### Interactive LLM Connection Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Opens an interactive, keyboard-driven picker for selecting the LLM mode, provider, and model. Run with no arguments to activate the guided picker. ```bash /connect ``` -------------------------------- ### Setup Example: CI/CD Pipeline Non-Interactive Approval Gate Source: https://superagenticai.github.io/rlm-code/security/approval-gates This example shows how to configure an ApprovalGate for CI/CD pipelines, utilizing the AutoDenyHandler to prevent any actions requiring approval in an automated environment. An ApprovalAuditLog is included for record-keeping. ```python from rlm_code.rlm.approval import ( ApprovalGate, ApprovalPolicy, AutoDenyHandler, ApprovalAuditLog, ) gate = ApprovalGate( policy=ApprovalPolicy.CONFIRM_MEDIUM_AND_UP, approval_handler=AutoDenyHandler( reason="CI/CD: risky actions not permitted" ).handle, audit_log=ApprovalAuditLog(log_file="ci_audit.jsonl"), ) ``` -------------------------------- ### Install RLM Code Documentation Tools Source: https://superagenticai.github.io/rlm-code/getting-started/installation Installs the necessary packages for building the RLM Code documentation locally. This includes `mkdocs`, `mkdocs-material`, `mkdocstrings`, and `mkdocs-minify-plugin`. ```bash uv tool install "rlm-code[docs]" ``` -------------------------------- ### Run Harness with CodeMode Strategy Source: https://superagenticai.github.io/rlm-code/codemode/utcp Executes a harness run with specific parameters including the number of steps, enabling MCP, setting the strategy to 'codemode', and specifying the MCP server. This command initiates a task for the model to inspect a repository and generate a report. ```shell /harness run "inspect this repo and create report.json with TODO/FIXME counts and top 5 improvements" steps=3 mcp=on strategy=codemode mcp_server=utcp-codemode ``` -------------------------------- ### Initialize RLM Project Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Initializes a new RLM Code project by creating an `rlm_config.yaml` file in the current directory. This command scans the project for existing files and frameworks to configure the project. ```bash /init ``` -------------------------------- ### Start Docker Daemon on macOS Source: https://superagenticai.github.io/rlm-code/getting-started/installation Starts the Docker Desktop application on macOS. This is necessary if the Docker daemon is not running and `/sandbox doctor` reports Docker as unavailable. ```bash # macOS open -a Docker ``` -------------------------------- ### Initial RLM Code Commands Source: https://superagenticai.github.io/rlm-code/getting-started/researcher-onboarding A sequence of commands to quickly get started with RLM Code, including initialization, connection, status checks, sandbox operations, running a task, and benchmarking. ```bash rlm-code /init /connect /status /sandbox profile secure /sandbox status /rlm run "Summarize this repository architecture" env=pure_rlm steps=4 /rlm bench list /rlm bench preset=dspy_quick /rlm frameworks ``` -------------------------------- ### Run DSPy Quick Benchmark Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Executes a quick DSPy smoke test benchmark, which includes 3 cases: Build Signature, Build Module, and Add Tests. This benchmark demonstrates the RLM loop: context -> action proposal -> sandbox execution -> observation -> reward -> memory update. ```bash /rlm bench preset=dspy_quick ``` -------------------------------- ### Install Docker on macOS Source: https://superagenticai.github.io/rlm-code/getting-started/installation Installs Docker Desktop on macOS using Homebrew Cask. Docker is required for the Docker runtime sandbox. ```bash # macOS brew install --cask docker ``` -------------------------------- ### Launch RLM Code TUI Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Creates a demo project directory, navigates into it, and launches the RLM Code terminal user interface. It's recommended to run RLM Code from a dedicated project directory, not your home directory. ```bash mkdir -p ~/projects/rlm-demo && cd ~/projects/rlm-demo rlm-code ``` -------------------------------- ### Connect and Verify MCP Tools in TUI Source: https://superagenticai.github.io/rlm-code/codemode/utcp Commands to initiate the rlm-code TUI, connect to MCP servers, list available MCP servers, and connect to a specific server ('utcp-codemode'). It also shows how to list the tools provided by the connected MCP server to ensure 'search_tools' and 'call_tool_chain' are present. ```shell rlm-code /connect /mcp-servers /mcp-connect utcp-codemode /mcp-tools utcp-codemode ``` -------------------------------- ### Verify Docker Installation Source: https://superagenticai.github.io/rlm-code/getting-started/installation Checks if the Docker daemon is installed and running correctly on the system. This command provides information about the Docker environment. ```bash docker info ``` -------------------------------- ### Install ADK RLM Adapter Source: https://superagenticai.github.io/rlm-code/integrations/frameworks Shows the pip command to install the ADK RLM adapter, including optional extras for Google ADK and Google GenAI. This command installs the necessary packages to run the Google ADK sample RLM implementation. ```bash pip install 'rlm-code[adk]' ``` -------------------------------- ### Daytona SDK Installation (Python) Source: https://superagenticai.github.io/rlm-code/sandbox/cloud Shows how to install the Daytona SDK using pip for programmatic access to Daytona environments. ```python pip install daytona-sdk ``` -------------------------------- ### Install LangFuse SDK (Bash) Source: https://superagenticai.github.io/rlm-code/observability/langfuse This command installs the necessary LangFuse Python SDK, which is a prerequisite for using the LangFuse sink with RLM. ```bash pip install langfuse ``` -------------------------------- ### Download Local LLM Model Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Pulls the llama3.2 model from Ollama for local use. This command requires Ollama to be installed and running. ```bash ollama pull llama3.2 ``` -------------------------------- ### Cloud Runtime SDK Installation Status Messages (Text) Source: https://superagenticai.github.io/rlm-code/sandbox/cloud Displays example messages indicating when a cloud runtime's SDK is not installed and provides the corresponding installation command. ```text SDK not installed (pip install modal) SDK not installed (pip install e2b-code-interpreter) Not installed (pip install daytona-sdk or install CLI) ``` -------------------------------- ### Complete Usage Example for ParadigmComparator Source: https://superagenticai.github.io/rlm-code/core/comparison Demonstrates the complete workflow for using ParadigmComparator, from setting up RLMRunner and loading context to running comparisons, displaying results, and accessing individual paradigm outcomes. It highlights token and cost savings. ```python from rlm_code.rlm.comparison import ParadigmComparator, Paradigm from rlm_code.rlm.runner import RLMRunner # Set up runner runner = RLMRunner( llm_connector=my_connector, execution_engine=my_engine, workdir=my_project_dir, ) # Create comparator comparator = ParadigmComparator(runner=runner) # Load a large context with open("large_document.txt") as f: context = f.read() # Run comparison result = comparator.compare( task="Summarize the key findings in this document", context=context, paradigms=[Paradigm.PURE_RLM, Paradigm.CODEACT], ground_truth="The document discusses three main findings: ...", max_steps=5, exec_timeout=120, ) # Display results print(result.format_table()) # Get winner token_winner = result.get_winner("total_tokens") cost_winner = result.get_winner("estimated_cost") print(f"Token winner: {token_winner.value}") print(f"Cost winner: {cost_winner.value}") # Detailed analysis from rlm_code.rlm.comparison import create_comparison_report print(create_comparison_report(result)) # Access individual paradigm results pure_rlm = result.results[Paradigm.PURE_RLM] codeact = result.results[Paradigm.CODEACT] print(f"Pure RLM: {pure_rlm.total_tokens} tokens, ${pure_rlm.estimated_cost:.4f}") print(f"CodeAct: {codeact.total_tokens} tokens, ${codeact.estimated_cost:.4f}") print(f"Token savings: {1 - pure_rlm.total_tokens / codeact.total_tokens:.1%}") ``` -------------------------------- ### UTCP CodeMode First Run Commands Source: https://superagenticai.github.io/rlm-code/getting-started/codemode-quickstart These shell commands initiate the UTCP CodeMode flow. They connect to the UTCP MCP server and run the harness with CodeMode strategy to inspect a repository and generate a report. ```bash /mcp-connect utcp-codemode /harness tools mcp=on /harness run "inspect this repo and create report.json with TODO/FIXME counts and top 5 improvements" steps=3 mcp=on strategy=codemode mcp_server=utcp-codemode ``` -------------------------------- ### Initialize FrameworkAdapterRegistry (Python) Source: https://superagenticai.github.io/rlm-code/integrations/frameworks Demonstrates the initialization of the `FrameworkAdapterRegistry`, which manages the registration and lookup of framework adapters. The `default()` factory method creates a registry instance with all built-in adapters pre-registered, simplifying the setup process. The `workdir` parameter is essential for initializing adapters that might require a project context. ```python from rlm_code.rlm.frameworks import FrameworkAdapterRegistry registry = FrameworkAdapterRegistry.default(workdir="/path/to/project") ``` -------------------------------- ### Example Usage of LeaderboardFilter (Python) Source: https://superagenticai.github.io/rlm-code/benchmarks/leaderboard This example demonstrates how to instantiate and use the LeaderboardFilter class to create a filter object. The filter is configured with specific environments, a minimum reward threshold, a minimum completion rate, and a start date. ```python from datetime import datetime, timezone from rlm_code.rlm.leaderboard import LeaderboardFilter filter = LeaderboardFilter( environments=["dspy", "pure_rlm"], min_reward=0.5, min_completion_rate=0.8, date_from=datetime(2025, 1, 1, tzinfo=timezone.utc), ) ``` -------------------------------- ### Install Docker on Linux (Ubuntu/Debian) Source: https://superagenticai.github.io/rlm-code/getting-started/installation Installs the Docker engine on Ubuntu or Debian-based Linux systems using apt-get. Docker is necessary for running code in isolated containers. ```bash # Linux (Ubuntu/Debian) sudo apt-get install docker.io ``` -------------------------------- ### Configure MCP Server in rlm_config.yaml Source: https://superagenticai.github.io/rlm-code/codemode/utcp Defines the configuration for the 'utcp-codemode' MCP server within the rlm_config.yaml file. This setup enables local CodeMode functionality by specifying the transport type and the command to execute the CodeMode MCP bridge. ```yaml mcp_servers: utcp-codemode: name: utcp-codemode description: "Local CodeMode MCP bridge" enabled: true auto_connect: false timeout_seconds: 30 retry_attempts: 3 transport: type: stdio command: npx args: - "@utcp/code-mode-mcp" ``` -------------------------------- ### Inspect and Run RLM Frameworks via CLI Source: https://superagenticai.github.io/rlm-code/integrations/frameworks Demonstrates how to use command-line interface commands to inspect available RLM adapters and run tasks using specific frameworks. It shows commands for listing frameworks and initiating runs with different adapter configurations. ```bash # Inspect adapter readiness /rlm frameworks # Run a task with a specific framework /rlm run Investigate memory leak framework=dspy-rlm env=generic /rlm run Build an RLM planner framework=adk-rlm env=generic /rlm chat Continue analysis framework=deepagents ``` -------------------------------- ### JSONL Trajectory Log Example Source: https://superagenticai.github.io/rlm-code/core/trajectory An example of a trajectory log file in JSONL format, showing a sequence of events for an RLM run. Each line is a JSON object representing an event like run start, reasoning, code execution, output, and run end. ```json {"event_type": "run_start", "timestamp": 1706400000.0, "run_id": "run_001", "data": {"task": "..."}} {"event_type": "iteration_reasoning", "timestamp": 1706400001.2, "run_id": "run_001", "iteration": 1, "data": {"reasoning": "..."}} {"event_type": "iteration_code", "timestamp": 1706400001.5, "run_id": "run_001", "iteration": 1, "data": {"code": "..."}} {"event_type": "iteration_output", "timestamp": 1706400002.1, "run_id": "run_001", "iteration": 1, "data": {"output": "..."}, "duration_ms": 600} {"event_type": "final_detected", "timestamp": 1706400005.0, "run_id": "run_001", "data": {"answer": "..."}} {"event_type": "run_end", "timestamp": 1706400005.1, "run_id": "run_001", "data": {"success": true}, "duration_ms": 5100} ``` -------------------------------- ### Start Docker Daemon on Linux Source: https://superagenticai.github.io/rlm-code/getting-started/installation Starts the Docker service on Linux systems using systemctl. This command is used to ensure the Docker daemon is running, especially if it's reported as unavailable. ```bash # Linux sudo systemctl start docker ``` -------------------------------- ### Compare Benchmark Results Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Compares the latest benchmark results against a previous baseline. This command is useful for tracking performance changes over time. ```bash /rlm bench compare candidate=latest baseline=previous ``` -------------------------------- ### Docker Image Examples (YAML) Source: https://superagenticai.github.io/rlm-code/sandbox/docker Illustrates different Docker image configurations for the sandbox runtime. It shows examples for a minimal Python image, a full scientific Python stack, and a custom user-defined image. ```yaml # Minimal Python (fastest pull, smallest surface) sandbox: docker: image: "python:3.11-slim" # Full scientific Python stack sandbox: docker: image: "python:3.11" # Custom image with pre-installed packages sandbox: docker: image: "myregistry/rlm-sandbox:latest" ``` -------------------------------- ### Abort All RLM Runs Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Cancels all currently running RLM tasks. Use this command if a run is going out of control or needs to be stopped. ```bash /rlm abort all ``` -------------------------------- ### Basic Setup for ApprovalGate in Python Source: https://superagenticai.github.io/rlm-code/security Demonstrates how to initialize the ApprovalGate with an audit log and a console handler for interactive approval. It sets up the necessary components for a basic approval workflow. ```python from rlm_code.rlm.approval import ( ApprovalGate, ApprovalPolicy, ConsoleApprovalHandler, ApprovalAuditLog, ) # Create audit log audit_log = ApprovalAuditLog(log_file="audit.jsonl") # Create console handler for interactive approval handler = ConsoleApprovalHandler(timeout_seconds=60) # Create approval gate gate = ApprovalGate( policy=ApprovalPolicy.CONFIRM_HIGH_RISK, approval_handler=handler.handle, audit_log=audit_log, ) ``` -------------------------------- ### Connect to OpenAI LLM Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Connects RLM Code to the OpenAI GPT-5 model. Requires the `OPENAI_API_KEY` environment variable or a `.env` file. ```bash /connect openai gpt-5.3-codex ``` -------------------------------- ### Google ADK Framework Adapter Usage in Python Source: https://superagenticai.github.io/rlm-code/integrations/frameworks Example demonstrating the usage of the GoogleADKFrameworkAdapter. It shows how to initialize the adapter, check its readiness using the `doctor` method, and run a task with specified parameters like task description, LLM connector, and model details. The output includes the completion status and the number of steps taken. ```python from rlm_code.rlm.frameworks import GoogleADKFrameworkAdapter adapter = GoogleADKFrameworkAdapter(workdir="/my/project") # Check readiness ok, detail = adapter.doctor() print(ok, detail) # True, "google-adk available" # Run a task result = adapter.run_episode( task="Analyze this dataset", llm_connector=my_connector, max_steps=5, exec_timeout=120, workdir="/my/project", sub_provider="gemini", sub_model="gemini-2.5-pro", ) print(result.completed) print(len(result.steps)) ``` -------------------------------- ### Connect to Anthropic LLM Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Connects RLM Code to the Anthropic Claude Opus model. Requires the `ANTHROPIC_API_KEY` environment variable or a `.env` file. ```bash /connect anthropic claude-opus-4-6 ``` -------------------------------- ### Abort Specific RLM Run Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Cancels a specific RLM run identified by its unique run ID. This allows for targeted cancellation of individual tasks. ```bash /rlm abort ``` -------------------------------- ### Configuration-Based Instantiation Source: https://superagenticai.github.io/rlm-code/policies/registry Creates a complete set of policy instances from a configuration dictionary, which is the recommended method for setting up policies from configuration files. ```APIDOC ## Configuration-Based Instantiation ### `create_from_config(config: dict) -> dict` #### Description Creates a complete set of policy instances from a configuration dictionary. This is the preferred method for setting up policies from configuration files. #### Method `PolicyRegistry.create_from_config(config: dict)` #### Parameters - **`config`** (dict) - Required - A dictionary defining the policies to instantiate. The structure should follow the schema: ``` { "": { "name": str, # Registered policy name (e.g., "reward", "action") "config": dict, # Optional: policy-specific configuration }, ... } ``` Supported categories include: "reward", "action", "compaction", "termination". #### Request Example (Full Configuration) ```python policies = PolicyRegistry.create_from_config({ "reward": { "name": "research", "config": { "base_success": 0.4, "fast_execution_bonus": 0.1, }, }, "action": { "name": "sampling", "config": { "temperature": 0.7, }, }, "compaction": { "name": "hierarchical", "config": { "recent_window": 5, }, }, "termination": { "name": "composite", "config": { "policies": ["final_pattern", "reward_threshold"], "require_all": False, }, }, }) ``` #### Request Example (Partial Configuration) ```python # Only customize reward and action policies = PolicyRegistry.create_from_config({ "reward": {"name": "strict"}, "action": {"name": "mcts"}, }) # Result: policies = {"reward": StrictRewardPolicy(), "action": MCTSActionPolicy()} # No "compaction" or "termination" keys ``` #### Response - **Success Response (200)** - **`policies`** (dict) - A dictionary containing instantiated policy objects, keyed by category (e.g., `policies["reward"]`). #### Response Example ```json { "reward": , "action": , "compaction": , "termination": } ``` #### YAML Configuration Example ```yaml # rlm_policies.yaml reward: name: research config: base_success: 0.4 base_failure: 0.3 fast_execution_bonus: 0.1 step_penalty_per_step: 0.02 action: name: sampling config: temperature: 0.7 min_probability: 0.05 compaction: name: llm config: max_entries_before_compact: 15 preserve_last_n: 3 summary_max_tokens: 300 termination: name: final_pattern config: case_sensitive: false extract_answer: true ``` #### Usage with YAML ```python import yaml from rlm_code.rlm.policies import PolicyRegistry with open("rlm_policies.yaml") as f: config = yaml.safe_load(f) policies = PolicyRegistry.create_from_config(config) ``` ``` -------------------------------- ### Cloudflare CodeMode First Run Commands Source: https://superagenticai.github.io/rlm-code/getting-started/codemode-quickstart These shell commands initiate the Cloudflare CodeMode flow. They connect to the Cloudflare MCP server, list available tools, and run a safe read-only action, summarizing the results. ```bash /mcp-connect cloudflare-codemode /mcp-tools cloudflare-codemode /harness run "list available tools and run one safe read-only action, then summarize in 3 bullets" steps=3 mcp=on strategy=tool_call mcp_server=cloudflare-codemode ``` -------------------------------- ### LLMConnector Usage Tracking Example Source: https://superagenticai.github.io/rlm-code/integrations/llm-providers Illustrates how to track token usage with the LLMConnector. It shows how to get a snapshot before and after a task, and then calculate the difference to understand resource consumption. ```python # Before a task before = connector.usage_snapshot() # Run task... response = connector.generate_response("Explain this code") # After after = connector.usage_snapshot() delta = LLMConnector.usage_delta(before, after) print(delta) # {"total_calls": 1, "prompt_tokens": 150, "completion_tokens": 300} ``` -------------------------------- ### Install and Authenticate E2B SDK Source: https://superagenticai.github.io/rlm-code/sandbox/cloud Steps to set up the E2B environment, including installing the necessary SDK and configuring the API key, which can be done via an environment variable. ```shell # 1. Install the SDK pip install e2b-code-interpreter # 2. Set your API key export E2B_API_KEY=your_api_key_here ``` -------------------------------- ### Generate Benchmark Report Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Generates a report comparing the latest benchmark results against a previous baseline, formatted as Markdown. This provides a detailed analysis of benchmark performance. ```bash /rlm bench report candidate=latest baseline=previous format=markdown ``` -------------------------------- ### Create Policies from Configuration - Python Source: https://superagenticai.github.io/rlm-code/policies/registry Shows how to instantiate reward, action, and termination policies using a configuration dictionary. This allows for flexible and dynamic policy setup based on external configurations. ```python policies = PolicyRegistry.create_from_config({ "reward": { "name": "weighted_components", "config": { "weights": {"success": 1.5, "speed": 0.8}, "speed_threshold_ms": 500, }, }, "action": {"name": "greedy"}, "termination": {"name": "final_pattern"}, }) ``` -------------------------------- ### Connect to Gemini LLM Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Connects RLM Code to the Google Gemini 2.5 Flash model. Requires the `GEMINI_API_KEY` or `GOOGLE_API_KEY` environment variable or a `.env` file. ```bash /connect gemini gemini-2.5-flash ``` -------------------------------- ### RLM Runner Quick Start Source: https://superagenticai.github.io/rlm-code/core Demonstrates how to initialize and use the RLMRunner to execute a task. It requires a language model connector, an execution engine, and a working directory. The runner executes a given task within a specified environment and returns the completion status, final response, steps taken, and total reward. ```python from rlm_code.rlm.runner import RLMRunner runner = RLMRunner( llm_connector=my_connector, execution_engine=my_engine, workdir=Path("/my/project"), ) result = runner.run_task( task="Analyze the codebase and find all TODO comments", environment="pure_rlm", max_steps=5, ) print(f"Completed: {result.completed}") print(f"Answer: {result.final_response}") print(f"Steps: {result.steps}, Reward: {result.total_reward}") ``` -------------------------------- ### Install and Authenticate Modal SDK Source: https://superagenticai.github.io/rlm-code/sandbox/cloud Instructions for setting up the Modal environment. This includes installing the Modal SDK using pip and authenticating the user with the Modal service. ```shell # 1. Install the SDK pip install modal # 2. Authenticate modal setup ``` -------------------------------- ### Complete Usage Example: TrajectoryLogger and TrajectoryViewer Source: https://superagenticai.github.io/rlm-code/core/trajectory Imports the necessary classes, TrajectoryLogger and TrajectoryViewer, from the rlm_code.rlm.trajectory module. This is the starting point for using the trajectory logging and viewing functionalities. ```python from rlm_code.rlm.trajectory import TrajectoryLogger, TrajectoryViewer ``` -------------------------------- ### End-to-End Memory Compaction Example in Python Source: https://superagenticai.github.io/rlm-code/core/memory-compaction This example demonstrates the full lifecycle of memory compaction. It shows how to configure the MemoryCompactor, simulate REPL history, check if compaction is needed, perform compaction, and apply the results. It highlights the reduction in entries after compaction. ```python from rlm_code.rlm.memory_compaction import ( MemoryCompactor, CompactionConfig, ConversationMemory, ) from rlm_code.rlm.repl_types import REPLHistory # 1. Configure compaction config = CompactionConfig( max_entries_before_compaction=8, max_chars_before_compaction=5000, preserve_last_n_entries=2, summary_max_sentences=2, use_llm_for_summary=False, # Deterministic for this example ) # 2. Create compactor compactor = MemoryCompactor(config=config) # 3. Simulate REPL history building history = REPLHistory() for i in range(10): history = history.append( reasoning=f"Step {i}: analyzing chunk {i}", code=f"result_{i} = analyze(chunks[{i}])", output=f"Processed chunk {i}: found {i * 3} patterns", ) # 4. Check and compact if compactor.should_compact(history): result = compactor.compact(history, task="Analyze all data chunks") print(f"Compression ratio: {result.compression_ratio:.0%}") # 5. Apply compaction compacted = compactor.apply_compaction(history, result) print(f"Entries: {len(history)} -> {len(compacted)}") # Entries: 10 -> 3 (1 summary + 2 preserved) ``` -------------------------------- ### Connect to Local Ollama LLM Source: https://superagenticai.github.io/rlm-code/getting-started/quickstart Connects RLM Code to a local Ollama instance running the llama3.2 model. Requires a running Ollama server at `http://localhost:11434`. ```bash /connect ollama llama3.2 ``` -------------------------------- ### PureRLMEnvironment Initialization and Configuration Source: https://superagenticai.github.io/rlm-code/core/environments Demonstrates how to initialize the PureRLMEnvironment with a custom configuration, including setting the preview length for variable metadata. This environment is designed to comply with the semantics of the 'Recursive Language Models' paper. ```python from pathlib import Path from rlm_code.rlm.pure_rlm_environment import PureRLMEnvironment, PureRLMConfig from rlm_code.rlm.reward_profile import RLMRewardProfile # Example configuration config = PureRLMConfig(preview_length=1000) # Initialize environment env = PureRLMEnvironment(config=config) # Example context initialization (assuming large_document_text and lookup_table are defined) # env.initialize_context( # context=large_document_text, # description="Legal contract to analyze", # additional_vars={"reference_data": lookup_table}, # ) ``` -------------------------------- ### Complete RLM Code Approval Workflow Example Source: https://superagenticai.github.io/rlm-code/security/audit A comprehensive example demonstrating the setup and usage of the RLM Code approval system. It includes initializing the audit log, configuring a risk assessor with custom rules, setting up an approval gate with a console handler, executing agent actions with approval checks, and finally analyzing the audit trail and exporting a compliance report. ```python from rlm_code.rlm.approval import ( ApprovalGate, ApprovalPolicy, ApprovalAuditLog, ConsoleApprovalHandler, RiskAssessor, ) from rlm_code.rlm.approval.policy import RiskRule, ToolRiskLevel # 1. Set up audit log with file persistence audit_log = ApprovalAuditLog( log_file="logs/session_audit.jsonl", max_memory_entries=2000, ) # 2. Set up risk assessor with custom rules assessor = RiskAssessor() assessor.add_rule(RiskRule( name="env_var_modification", pattern=r"os\.environ[", risk_level=ToolRiskLevel.MEDIUM, reason="Environment variable modification detected", reversible=True, )) # 3. Set up gate with all components gate = ApprovalGate( policy=ApprovalPolicy.CONFIRM_MEDIUM_AND_UP, risk_assessor=assessor, approval_handler=ConsoleApprovalHandler(timeout_seconds=120).handle, audit_log=audit_log, ) # 4. Agent execution loop async def agent_loop(actions): for action in actions: request = gate.check_action(action) if request.requires_approval: response = await gate.request_approval(request) if not response.approved: print(f"Skipping: {response.reason}") continue # Execute approved action execute(action) # 5. After execution, analyze the audit trail summary = audit_log.get_summary() print(f"Total decisions: {summary['total']}") print(f"Approval rate: {summary['approval_rate']:.0%}") print(f"Denied high-risk: {summary['by_risk_level'].get('high', {}).get('denied', 0)}") # 6. Query specific entries denied_critical = audit_log.get_entries(denied_only=True, risk_level="critical") for entry in denied_critical: print(f"DENIED CRITICAL: {entry.code_preview}") print(f" Reason: {entry.reason}") print(f" Resources: {entry.affected_resources}") # 7. Export compliance report audit_log.export_report("reports/session_compliance.md") ```