## Summary Adds `experimental/`, a first version of worker RSI: a Curator that shapes a Raven worker's harness from the task, the materials handed to it and feedback, the way a new employee is trained. The worker is a harness-of-harnesses. A root Raven harness faces the user and calls child harnesses, each a full Raven agent hosted over ACP, through the nodes of its playbooks. Every harness has the same four strategy facets (memory, planning, capability, action). The Curator reads the actual harnesses and generates code and config on those facets at both levels: the root candidate sets the playbooks and writes per-node requirements, each child is curated against the requirements of its nodes, and the set is checked on copies and activated together. Layout: - `curator/`: staged generation (understand, select, design, implement, repair), two-level composition, harness contracts, and `raven_adapter/`, the only layer that touches a worker's Raven runtime - `analyst/`: turns an evaluator's words and execution records into observable behavior requirements - `iteration/`: the generic loop (onboarding curation, then trial, review and curation each round) and a CLI for a human evaluator - `simulation/`: a simulated travel agency that runs the loop, plus one showcase case (`simulation/cases/s0925c/`: case notes, the exported transcript split by phase, and the round 1 and round 3 decks) - `docs/design.md` (structure, curation flow, composition sequence, the Raven connection) and `docs/rsi-iteration.md` (the loop and the Analyst) Key decisions: - No change under `raven/`, and `raven/` does not import `experimental/`. Generated artifacts land on Raven's existing extension points. The few Raven internals the adapter reads are listed in `docs/design.md` section 5.4. - The Curator explores a read-only source snapshot; the caller names the evaluation side to withhold from it, so the generic layers name no scenario. - The single-layer owner analysis is kept only to reproduce the showcase case and is marked for removal; the two-layer Analyst is the default. - The two decks are `.pptx` files of about 230 KB each. They pass `check-large-files`; flagging them in case they count as report assets under AGENTS.md section 7, in which case they can move out of git behind a link. - One follow-up for Raven 0.2.2: playbooks in prompt and rounds modes ship no fixed nodes, so node requirements are read from dag playbooks only. ## Type - [ ] Fix - [x] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [ ] Other ## Verification On the branch rebased onto the latest `main`: - `uv run pytest tests/test_harness_curator_*.py tests/test_analyst_*.py tests/test_iteration_*.py tests/test_simulation_*.py -q`: 368 passed - `uv run pytest -m integration tests/integration/test_harness_curator_*.py --deselect tests/integration/test_harness_curator_real_llm.py -q` (offline, stub providers): 57 passed - `uv run pytest -q` (whole suite, with the host proxy variables unset and `PYTHONTZPATH` set): 26692 passed, 2 failed. One was an order-dependent test of this PR and is fixed here; the other, `tests/test_subagent_node_runtime.py::test_what_cannot_be_read_names_nothing`, fails only because the machine runs as root and is unrelated. - `uv run ruff check` and `uv run ruff format --check` on the touched files: clean - `scripts/check_large_files.py origin/main..HEAD`, `scripts/check_source_language.py origin/main..HEAD`, `scripts/check_commit_messages.py origin/main..HEAD` and `npx commitlint --from origin/main --to HEAD`: all exit 0 - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [x] User-facing docs or screenshots are updated when needed ## Risk No user-visible change for Raven: `experimental/` is not imported by `raven/` and is not packaged in the wheel (`packages = ["raven"]`). `CONTEXT.md` gains one glossary entry. The Curator's exploration offers a shell only under an OS sandbox executor. Rollback is a revert of the squash commit; nothing else depends on `experimental/`. - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes ## Related Issues N/A --------- Co-authored-by: Yuqi Yang <yiqiyang524@gmail.com> Co-authored-by: Claude (claude-opus-5-5) <noreply@anthropic.com>
135 lines
5.8 KiB
Python
135 lines
5.8 KiB
Python
"""Mechanism activity counts each decision once; the row shapes are cut from recorded runs."""
|
|
|
|
from experimental.analyst.activity import activity
|
|
from experimental.curator.raven_adapter.worker import Execution
|
|
from experimental.iteration.protocols import Exchange
|
|
|
|
FEEDBACK = "This message asks three questions; keep at most two."
|
|
RESAMPLE = [
|
|
{"kind": "action.call", "turn_id": "t", "operation": "assess"},
|
|
{
|
|
"kind": "action.result",
|
|
"turn_id": "t",
|
|
"operation": "assess",
|
|
"source": "review",
|
|
"result": {"action": "resample", "feedback": FEEDBACK},
|
|
},
|
|
{
|
|
"kind": "action.callback",
|
|
"turn_id": "t",
|
|
"operation": "review",
|
|
"result": {"verdict": "resample", "reason": FEEDBACK, "inject": [{"role": "user", "content": FEEDBACK}]},
|
|
},
|
|
{"kind": "action.callback", "turn_id": "t", "operation": "system_addendum", "phase": "iteration", "result": None},
|
|
{"kind": "loop.control", "turn_id": "t", "rollbacks": 1, "rollbacks_refused": 0, "mode": "high"},
|
|
]
|
|
REFUSED_STEP = [
|
|
{
|
|
"kind": "planning.error",
|
|
"turn_id": "t",
|
|
"operation": "revise",
|
|
"source": "tool",
|
|
"error": "ValueError: moving from S1 to S3 is not allowed (stages may not be skipped)",
|
|
},
|
|
{
|
|
"kind": "planning.error",
|
|
"turn_id": "t",
|
|
"operation": "tool",
|
|
"source": "tool",
|
|
"error": "moving from S1 to S3 is not allowed (stages may not be skipped)",
|
|
},
|
|
{"kind": "planning.error", "turn_id": "t", "operation": "view", "error": "KeyError: 'stage'"},
|
|
]
|
|
|
|
|
|
def rows_of(records):
|
|
sessions = {"family": [Exchange("Hi", Execution("t", [], records, {}, "a"))]}
|
|
return {(row["target"], row["decision"]): row for row in activity(sessions)}
|
|
|
|
|
|
def test_a_resample_counts_once_though_the_host_applies_it_and_the_loop_rolls_back():
|
|
rows = rows_of(RESAMPLE)
|
|
interventions = {key: row["count"] for key, row in rows.items() if row["acted"]}
|
|
assert interventions == {("action.strategy", "resample"): 1}
|
|
assert FEEDBACK in rows[("action.strategy", "resample")]["reasons"][0]
|
|
assert rows[("action.strategy", "applied")]["count"] == 1 and not rows[("loop", "rollback")]["acted"]
|
|
assert rows[("action.strategy", "assessed")]["count"] == 1 and not rows[("action.strategy", "assessed")]["acted"]
|
|
|
|
|
|
def test_a_send_back_counts_in_the_hosts_verdict_whatever_word_the_generated_reviewer_used():
|
|
"""The reviewer said `revise` with a rule code; the host carried it out as a resample."""
|
|
correction = "G2: this message asks three questions; at most two per message. Cut and rewrite."
|
|
rows = rows_of(
|
|
[
|
|
{
|
|
"kind": "action.result",
|
|
"turn_id": "t",
|
|
"operation": "assess",
|
|
"source": "review",
|
|
"result": {"verdict": "revise", "rule": "G2", "message": correction, "note": None, "reply": None},
|
|
},
|
|
{
|
|
"kind": "action.callback",
|
|
"turn_id": "t",
|
|
"operation": "review",
|
|
"result": {"verdict": "resample", "reason": "G2", "inject": [{"role": "user", "content": correction}]},
|
|
},
|
|
{"kind": "loop.control", "turn_id": "t", "rollbacks": 1, "rollbacks_refused": 0, "mode": "high"},
|
|
]
|
|
)
|
|
sent_back = rows[("action.strategy", "resample")]
|
|
assert sent_back["acted"] and sent_back["count"] == 1 and correction in sent_back["reasons"][0]
|
|
assert ("action.strategy", "revise") not in rows
|
|
|
|
|
|
def test_a_planning_step_the_strategy_rejects_is_one_refusal_and_a_crash_stays_an_error():
|
|
rows = rows_of(REFUSED_STEP)
|
|
refused = rows[("planning.strategy", "refused")]
|
|
assert refused["acted"] and refused["count"] == 1 and refused["reasons"][0].startswith("moving from S1")
|
|
assert rows[("planning.strategy", "error")]["count"] == 1 and not rows[("planning.strategy", "error")]["acted"]
|
|
|
|
|
|
def test_a_failed_tool_is_a_fact_for_the_curator_and_not_an_intervention():
|
|
"""The worker could not open a handed-over file."""
|
|
rows = rows_of(
|
|
[
|
|
{
|
|
"kind": "runner.event",
|
|
"event_type": "ToolEvent",
|
|
"event": {
|
|
"phase": "start",
|
|
"tool_call_id": "r1",
|
|
"name": "read_file",
|
|
"arguments": {"path": "uploads/x.md"},
|
|
},
|
|
},
|
|
{
|
|
"kind": "runner.event",
|
|
"event_type": "ToolEvent",
|
|
"event": {
|
|
"phase": "complete",
|
|
"tool_call_id": "r1",
|
|
"ok": False,
|
|
"result_preview": "Error: File not found: uploads/x.md",
|
|
},
|
|
},
|
|
]
|
|
)
|
|
failed = rows[("tool:read_file", "failed")]
|
|
assert not failed["acted"] and failed["reasons"] == ["Error: File not found: uploads/x.md"]
|
|
|
|
|
|
def test_a_plan_that_never_changes_and_a_send_back_after_the_reply_was_visible_are_stated():
|
|
"""The plan stays at one stage for every view, and a resample comes after the reply was already shown."""
|
|
view = {"kind": "planning.result", "operation": "view", "result": {"stage": "S1", "confirmed": False}}
|
|
shown = {"kind": "runner.event", "event_type": "Text", "event": {"content": "Your total is 12,000."}}
|
|
turns = [
|
|
Exchange("Hi", Execution("t1", [], [view, view], {}, "a")),
|
|
Exchange("Yes", Execution("t2", [], [view, shown, *RESAMPLE[:3]], {}, "a")),
|
|
]
|
|
rows = {(row["target"], row["decision"]): row for row in activity({"family": turns})}
|
|
still = rows[("planning.strategy", "state_unchanged")]
|
|
assert still["count"] == 3 and "S1" in still["reasons"][0] and not still["acted"]
|
|
assert rows[("action.strategy", "resample")]["after_visible_output"] == 1
|
|
assert all(row["session"] == "family" for row in rows.values())
|