mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-08 23:33:16 +08:00
- Add runtime/plan_agent_v2 package and shims; gateway/direct_loop/WS wiring - Admin chat: interaction mode and specialist only in user menu; session API stores memory_mode and execution_mode only - POST /admin/api/chat/user-mode mirrors plan_agent_version to AIA_EXPERT_PLAN_AGENT_V2_ENABLED (v2 to 1, v1 to 0) - Composer cleanup (hidden mode select, no reasoning toggle in meta bar); tests and _local/system.env.example Co-authored-by: Cursor <cursoragent@cursor.com>
3.6 KiB
3.6 KiB
Plan Agent V2 (Shadow) Design
Goal
- Build a complete plan/agent pipeline in shadow mode first.
- Keep legacy runtime path unchanged until final one-shot cutover.
- Support instant rollback via a single feature switch.
Scope
- Target only
interaction_mode=expert. interaction_mode=comprehensiveremains on legacy path.- Current implementation is dry-run/shadow ready, not wired into gateway production flow.
Runtime Components
- Package root:
runtime/plan_agent_v2/models.py: state model (PlanAgentStateV2)state_store.py: session state persistencemanager.py: plan lifecycle (enter/confirm/exit)tool_policy.py: plan-mode tool filtering policyprompt_injector.py: plan-mode and approved-plan prompt injectiontool_specs.py: shadow plan tools (enter_plan_mode_v2,exit_plan_mode_v2)switch.py: feature switch and routing predicateadapter.py: expert-mode plan decision logicgateway_adapter.py: gateway-side shadow adaptertrace.py: plan events trace helpercompat.py: legacy result-shape compatibility helpers
Legacy Compatibility
- Flat module paths are still available and now forward to package modules:
runtime/plan_agent_v2_*.py->runtime/plan_agent_v2/*
- This prevents existing imports from breaking during migration.
Session State Contract
- Stored under key:
AIA_PLAN_AGENT_V2_STATE:<session_id>
- Serialized JSON fields:
mode:normal|planowner_specialistplan_idplan_pathplan_contentplan_confirmedentered_at_msupdated_at_ms
Feature Switches
AIA_EXPERT_PLAN_AGENT_V2_ENABLED- default: off
- effect: allow expert path to route to shadow v2 when wired
AIA_EXPERT_PLAN_FILE_DIR- optional plan file root override
AIA_EXPERT_PLAN_CONFIRM_STRATEGYstrict(default): confirmation inplanmode is blocked until user switches toagentauto: confirmation inplanmode auto-switches to executionoff: disable confirmation-mode gate (same confirm behavior asauto)
Admin API Mode Fields
GET /admin/api/chat/sessions/{session_id}/mode- now returns
confirm_strategytogether withinteraction_mode/specialist/memory_mode/execution_mode.
- now returns
POST /admin/api/chat/sessions/{session_id}/mode- accepts optional
confirm_strategy(strict|auto|off) - persists per-user and per-session mode settings
- mirrors to runtime key
AIA_EXPERT_PLAN_CONFIRM_STRATEGYfor immediate effect in expert v2 turns
- accepts optional
Routing Contract (Shadow)
- Predicate:
should_route_to_v2(store, interaction_mode, force_flag=False)
- Rules:
- non-expert mode: always false
- expert +
force_flag=True: true - expert + feature on: true
- otherwise: false
Adapter Outputs
evaluate_for_expert_mode(...)returns:action:enter_plan|stay_plan|run_agentreply_textplan_statesystem_prompt_override(set onrun_agent)
Trace Events
- Emitted by
emit_plan_agent_v2_trace(...):plan_mode_enteredplan_mode_activeplan_mode_confirmed
Tests
- Shadow core tests:
tests/test_plan_agent_v2_shadow.py
- Gateway dry-run comparison tests:
tests/test_plan_agent_v2_gateway_dryrun.py
Cutover Plan (Later, Not Yet Applied)
- Add one gateway branch:
- if
should_route_to_v2(...)then callevaluate_gateway_expert_turn_shadow(...) - else keep legacy path
- if
- Keep cutover in one commit for easy rollback.
Rollback
- Runtime rollback:
- set
AIA_EXPERT_PLAN_AGENT_V2_ENABLED=false
- set
- Code rollback:
- revert only gateway branch commit; shadow modules can remain dormant.