A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
prompt: make long-running RLM work nonblocking, visible, and clear (#1188)
samsja7ca44937ff2c
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.mdindex 647fbcfd19..3dc4d41ed1 100644--- a/packages/coding-agent/CHANGELOG.md+++ b/packages/coding-agent/CHANGELOG.md@@ -2,6 +2,7 @@## [Unreleased]+- Changed RLM guidance to orchestrate independent workers in parallel, use available async shell helpers safely, end the turn instead of sleeping, polling, or blocking on long awaits, provide proactive outcome-focused progress updates from root agents, and use simplified technical English for user-facing prose.- Fixed new top-level daemon sessions inheriting an RLM child depth from the supervisor process.## [0.7.3] - 2026-08-17diff --git a/packages/coding-agent/src/core/prompts/rlm.ts b/packages/coding-agent/src/core/prompts/rlm.tsindex 7e023d5278..3bab46027d 100644--- a/packages/coding-agent/src/core/prompts/rlm.ts+++ b/packages/coding-agent/src/core/prompts/rlm.ts@@ -11,6 +11,22 @@ export interface RlmPromptOptions {activeTools?: string[];}+const LONG_RUNNING_WORK_PROMPT = [+ "For slow or independently completing work, use a nonblocking control loop: start the work, record its handle or output location, then end your turn. Read the result on a later turn or when a reply arrives.",+ "When delegation is available and useful, assign independent substantive tasks to separate workers. Start independent workers without waiting for each one sequentially, and let them run in parallel.",+ "Do not keep the turn open by polling with `time.sleep()` or shell `sleep`, and do not replace polling with a long blocking `await`. Await only the short operation needed to start work or inspect a result that is already available; otherwise end the turn.",+].join("\n");++const USER_PROGRESS_PROMPT =+ "As the user-facing root agent, when work follows a plan, uses many subagents, or spans multiple turns, proactively give regular concise progress updates so the user does not have to ask. State the current plan, what has completed, any blockers, the proposed fixes, and the next actions. Lead with user-visible outcomes rather than internal process or gate names. Mention internal details only when they explain a blocker or decision. Send an update at meaningful milestones and before ending a turn while work is still running. Do not repeat unchanged status or interrupt short work with unnecessary updates.";++const SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT = [+ "Use simplified technical English by default for user-facing prose.",+ "Prefer short sentences, common words, and concrete verbs. State one main action or fact per sentence when practical. Use lists for steps or conditions.",+ "Keep necessary technical terms, names, commands, code, paths, and exact quoted text unchanged. State uncertainty directly.",+ "Treat this as clarity guidance, not a claim of formal ASD-STE100 compliance. Preserve a user-requested format, tone, terminology, and necessary precision.",+].join("\n");+const IPYTHON_CONTROL_PROMPT = ["IPython is the agent's long-lived notebook: a persistent control environment for reasoning, context management, state, tool orchestration, and recursive subcalls. Use it to keep intermediate variables, inspect and transform outputs, write small helper functions, and preserve useful state across turns or compaction.","",@@ -18,6 +34,8 @@ const IPYTHON_CONTROL_PROMPT = ["","When running shell commands from IPython, use `%%bash` cells. If you use `%%bash`, it must be the first line of the code cell: no comments, spaces, blank lines, imports, or Python statements before it. Avoid `!cmd` shell escapes for project commands so shell behavior is explicit and multi-line commands share one shell context.","",+ "If the runtime provides a documented async `bash()` helper, use `await bash(...)` only for short, bounded work that completes in the current turn; do not wrap it in `asyncio.create_task`. For background work, or work that must survive a kernel restart, session rotation, or teardown, use a managed job with a durable receipt instead.",+ "","Important: do not install dependencies into the IPython kernel just to make an external project import or run there. If a project import, test, script, CLI, or dependency check is needed, run it through that project's own environment and normal command interface. For example, in a Python repo use its documented commands, `uv run ...`, `.venv/bin/python ...`, or the active project interpreter from the repo root. Treat failures from that native environment as the relevant result.","","Use Python for reading, searching, and editing files — it gives you reusable variables you can slice, filter, and act on without re-reading. Always assign read/search results to named variables so you can revisit them later.",@@ -72,6 +90,11 @@ export function buildRlmPrompt(options: RlmPromptOptions): string {"You solve tasks by breaking down problems into sub-tasks, writing and executing code, observing results, and iterating one step at a time.","When you are done, stop calling tools and state your final answer.","",+ LONG_RUNNING_WORK_PROMPT,+ "",+ ...(depth === 0 ? [USER_PROGRESS_PROMPT, ""] : []),+ SIMPLIFIED_TECHNICAL_ENGLISH_PROMPT,+ "",`Working directory: ${cwd}`,`Conversation log: ${messagesPath}`,`Recursive agent depth: ${depth}`,diff --git a/packages/coding-agent/test/system-prompt.test.ts b/packages/coding-agent/test/system-prompt.test.tsindex bbb128ef45..9f97e0b7a8 100644--- a/packages/coding-agent/test/system-prompt.test.ts+++ b/packages/coding-agent/test/system-prompt.test.ts@@ -1,5 +1,4 @@import { describe, expect, test } from "vitest";-import { DEFAULT_RLM_EXTRA_IMPORT_LABELS } from "../src/core/kernel/bootstrap.js";import { buildRlmPrompt } from "../src/core/prompts/index.js";import type { HarnessState } from "../src/core/refinement/index.js";import type { Skill } from "../src/core/skills.js";@@ -37,56 +36,6 @@ function pythonSkill(name: string, importName = name.replaceAll("-", "_")): Skil}describe("buildRlmPrompt", () => {- test("builds the rlm prompt without recursion", () => {- const prompt = buildRlmPrompt({- cwd: "/repo",- messagesPath: "/repo/.pi/sessions/session.jsonl",- installedSkills: ["websearch", "refine"],- activeTools: ["ipython"],- allowRecursion: false,- });-- expect(prompt).toBe(- [- "You are a general purpose agent that uses code to solve tasks.",- "You solve tasks by breaking down problems into sub-tasks, writing and executing code, observing results, and iterating one step at a time.",- "When you are done, stop calling tools and state your final answer.",- "",- "Working directory: /repo",- "Conversation log: /repo/.pi/sessions/session.jsonl",- "Recursive agent depth: 0",- `Pre-installed Python packages: ${DEFAULT_RLM_EXTRA_IMPORT_LABELS.join(", ")}.`,- "Install additional packages with `uv pip install <pkg>` (this is a uv-managed venv with no pip module).",- "",- "Installed Python skill modules (pre-imported): `websearch`, `refine`.",- "Read each skill's SKILL.md for its API. Inspect a module with `help(<skill>)` or `dir(<skill>)`, then inspect a documented callable with `inspect.signature(<skill>.<function>)`.",- "Each skill is also available as a shell command by the same name: `<skill> ...`. Discover its CLI usage with `<skill> --help`.",- "",- "IPython is the agent's long-lived notebook: a persistent control environment for reasoning, context management, state, tool orchestration, and recursive subcalls. Use it to keep intermediate variables, inspect and transform outputs, write small helper functions, and preserve useful state across turns or compaction.",- "",- "Do not assume IPython is the native runtime of the external thing being investigated. A repository, package, service, dataset, paper, website, benchmark, or API may have its own environment and normal interface. Evaluate external systems through their own interface, then use IPython to coordinate the process and analyze what comes back.",- "",- "When running shell commands from IPython, use `%%bash` cells. If you use `%%bash`, it must be the first line of the code cell: no comments, spaces, blank lines, imports, or Python statements before it. Avoid `!cmd` shell escapes for project commands so shell behavior is explicit and multi-line commands share one shell context.",- "",- "Important: do not install dependencies into the IPython kernel just to make an external project import or run there. If a project import, test, script, CLI, or dependency check is needed, run it through that project's own environment and normal command interface. For example, in a Python repo use its documented commands, `uv run ...`, `.venv/bin/python ...`, or the active project interpreter from the repo root. Treat failures from that native environment as the relevant result.",- "",- "Use Python for reading, searching, and editing files — it gives you reusable variables you can slice, filter, and act on without re-reading. Always assign read/search results to named variables so you can revisit them later.",- "",- "Each `%%bash` cell runs in a throw-away subshell, so shell-level state (`cd`, `export`, `source`, shell variables) does NOT carry to later cells. Keep dependent shell steps inside one `%%bash` cell when they need shared shell state, or use kernel-level equivalents that survive across calls: `%cd <dir>` for the working directory and `os.environ['VAR'] = '...'` (or `%env VAR=...`) for environment variables — these apply to all subsequent `%%bash` calls.",- "",- "Python state in the kernel, by contrast, persists across cells: named variables, helper functions, classes, imports, notes, parsed outputs, and helper data structures all remain available in every later turn. Tool calls are themselves Python `await` expressions, so their return values can be bound to variables and composed into program logic just like any other call.",- "",- "Continual harness state is available as `rlm.harness` and `rlm.get_harness_state()`. CRUD calls are local to this Prime Agent session by default: `rlm.harness.create_memory(...)`, `rlm.harness.update_memory(...)`, `rlm.harness.delete_memory(...)`, `rlm.harness.create_skill(...)`, `rlm.harness.update_skill(...)`, `rlm.harness.delete_skill(...)`, `rlm.harness.create_subagent(...)`, `rlm.harness.update_subagent(...)`, `rlm.harness.delete_subagent(...)`, `rlm.harness.create_prompt_note(...)`, `rlm.harness.update_prompt_note(...)`, `rlm.harness.delete_prompt_note(...)`, plus `rlm.harness.record_refinement(...)` and `rlm.harness.overview()`. Use `global_=True` only for stable cross-session lessons; Python reserves `global`, so literal `global=True` is invalid syntax.",- "",- "Terminology: continual harness names the persisted prompt, memory, skill, and subagent layer; RLM names the runtime, IPython kernel, and native call interface exposed to the model.",- "",- "RLM-native call contract: installed Python skills are pre-imported modules. Read the matching SKILL.md and call its documented function, such as `await <skill_import>.<function>(...)`; when a CLI exists, use `<skill_import> ...` from shell. Continual harness skill entries are Python REPL skills with an explicit Python `reference` and `arguments` contract. Spawn a reusable delegation spec with `await rlm('sub-task')`; admission returns a child handle immediately. Results arrive only through an available messaging capability or files, never as an `rlm()` return value. Do not invent non-native wrappers such as `call_skill(...)` or `run_subagent(...)`.",- "",- "Treat continual harness refinement as a small, evidence-backed update after observing a repeated failure or reusable tactic: diagnose the issue, update the smallest relevant continual harness component, validate on the next action, then record the outcome. Use `await refine.run()` to turn repeated delegation patterns into reusable subagent specs, repeated procedures into skills, durable facts/preferences into memories, and narrow behavioral policies into prompt addendums. It returns immediately and runs when the current turn ends, so continue working normally after calling it. Do not rewrite the whole continual harness when a focused memory, skill, prompt note, or subagent spec is enough.",- ].join("\n"),- );- });-test("defaults omitted activeTools to ipython guidance", () => {const prompt = buildRlmPrompt({cwd: "/repo",