react-agent-harness 0.9.1__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {react_agent_harness-0.9.1/react_agent_harness.egg-info → react_agent_harness-0.10.0}/PKG-INFO +1 -1
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/README.md +33 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/agents/base.py +76 -51
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/console.py +41 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/events.py +1 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/hitl.py +145 -2
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/persistent.py +408 -3
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/persistent_completion.py +10 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/persistent_controls.py +41 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/persistent_prompt.py +42 -3
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/steering.py +11 -11
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/working.py +47 -6
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/pyproject.toml +1 -1
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0/react_agent_harness.egg-info}/PKG-INFO +1 -1
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/react_agent_harness.egg-info/SOURCES.txt +3 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_agents_base.py +48 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_persistent_prompt.py +59 -0
- react_agent_harness-0.10.0/tests/test_plan_approval.py +119 -0
- react_agent_harness-0.10.0/tests/test_plan_mode.py +711 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_steering.py +16 -0
- react_agent_harness-0.10.0/tests/test_trailing_assistant_state.py +115 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_working_memory.py +31 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/LICENSE +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/agents/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/annotation.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/cancellation.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/checkpoint.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/cli.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/executor_bridge.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/_streaming.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/anthropic.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/auth.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/claude_code.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/fallback.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/openai.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/openai_codex.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/llm/routing.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/oauth_browser.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/otel.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/runtime.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/streaming.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/tool_policy.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/trace.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/trace_viewer.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/harness/utils.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/episodic_lance.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/manager.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/redis_store.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/memory/stores.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/orchestrator/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/orchestrator/planner.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/react_agent_harness.egg-info/dependency_links.txt +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/react_agent_harness.egg-info/entry_points.txt +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/react_agent_harness.egg-info/requires.txt +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/react_agent_harness.egg-info/top_level.txt +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/setup.cfg +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_annotation.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_anthropic_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_budget_guard.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_cancellation.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_checkpoint_resume.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_claude_code_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_cli.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_console_renderer.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_executor_bridge.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_fallback_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_fan_in.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_http_fetch.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_llm_auth.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_mcp_adapter.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_mcp_auth.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_memory.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_memory_reconciler.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_memory_touchpoints.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_oauth_browser.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_openai_codex_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_openai_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_orchestrator.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_otel.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_parse_action_json.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_per_call_site_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_persistent_agent.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_persistent_completion.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_persistent_controls.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_redis_store.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_resume_hint_banner.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_routing_llm.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_streaming.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_subagent_tool.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_system_prompt_routing.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_tool_policy.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_trace.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_utils.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tests/test_vision.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/builtin/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/builtin/fetch_image.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/builtin/http_fetch.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/builtin/subagent.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/mcp/__init__.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/mcp/adapter.py +0 -0
- {react_agent_harness-0.9.1 → react_agent_harness-0.10.0}/tools/mcp/auth.py +0 -0
{react_agent_harness-0.9.1/react_agent_harness.egg-info → react_agent_harness-0.10.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: react-agent-harness
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Multi-agent LLM orchestration: hybrid DAG planning, two-tier memory, streaming, cost/token budgets with per-call-site breakdown
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
License-File: LICENSE
|
|
@@ -710,12 +710,45 @@ The demo uses that utility for:
|
|
|
710
710
|
- `/save` flushes turns after the last reconcile checkpoint into long-term memory **without** evicting the cached prior (foreground prefix stays warm)
|
|
711
711
|
- `/compact` forces a structural reorg — summary + trim + reconcile + cache evict — used when the transcript is bloating, not for routine "save"
|
|
712
712
|
- `/forget` evicts cached memory context so the next turn refetches it
|
|
713
|
+
- `/plan [on|off]` toggles plan-before-execute mode — see below
|
|
713
714
|
- `/switch <id>` resumes or creates a logical session id
|
|
714
715
|
- `/new [id]` starts a fresh session id and refuses to collide with an existing id
|
|
715
716
|
- `/clear` clears the current transcript/summary/counters; long-term memory is retained
|
|
716
717
|
- `/delete [id] confirm` deletes a transcript row; long-term memory is retained
|
|
717
718
|
- `/end` exits the demo — no auto-flush; call `/save` first if you want pending facts persisted
|
|
718
719
|
|
|
720
|
+
**Plan mode** (`/plan on`, or **Shift-Tab** at the prompt) gates each turn behind an approval step. The
|
|
721
|
+
coordinator's LLM produces a structured plan (`{summary, steps[]}`) before
|
|
722
|
+
any tools run; `PersistentAgent.chat` yields a `PLAN_PROPOSED` event so
|
|
723
|
+
the renderer can display it, then routes approval through
|
|
724
|
+
`harness.hitl.request_plan_approval` — the plan-specific sibling of the
|
|
725
|
+
primitive that already gates individual tool calls.
|
|
726
|
+
|
|
727
|
+
**Plan mode approves intent, not arguments.** Most realistic agent tasks
|
|
728
|
+
have args that can only be known at runtime — a URL discovered by a
|
|
729
|
+
search, a file path extracted from a directory listing, a row id from a
|
|
730
|
+
query. The planner is told to use concrete `args` only when the value
|
|
731
|
+
was user-supplied or otherwise knowable upfront; for everything else it
|
|
732
|
+
returns `args: null` (or omits the field), and the renderer shows
|
|
733
|
+
`args: (resolved at runtime)` instead of fabricating placeholder JSON.
|
|
734
|
+
The approval banner surfaces `dynamic_steps: N` alongside the summary so
|
|
735
|
+
the reviewer sees how many step args will be filled in during execution.
|
|
736
|
+
The approved-plan prior tells the executor explicitly that
|
|
737
|
+
`(resolved at runtime)` means *"derive the argument from your
|
|
738
|
+
observations of the prior step,"* not *"a value you must invent."*
|
|
739
|
+
|
|
740
|
+
Plan approval uses a focused HITL surface:
|
|
741
|
+
|
|
742
|
+
- `Enter` or `y` approves the plan and runs the ReAct loop with the plan injected as a pinned prior.
|
|
743
|
+
- `n` rejects; an `ERROR` event is yielded and **nothing is written to the session store** (cancelled turn = never happened, same as `Esc`-cancel).
|
|
744
|
+
- Free text becomes a correction — the planner re-runs with the feedback folded into the system prompt. Up to `_PLAN_REVISION_LIMIT` revision cycles before the gate yields a clean "revision limit reached" error.
|
|
745
|
+
|
|
746
|
+
Plan mode is off by default and persists per-session in SQLite, so the
|
|
747
|
+
preference survives process restart (and `/clear`, which is a transcript
|
|
748
|
+
reset, not a settings reset). Esc during plan generation or during the
|
|
749
|
+
HITL wait unwinds `asyncio.CancelledError` through the chat generator
|
|
750
|
+
cleanly — no partial plan written. The setting is on `SessionState.plan_mode_enabled`; flip it programmatically via `PersistentAgent.set_plan_mode(session_id, enabled)`.
|
|
751
|
+
|
|
719
752
|
**Press `Esc` during a turn to cancel it.** Every example that streams a
|
|
720
753
|
`BusEvent` loop wraps it in `ConsoleRenderer.render_stream(events, *,
|
|
721
754
|
terminal_event_type=...)` — one call that renders each event, captures
|
|
@@ -686,6 +686,7 @@ class BaseAgent:
|
|
|
686
686
|
await self._commit_checkpoint(run_id, step)
|
|
687
687
|
|
|
688
688
|
combined: list[dict] = []
|
|
689
|
+
observation_events: list[BusEvent] = []
|
|
689
690
|
for i, (act, obs) in enumerate(zip(parallel_actions, observations, strict=False)):
|
|
690
691
|
tool_name = act.get("tool", "")
|
|
691
692
|
tool_args = act.get("args", {})
|
|
@@ -700,10 +701,12 @@ class BaseAgent:
|
|
|
700
701
|
"observation": obs_display,
|
|
701
702
|
},
|
|
702
703
|
)
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
704
|
+
observation_events.append(
|
|
705
|
+
BusEvent(
|
|
706
|
+
type=EventType.OBSERVATION,
|
|
707
|
+
agent_id=self.config.agent_id,
|
|
708
|
+
payload={"step": step, "tool": tool_name, "observation": obs_display},
|
|
709
|
+
)
|
|
707
710
|
)
|
|
708
711
|
combined.append({"tool": tool_name, "result": obs_display})
|
|
709
712
|
if obs and not isinstance(obs, str) and not _is_image_block(obs):
|
|
@@ -716,29 +719,15 @@ class BaseAgent:
|
|
|
716
719
|
)
|
|
717
720
|
)
|
|
718
721
|
|
|
719
|
-
await self._working_memory.append("assistant", json.dumps(response))
|
|
720
722
|
# Inject image observations as content blocks; text observations as a string.
|
|
721
723
|
image_blocks = [
|
|
722
724
|
(act.get("tool", ""), obs)
|
|
723
725
|
for act, obs in zip(parallel_actions, observations, strict=False)
|
|
724
726
|
if _is_image_block(obs)
|
|
725
727
|
]
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
"type": "text",
|
|
730
|
-
"text": f"Observations:\n{json.dumps(combined, default=str)}",
|
|
731
|
-
}
|
|
732
|
-
]
|
|
733
|
-
for tool_name_img, img_block in image_blocks:
|
|
734
|
-
content.append({"type": "text", "text": f"\nImage from {tool_name_img}:"})
|
|
735
|
-
content.append(img_block)
|
|
736
|
-
await self._working_memory.append("user", content)
|
|
737
|
-
else:
|
|
738
|
-
await self._working_memory.append(
|
|
739
|
-
"user",
|
|
740
|
-
f"Observations:\n{json.dumps(combined, default=str)}",
|
|
741
|
-
)
|
|
728
|
+
await self._record_parallel_observations(response, combined, image_blocks)
|
|
729
|
+
for event in observation_events:
|
|
730
|
+
yield event
|
|
742
731
|
else:
|
|
743
732
|
# Single action path.
|
|
744
733
|
tool_name = response.get("action", "")
|
|
@@ -774,6 +763,7 @@ class BaseAgent:
|
|
|
774
763
|
if observation is _HITL_CORRECTION:
|
|
775
764
|
continue
|
|
776
765
|
|
|
766
|
+
await self._record_tool_observation(response, tool_name, observation)
|
|
777
767
|
obs_display = "[image]" if _is_image_block(observation) else str(observation)[:500]
|
|
778
768
|
self._tracer.log(
|
|
779
769
|
"action",
|
|
@@ -809,23 +799,6 @@ class BaseAgent:
|
|
|
809
799
|
)
|
|
810
800
|
)
|
|
811
801
|
|
|
812
|
-
await self._working_memory.append("assistant", json.dumps(response))
|
|
813
|
-
if _is_image_block(observation):
|
|
814
|
-
await self._working_memory.append(
|
|
815
|
-
"user",
|
|
816
|
-
[
|
|
817
|
-
{"type": "text", "text": f"Observation ({tool_name}):"},
|
|
818
|
-
observation,
|
|
819
|
-
],
|
|
820
|
-
)
|
|
821
|
-
else:
|
|
822
|
-
obs_text = (
|
|
823
|
-
json.dumps(observation, default=str)
|
|
824
|
-
if not isinstance(observation, str)
|
|
825
|
-
else observation
|
|
826
|
-
)
|
|
827
|
-
await self._working_memory.append("user", f"Observation: {obs_text}")
|
|
828
|
-
|
|
829
802
|
# Max steps exhausted.
|
|
830
803
|
self._tracer.log(
|
|
831
804
|
"task_result",
|
|
@@ -859,6 +832,21 @@ class BaseAgent:
|
|
|
859
832
|
# honoured. OpenAI's adapter re-injects it inline when needed.
|
|
860
833
|
# See ``_split_system`` docstring for the full rationale.
|
|
861
834
|
system_text, messages = _split_system(self._working_memory.get_messages())
|
|
835
|
+
|
|
836
|
+
# The ReAct loop should call the LLM only after a user task or
|
|
837
|
+
# user observation. If working memory ends with an assistant
|
|
838
|
+
# message, log the invalid shape, but do not fabricate a user
|
|
839
|
+
# turn. Synthetic cues such as "Continue." hide the missing
|
|
840
|
+
# observation and can make the model continue from the wrong
|
|
841
|
+
# state.
|
|
842
|
+
if messages and messages[-1].get("role") == "assistant":
|
|
843
|
+
logger.warning(
|
|
844
|
+
"Agent %s: messages end with assistant before LLM call; "
|
|
845
|
+
"leaving messages unchanged. role_sequence=%r",
|
|
846
|
+
self.config.agent_id,
|
|
847
|
+
[m.get("role") for m in messages],
|
|
848
|
+
)
|
|
849
|
+
|
|
862
850
|
accumulated = ""
|
|
863
851
|
before_usage = self._working_memory.context_usage()
|
|
864
852
|
before_summarizations = self._working_memory.summarization_count
|
|
@@ -1002,6 +990,55 @@ class BaseAgent:
|
|
|
1002
990
|
self._last_think_error = f"Unparseable stream response: {accumulated[:300]}"
|
|
1003
991
|
return response
|
|
1004
992
|
|
|
993
|
+
async def _record_tool_observation(
|
|
994
|
+
self,
|
|
995
|
+
response: dict,
|
|
996
|
+
tool_name: str,
|
|
997
|
+
observation: Any,
|
|
998
|
+
) -> None:
|
|
999
|
+
"""Record one ReAct action and its observation in working memory."""
|
|
1000
|
+
await self._working_memory.append("assistant", json.dumps(response))
|
|
1001
|
+
if _is_image_block(observation):
|
|
1002
|
+
await self._working_memory.append(
|
|
1003
|
+
"user",
|
|
1004
|
+
[
|
|
1005
|
+
{"type": "text", "text": f"Observation ({tool_name}):"},
|
|
1006
|
+
observation,
|
|
1007
|
+
],
|
|
1008
|
+
)
|
|
1009
|
+
return
|
|
1010
|
+
obs_text = (
|
|
1011
|
+
json.dumps(observation, default=str)
|
|
1012
|
+
if not isinstance(observation, str)
|
|
1013
|
+
else observation
|
|
1014
|
+
)
|
|
1015
|
+
await self._working_memory.append("user", f"Observation: {obs_text}")
|
|
1016
|
+
|
|
1017
|
+
async def _record_parallel_observations(
|
|
1018
|
+
self,
|
|
1019
|
+
response: dict,
|
|
1020
|
+
combined: list[dict],
|
|
1021
|
+
image_blocks: list[tuple[str, Any]],
|
|
1022
|
+
) -> None:
|
|
1023
|
+
"""Record one parallel ReAct action batch and its observations."""
|
|
1024
|
+
await self._working_memory.append("assistant", json.dumps(response))
|
|
1025
|
+
if image_blocks:
|
|
1026
|
+
content: list = [
|
|
1027
|
+
{
|
|
1028
|
+
"type": "text",
|
|
1029
|
+
"text": f"Observations:\n{json.dumps(combined, default=str)}",
|
|
1030
|
+
}
|
|
1031
|
+
]
|
|
1032
|
+
for tool_name_img, img_block in image_blocks:
|
|
1033
|
+
content.append({"type": "text", "text": f"\nImage from {tool_name_img}:"})
|
|
1034
|
+
content.append(img_block)
|
|
1035
|
+
await self._working_memory.append("user", content)
|
|
1036
|
+
return
|
|
1037
|
+
await self._working_memory.append(
|
|
1038
|
+
"user",
|
|
1039
|
+
f"Observations:\n{json.dumps(combined, default=str)}",
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1005
1042
|
# ── Tool Execution ────────────────────────────────────────────────────────
|
|
1006
1043
|
|
|
1007
1044
|
async def _execute_tool(self, name: str, args: dict) -> Any:
|
|
@@ -1284,25 +1321,13 @@ class BaseAgent:
|
|
|
1284
1321
|
if approval is None or approval.approved
|
|
1285
1322
|
else f"Tool rejected by human: {approval.correction or 'no reason given'}"
|
|
1286
1323
|
)
|
|
1324
|
+
await self._record_tool_observation(llm_response, tool_name, observation)
|
|
1287
1325
|
obs_display = "[image]" if _is_image_block(observation) else str(observation)[:500]
|
|
1288
1326
|
yield BusEvent(
|
|
1289
1327
|
type=EventType.OBSERVATION,
|
|
1290
1328
|
agent_id=self.config.agent_id,
|
|
1291
1329
|
payload={"step": step, "tool": tool_name, "observation": obs_display},
|
|
1292
1330
|
)
|
|
1293
|
-
await self._working_memory.append("assistant", json.dumps(llm_response))
|
|
1294
|
-
if _is_image_block(observation):
|
|
1295
|
-
await self._working_memory.append(
|
|
1296
|
-
"user",
|
|
1297
|
-
[{"type": "text", "text": f"Observation ({tool_name}):"}, observation],
|
|
1298
|
-
)
|
|
1299
|
-
else:
|
|
1300
|
-
obs_text = (
|
|
1301
|
-
json.dumps(observation, default=str)
|
|
1302
|
-
if not isinstance(observation, str)
|
|
1303
|
-
else observation
|
|
1304
|
-
)
|
|
1305
|
-
await self._working_memory.append("user", f"Observation: {obs_text}")
|
|
1306
1331
|
await self._commit_checkpoint(run_id, step)
|
|
1307
1332
|
|
|
1308
1333
|
|
|
@@ -113,6 +113,47 @@ class ConsoleRenderer:
|
|
|
113
113
|
file=self._out,
|
|
114
114
|
)
|
|
115
115
|
|
|
116
|
+
elif t == EventType.PLAN_PROPOSED:
|
|
117
|
+
# PersistentAgent plan-mode preview, before HITL approval.
|
|
118
|
+
# Renders the full plan so the user can read it before the
|
|
119
|
+
# approval banner prints; HITL's banner repeats the summary
|
|
120
|
+
# in a yes/no/correction context.
|
|
121
|
+
#
|
|
122
|
+
# Steps whose args are deferred to runtime render as
|
|
123
|
+
# ``args: (resolved at runtime)`` rather than fabricating
|
|
124
|
+
# placeholder JSON — keep the renderer convention in lock-
|
|
125
|
+
# step with ``_render_plan_for_banner`` so the user sees the
|
|
126
|
+
# same shape twice.
|
|
127
|
+
plan = p.get("plan", {}) if isinstance(p.get("plan"), dict) else {}
|
|
128
|
+
revision = p.get("revision", 0)
|
|
129
|
+
summary = plan.get("summary") or "(no summary)"
|
|
130
|
+
steps = plan.get("steps") or []
|
|
131
|
+
header = "[plan propose]"
|
|
132
|
+
if revision:
|
|
133
|
+
header = f"[plan rev {revision}]"
|
|
134
|
+
print(f"\n{header} {summary}", file=self._out)
|
|
135
|
+
for step in steps:
|
|
136
|
+
idx = step.get("step")
|
|
137
|
+
intent = step.get("intent") or "(no intent)"
|
|
138
|
+
tool = step.get("tool")
|
|
139
|
+
why = step.get("why")
|
|
140
|
+
prefix = f" {idx}." if idx is not None else " -"
|
|
141
|
+
print(f"{prefix} {intent}", file=self._out)
|
|
142
|
+
if tool:
|
|
143
|
+
# Convention: ``"args"`` key missing or ``args is None``
|
|
144
|
+
# → deferred. ``args == {}`` → "tool takes no args".
|
|
145
|
+
args_present = "args" in step and step["args"] is not None
|
|
146
|
+
if not args_present:
|
|
147
|
+
print(f" tool: {tool} args: (resolved at runtime)", file=self._out)
|
|
148
|
+
else:
|
|
149
|
+
args = step["args"] or {}
|
|
150
|
+
args_repr = (
|
|
151
|
+
json.dumps(args, ensure_ascii=False, default=str) if args else "{}"
|
|
152
|
+
)
|
|
153
|
+
print(f" tool: {tool} args: {args_repr}", file=self._out)
|
|
154
|
+
if why:
|
|
155
|
+
print(f" why: {why}", file=self._out)
|
|
156
|
+
|
|
116
157
|
elif t == EventType.THOUGHT:
|
|
117
158
|
thought = p.get("thought", "")
|
|
118
159
|
if thought:
|
|
@@ -153,9 +153,13 @@ def _print_banner(req: ApprovalRequest) -> None:
|
|
|
153
153
|
print(_SEP)
|
|
154
154
|
print(f" Tool: {req.tool}")
|
|
155
155
|
print(f" Args: {json.dumps(req.args, default=str)}")
|
|
156
|
+
# ``Agent: X step=N`` is the only context line — Run/ID UUIDs used
|
|
157
|
+
# to print here but the run_id is already echoed in the resume hint
|
|
158
|
+
# below (so the top line was duplicate) and the approval_id is a
|
|
159
|
+
# purely internal correlation token that's never user-actionable in
|
|
160
|
+
# the synchronous CLI flow. Both fields remain on ``ApprovalRequest``
|
|
161
|
+
# for callers that need them (tests, future async-approval systems).
|
|
156
162
|
print(f" Agent: {req.agent_id} step={req.step}")
|
|
157
|
-
print(f" Run: {req.run_id}")
|
|
158
|
-
print(f" ID: {req.approval_id}")
|
|
159
163
|
print(_SEP)
|
|
160
164
|
print(
|
|
161
165
|
" y = approve once | "
|
|
@@ -183,6 +187,145 @@ def _parse_stdin(approval_id: str, raw: str) -> ApprovalResponse:
|
|
|
183
187
|
return ApprovalResponse(approval_id=approval_id, approved=True, correction=stripped or None)
|
|
184
188
|
|
|
185
189
|
|
|
190
|
+
@dataclass
|
|
191
|
+
class PlanApprovalResponse:
|
|
192
|
+
"""Sibling of ``ApprovalResponse`` for ``request_plan_approval``.
|
|
193
|
+
|
|
194
|
+
Plan mode is per-turn, not per-tool — there's no a / A here because
|
|
195
|
+
"allow plans for the session" silently turns plan mode off (defeats
|
|
196
|
+
the whole feature), and "always allow plans" persistently always-
|
|
197
|
+
allows the gate, which is the same thing forever.
|
|
198
|
+
|
|
199
|
+
Three outcomes:
|
|
200
|
+
- ``approved=True``: run the plan.
|
|
201
|
+
- ``approved=False, correction=None``: user rejected — abort the turn.
|
|
202
|
+
- ``approved=False, correction=<text>``: user wants a revision; the
|
|
203
|
+
planner re-runs with the correction folded into its system prompt.
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
approved: bool
|
|
207
|
+
correction: str | None = None
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
async def request_plan_approval(
|
|
211
|
+
*,
|
|
212
|
+
summary: str,
|
|
213
|
+
step_count: int,
|
|
214
|
+
dynamic_step_count: int,
|
|
215
|
+
agent_id: str,
|
|
216
|
+
guard: Any,
|
|
217
|
+
) -> PlanApprovalResponse:
|
|
218
|
+
"""Plan-mode approval prompt: y / n / revision text.
|
|
219
|
+
|
|
220
|
+
Sibling of :func:`request_approval` that drops the session-allow and
|
|
221
|
+
persistent-allow options. They make sense for per-tool gating
|
|
222
|
+
(approve ``shell/grep`` for the session and stop nagging) but they're
|
|
223
|
+
actively wrong for plan-mode approval: ``a`` turns plan mode off
|
|
224
|
+
silently, ``A`` does it permanently. Both contradict the user's
|
|
225
|
+
intent in turning plan mode on at all.
|
|
226
|
+
|
|
227
|
+
Shares ``stdout_lock``, the steering router interop, and the
|
|
228
|
+
BudgetGuard suspend/resume cycle with :func:`request_approval`, so
|
|
229
|
+
the input plumbing stays one place.
|
|
230
|
+
|
|
231
|
+
The full plan was already rendered by the consumer when the
|
|
232
|
+
``PLAN_PROPOSED`` event fired upstream of this call; the banner here
|
|
233
|
+
is a short confirmation prompt with just enough context to re-anchor
|
|
234
|
+
a reviewer who scrolled.
|
|
235
|
+
"""
|
|
236
|
+
from harness.steering import get_active_router
|
|
237
|
+
|
|
238
|
+
async with stdout_lock:
|
|
239
|
+
router = get_active_router()
|
|
240
|
+
# Capital ``Y`` signals that Enter alone approves. Plan mode is
|
|
241
|
+
# opt-in and the full plan has already been rendered above this
|
|
242
|
+
# banner, so the reviewer's "I read it, proceed" gesture should
|
|
243
|
+
# be the cheapest possible — matches the apt / pip convention.
|
|
244
|
+
approve_prompt = " Approve plan? [Y/n/revision]: "
|
|
245
|
+
hitl_future: Any = (
|
|
246
|
+
router.claim_next_line(prompt=approve_prompt) if router is not None else None
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
_print_plan_banner(
|
|
250
|
+
summary=summary,
|
|
251
|
+
step_count=step_count,
|
|
252
|
+
dynamic_step_count=dynamic_step_count,
|
|
253
|
+
agent_id=agent_id,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
guard.suspend()
|
|
257
|
+
try:
|
|
258
|
+
if hitl_future is not None:
|
|
259
|
+
raw = await hitl_future
|
|
260
|
+
else:
|
|
261
|
+
from prompt_toolkit import PromptSession
|
|
262
|
+
|
|
263
|
+
from harness.steering import StdinRouter
|
|
264
|
+
|
|
265
|
+
session: PromptSession = PromptSession()
|
|
266
|
+
raw = await session.prompt_async(
|
|
267
|
+
approve_prompt,
|
|
268
|
+
multiline=True,
|
|
269
|
+
key_bindings=StdinRouter._build_key_bindings(),
|
|
270
|
+
)
|
|
271
|
+
finally:
|
|
272
|
+
guard.resume()
|
|
273
|
+
|
|
274
|
+
print()
|
|
275
|
+
return _parse_plan_stdin(raw)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _print_plan_banner(
|
|
279
|
+
*,
|
|
280
|
+
summary: str,
|
|
281
|
+
step_count: int,
|
|
282
|
+
dynamic_step_count: int,
|
|
283
|
+
agent_id: str,
|
|
284
|
+
) -> None:
|
|
285
|
+
"""Compact banner for plan approval. The full plan already streamed
|
|
286
|
+
via PLAN_PROPOSED — this banner is just a confirmation prompt with
|
|
287
|
+
summary / step counts as scroll anchors.
|
|
288
|
+
|
|
289
|
+
No ``--resume <run_id>`` hint here because PersistentAgent's
|
|
290
|
+
resumption model is session-id-based — the next ``chat()`` call on
|
|
291
|
+
the same session_id picks up state automatically. The
|
|
292
|
+
orchestrator-style ``--resume`` flag this banner used to print
|
|
293
|
+
doesn't apply.
|
|
294
|
+
"""
|
|
295
|
+
print(f"\n{_SEP}")
|
|
296
|
+
print(f" Plan ready for {agent_id}")
|
|
297
|
+
print(_SEP)
|
|
298
|
+
if summary:
|
|
299
|
+
print(f" Summary: {summary}")
|
|
300
|
+
detail = f"{step_count} step{'' if step_count == 1 else 's'}"
|
|
301
|
+
if dynamic_step_count:
|
|
302
|
+
detail += f" ({dynamic_step_count} with args resolved at runtime)"
|
|
303
|
+
print(f" Steps: {detail}")
|
|
304
|
+
print(_SEP)
|
|
305
|
+
print(" Enter or y = approve and run | n = reject | any other text = revise the plan")
|
|
306
|
+
print(_SEP)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _parse_plan_stdin(raw: str) -> PlanApprovalResponse:
|
|
310
|
+
"""Parse a plan-approval response.
|
|
311
|
+
|
|
312
|
+
No a / A handling — plan mode gates per turn, not per tool. Any
|
|
313
|
+
text that isn't ``y/yes/n/no`` is treated as a revision request.
|
|
314
|
+
|
|
315
|
+
Empty input (just Enter) approves — the plan has already been
|
|
316
|
+
rendered above the prompt and the capital ``Y`` in the prompt
|
|
317
|
+
text signals the default. Mirrors the apt / pip ``[Y/n]``
|
|
318
|
+
convention.
|
|
319
|
+
"""
|
|
320
|
+
stripped = (raw or "").strip()
|
|
321
|
+
lo = stripped.lower()
|
|
322
|
+
if lo in ("", "y", "yes"):
|
|
323
|
+
return PlanApprovalResponse(approved=True)
|
|
324
|
+
if lo in ("n", "no"):
|
|
325
|
+
return PlanApprovalResponse(approved=False)
|
|
326
|
+
return PlanApprovalResponse(approved=False, correction=stripped or None)
|
|
327
|
+
|
|
328
|
+
|
|
186
329
|
async def request_approval(
|
|
187
330
|
req: ApprovalRequest,
|
|
188
331
|
guard: Any, # BudgetGuard — suspend/resume during wait
|