> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qredence.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# fleet-rlm Python API

> Reference for the public fleet-rlm Python interfaces — DaytonaInterpreter, FleetAgent, AgentRuntime, session runners, and the DSPy signatures used internally.

This page documents the current maintained Python interfaces. When this disagrees with the code, trust the code in `src/fleet_rlm/`.

## Core runtime classes

### `fleet_rlm.DaytonaInterpreter`

Primary sandbox execution runtime. The maintained implementation lives at `fleet_rlm.integrations.daytona.interpreter`.

```python theme={null}
from fleet_rlm import DaytonaInterpreter

with DaytonaInterpreter(timeout=600, volume_name="rlm-volume-dspy") as interp:
    result = interp.execute("print('hello')")
    print(result.text)
```

**Key capabilities:**

* Lifecycle control: `start()`, `shutdown()`, context-manager support.
* Sync/async execution: `execute()`, `aexecute()`.
* Execution profile support used by server and delegate workflows.
* Child sandbox creation via `build_delegate_child()` (called from the delegation tool, not typically directly).

The interpreter is **the** facade — outside `integrations/daytona/`, no other code should touch the Daytona SDK directly.

### `fleet_rlm.runtime.agent.agent.FleetAgent`

The interactive `dspy.ReAct`-backed orchestration module used by every chat surface (CLI, HTTP, WebSocket).

**Key behaviors:**

* Tool discovery and registration via `discover_tools()`.
* Sync chat turn helpers.
* Streaming event generation for WebSocket clients.
* Tool dispatch including the recursive `delegate_to_rlm` tool.

`FleetAgent` is normally wrapped by `AgentRuntime`, which adds the Daytona interpreter, conversation history, and core-memory state.

### `fleet_rlm.runtime.agent.runtime.AgentRuntime`

State envelope around `FleetAgent`. Owns:

* The DSPy `LM` configuration.
* The `DaytonaInterpreter` instance.
* `dspy.History` conversation turns.
* Loaded document paths.
* Agent core memory blocks.

Build one via `runtime.factory.build_runtime()` — the same factory the WebSocket transport uses.

## Runner functions (`fleet_rlm.cli.runners`)

The current maintained runner surface used by the CLI and tests:

* `build_chat_agent(...)` — construct an `AgentRuntime`.
* `run_react_chat_once(...)` — single-turn sync wrapper.
* `arun_react_chat_once(...)` — single-turn async wrapper.
* `run_long_context(...)` — long-document analysis backed by DSPy RLM signatures.

### `build_chat_agent(...)`

Constructs an `AgentRuntime` wrapping `FleetAgent`. The maintained surface is intentionally small:

| Parameter                | Purpose                                                   |
| ------------------------ | --------------------------------------------------------- |
| `docs_path`              | Optional document to preload as context                   |
| `react_max_iters`        | Max ReAct iterations per turn                             |
| `history_max_turns`      | Conversation history window                               |
| `extra_tools`            | Additional ReAct tools to register                        |
| `env_file`               | Path to `.env`                                            |
| `planner_lm`             | DSPy `LM` for the planner role                            |
| `interpreter`            | Pre-built `DaytonaInterpreter` (otherwise built from env) |
| `sub_lm` / `delegate_lm` | Optional separate LM for delegation                       |
| `repository`             | Persistence repository                                    |

<Note>
  Daytona sandbox controls (timeout, volume, recursion limits, child isolation, delegate budgets) belong on `DaytonaInterpreter`, server runtime config, or the interpreter pool. They are **not** accepted as no-op legacy kwargs by `build_chat_agent`.
</Note>

### `run_react_chat_once(...)` and `arun_react_chat_once(...)`

Single-turn wrappers around the interactive ReAct agent.

**Maintained parameters:** `message`, `docs_path`, `react_max_iters`, `include_trajectory`, `env_file`, `delegate_lm`. The async wrapper also accepts `planner_lm`.

**Output shape includes:**

* `assistant_response`
* Optional trajectory metadata (when `include_trajectory=True`).
* Turn / session metadata and warnings.

### `run_long_context(...)`

Long-document analysis/summarization helper backed by DSPy RLM signatures.

```python theme={null}
from fleet_rlm.cli.runners import run_long_context

result = run_long_context(
    docs_path="README.md",
    query="Summarize the architecture",
    mode="summarize",
)
print(result["summary"])
```

Modes:

| Mode        | Signature               |
| ----------- | ----------------------- |
| `summarize` | `SummarizeLongDocument` |

## Signatures (`fleet_rlm.runtime.agent.signatures`)

DSPy signatures define the typed input/output contracts for agent behavior:

| Signature                               | Purpose                         |
| --------------------------------------- | ------------------------------- |
| `SummarizeLongDocument`                 | Long-document summarization     |
| `ExtractFromLogs`                       | Structured extraction from logs |
| `GroundedAnswerWithCitations`           | Grounded QA with citations      |
| `IncidentTriageFromLogs`                | Incident triage                 |
| `CodeChangePlan`                        | Code-change planning            |
| `CoreMemoryUpdateProposal`              | Core-memory updates             |
| `VolumeFileTreeSignature`               | Volume tree exploration         |
| `MemoryActionIntentSignature`           | Memory action intent            |
| `MemoryStructureAuditSignature`         | Memory structure audit          |
| `MemoryStructureMigrationPlanSignature` | Memory migration planning       |
| `ClarificationQuestionSignature`        | Clarification questions         |

All are `dspy.Signature` subclasses with typed `InputField`s and `OutputField`s. They're independently testable and optimizable through DSPy's optimization pipelines.

## Building a recursive RLM directly

When you need a bounded recursive runner without going through the ReAct delegation tool:

```python theme={null}
from fleet_rlm.runtime.models.builders import build_recursive_subquery_rlm

rlm = build_recursive_subquery_rlm(
    interpreter=child_interpreter,
    max_iterations=8,
    max_llm_calls=40,
)

result = rlm(prompt="Extract every TODO from these logs", context="...")
```

<Warning>
  In production code, prefer the `delegate_to_rlm` tool from inside the ReAct agent — it enforces the shared call budget across the recursive tree for you. See [Recursive RLM](/fleet-rlm/concepts/recursive-rlm).
</Warning>

## Tools (`fleet_rlm.runtime.tools`)

The ReAct tool registry is in `src/fleet_rlm/runtime/tools/`. The recursive delegation tool is:

* `rlm_delegate.delegate_to_rlm(query, context="", document_url="")`

Custom tools register through `discover_tools()` on `FleetAgent` or by passing `extra_tools=[...]` to `build_chat_agent`.

## Quality / optimization (`fleet_rlm.runtime.quality`)

Offline evaluation and GEPA optimization:

| Module                | Purpose                                            |
| --------------------- | -------------------------------------------------- |
| `module_registry`     | Registered DSPy modules (`longcot-reasoner`, etc.) |
| `dspy_evaluation`     | DSPy `Evaluate` integration                        |
| `gepa_optimization`   | GEPA optimization runner                           |
| `mlflow_evaluation`   | Evaluation with MLflow logging                     |
| `mlflow_optimization` | Optimization runs with MLflow logging              |
| `scorers`             | Scoring functions and metrics                      |
| `workspace_metrics`   | Workspace-aware metrics                            |

CLI surface: `uv run fleet-rlm optimize list` and `uv run fleet-rlm optimize <module> <dataset>`.

## Import verification

```bash theme={null}
uv run python -c "from fleet_rlm import DaytonaInterpreter"
uv run python -c "from fleet_rlm.cli.runners import run_long_context, run_react_chat_once"
uv run python -c "from fleet_rlm.runtime.agent.signatures import SummarizeLongDocument"
uv run python -c "from fleet_rlm.runtime.models.builders import build_recursive_subquery_rlm"
```

## See also

* [Architecture](/fleet-rlm/concepts/architecture) — where these classes sit in the layering.
* [Recursive RLM](/fleet-rlm/concepts/recursive-rlm) — full delegation flow.
* [DSPy integration](/fleet-rlm/guides/dspy-integration) — how the planner LM is wired.
