react-agent-harness 0.7.0__tar.gz → 0.9.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.7.0/react_agent_harness.egg-info → react_agent_harness-0.9.0}/PKG-INFO +1 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/README.md +283 -4
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/agents/base.py +336 -29
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/events.py +4 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/anthropic.py +61 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/claude_code.py +28 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/fallback.py +2 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/openai.py +115 -5
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/openai_codex.py +48 -4
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/routing.py +3 -2
- react_agent_harness-0.9.0/harness/persistent.py +1331 -0
- react_agent_harness-0.9.0/harness/persistent_completion.py +125 -0
- react_agent_harness-0.9.0/harness/persistent_controls.py +525 -0
- react_agent_harness-0.9.0/harness/streaming.py +136 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/stores.py +105 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/working.py +15 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/pyproject.toml +1 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0/react_agent_harness.egg-info}/PKG-INFO +1 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/react_agent_harness.egg-info/SOURCES.txt +10 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_agents_base.py +30 -0
- react_agent_harness-0.9.0/tests/test_fan_in.py +94 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_memory.py +14 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_openai_codex_llm.py +42 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_openai_llm.py +112 -1
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_parse_action_json.py +12 -0
- react_agent_harness-0.9.0/tests/test_persistent_agent.py +911 -0
- react_agent_harness-0.9.0/tests/test_persistent_completion.py +140 -0
- react_agent_harness-0.9.0/tests/test_persistent_controls.py +193 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_streaming.py +34 -0
- react_agent_harness-0.9.0/tests/test_subagent_tool.py +453 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_working_memory.py +58 -0
- react_agent_harness-0.9.0/tools/builtin/subagent.py +173 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/LICENSE +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/agents/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/annotation.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/checkpoint.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/cli.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/console.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/executor_bridge.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/hitl.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/_streaming.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/llm/auth.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/oauth_browser.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/otel.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/runtime.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/steering.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/tool_policy.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/trace.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/trace_viewer.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/harness/utils.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/episodic_lance.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/manager.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/memory/redis_store.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/orchestrator/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/orchestrator/planner.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/react_agent_harness.egg-info/dependency_links.txt +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/react_agent_harness.egg-info/entry_points.txt +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/react_agent_harness.egg-info/requires.txt +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/react_agent_harness.egg-info/top_level.txt +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/setup.cfg +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_annotation.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_anthropic_llm.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_budget_guard.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_checkpoint_resume.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_claude_code_llm.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_cli.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_console_renderer.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_executor_bridge.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_fallback_llm.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_http_fetch.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_llm_auth.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_mcp_adapter.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_mcp_auth.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_memory_reconciler.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_memory_touchpoints.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_oauth_browser.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_orchestrator.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_otel.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_per_call_site_llm.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_redis_store.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_routing_llm.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_steering.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_tool_policy.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_trace.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_utils.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tests/test_vision.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/builtin/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/builtin/fetch_image.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/builtin/http_fetch.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/mcp/__init__.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/mcp/adapter.py +0 -0
- {react_agent_harness-0.7.0 → react_agent_harness-0.9.0}/tools/mcp/auth.py +0 -0
{react_agent_harness-0.7.0/react_agent_harness.egg-info → react_agent_harness-0.9.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.9.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
|
|
@@ -55,6 +55,7 @@ harness/checkpoint.py CheckpointStore + _ResumeHint + maybe_resume_key —
|
|
|
55
55
|
harness/otel.py OTELHook — OpenTelemetry span exporter (opt-in)
|
|
56
56
|
harness/executor_bridge.py ExecutorBridge + ExecutorTool — controlled subprocess launcher with optional Docker sandboxing
|
|
57
57
|
harness/oauth_browser.py Localhost OAuth callback server + open_or_print_url — shared by MCP browser-OAuth and LLM login flows
|
|
58
|
+
harness/persistent.py PersistentAgent + SQLiteSessionStore — durable chat sessions around user-built agents
|
|
58
59
|
orchestrator/planner.py Hybrid DAG orchestrator — plan, replan, synthesize
|
|
59
60
|
agents/base.py Generic BaseAgent — ReAct loop, no subclassing needed
|
|
60
61
|
memory/manager.py MemoryManager — semantic KV + episodic vector
|
|
@@ -64,8 +65,10 @@ memory/redis_store.py Redis semantic store — durable KV with TTL
|
|
|
64
65
|
memory/stores.py InMemory stores — local dev default, no deps
|
|
65
66
|
tools/builtin/http_fetch.py HTTPFetch — minimal read-only GET tool
|
|
66
67
|
tools/builtin/fetch_image.py FetchImage — fetch URL and return OpenAI image_url block
|
|
68
|
+
tools/builtin/subagent.py SubAgentTool — expose a BaseAgent as a parent-callable streaming tool
|
|
67
69
|
tools/mcp/adapter.py MCP tool adapter — stdio, SSE, streamable-HTTP transports
|
|
68
70
|
tools/mcp/auth.py ApiKeyMCPAuth + BrowserOAuthMCPAuth — auth primitives for remote MCP servers
|
|
71
|
+
harness/streaming.py Multi-producer fan-in for parallel streaming tools (sub-agents)
|
|
69
72
|
```
|
|
70
73
|
|
|
71
74
|
Execution is **streaming-primary**: every path yields `BusEvent`s for
|
|
@@ -90,6 +93,8 @@ explicit control.
|
|
|
90
93
|
| `examples/mcp_demo.py` | Connects to an MCP filesystem server and gives the agent its tools. | `OPENAI_API_KEY`, `[openai,mcp]`, `npx` |
|
|
91
94
|
| `examples/mcp_auth_demo.py` | Connects to an authenticated remote MCP server using bearer or auth-file credentials. | `OPENAI_API_KEY`, `[openai,mcp]`, `MCP_URL`, `MCP_BEARER_TOKEN` or `MCP_AUTH_PROVIDER` |
|
|
92
95
|
| `examples/subscription_auth_demo.py` | Runs an agent through subscription-backed providers: direct `openai-codex` OAuth or direct `claude-code` OAuth. | `agent-harness login openai-codex` or `agent-harness login claude-code` |
|
|
96
|
+
| `examples/coordinator_demo.py` | Sub-agent-as-tool pattern: a `coordinator` ReAct agent delegates dynamically to `researcher` / `analyst` / `reporter` via `SubAgentTool`. Demonstrates parallel delegation through `actions: [...]`. | `OPENAI_API_KEY`, `[openai,http]` |
|
|
97
|
+
| `examples/persistent_agent_demo.py` | Persistent local assistant: SQLite session + semantic memory, Lance episodic memory, shell tool, and a browser researcher via `@playwright/mcp`. Supports `--provider openai`, `--provider openai-codex`, or `--provider claude-code`. | `[openai,mcp,lance]`, `OPENAI_API_KEY` or `python -m harness.cli login openai-codex` / `claude-code`, `ah-executor`, `npx` (Node 18+) |
|
|
93
98
|
|
|
94
99
|
## Adding a new domain (3 steps)
|
|
95
100
|
|
|
@@ -541,6 +546,262 @@ agents themselves still read from memory.
|
|
|
541
546
|
If a task fails mid-run and `on_failure="replan"`, the replan call does
|
|
542
547
|
go to the LLM — the bypass is for the *initial* plan only.
|
|
543
548
|
|
|
549
|
+
### 5. Sub-agents as tools — `SubAgentTool`
|
|
550
|
+
|
|
551
|
+
A different decomposition model from the orchestrator. Instead of a
|
|
552
|
+
separate planner LLM deciding the DAG upfront, **one main agent's ReAct
|
|
553
|
+
loop decides per step whether to delegate** and to whom. Use when the
|
|
554
|
+
path is exploratory — you don't know which specialist you'll need until
|
|
555
|
+
you've seen partial results.
|
|
556
|
+
|
|
557
|
+
```python
|
|
558
|
+
from tools.builtin.subagent import SubAgentTool
|
|
559
|
+
|
|
560
|
+
researcher = BaseAgent(config=researcher_config, ...)
|
|
561
|
+
analyst = BaseAgent(config=analyst_config, ...)
|
|
562
|
+
|
|
563
|
+
main_agent = BaseAgent(
|
|
564
|
+
config=AgentConfig(
|
|
565
|
+
agent_id="coordinator",
|
|
566
|
+
role="decides what to research and analyses results",
|
|
567
|
+
system_prompt="...",
|
|
568
|
+
allowed_tools=["delegate_research", "delegate_analyse"],
|
|
569
|
+
max_subagent_depth=3, # bounds the delegation chain
|
|
570
|
+
),
|
|
571
|
+
tools={
|
|
572
|
+
"delegate_research": SubAgentTool(researcher),
|
|
573
|
+
"delegate_analyse": SubAgentTool(analyst),
|
|
574
|
+
},
|
|
575
|
+
...
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
async for event in main_agent.run_stream(goal):
|
|
579
|
+
# Sub-agent THOUGHT / ACTION / OBSERVATION events bubble up tagged
|
|
580
|
+
# with event.parent_agent_id so renderers can indent or group them.
|
|
581
|
+
...
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
When the main agent's LLM emits `{"action": "delegate_research", "args":
|
|
585
|
+
{"task": "..."}}`, the wrapped sub-agent runs its own ReAct loop with a
|
|
586
|
+
**fresh `WorkingMemory`**; the sub's final answer becomes the main agent's
|
|
587
|
+
next observation. Each delegation = a fresh sub run; cross-delegation
|
|
588
|
+
continuity flows through long-term memory (`MemoryManager.build_context(
|
|
589
|
+
agent_id=…)`), not through WM carry-over — same model as the
|
|
590
|
+
orchestrator's per-task agents.
|
|
591
|
+
|
|
592
|
+
Parallel delegation works via the existing `actions: [...]` shape:
|
|
593
|
+
|
|
594
|
+
```json
|
|
595
|
+
{
|
|
596
|
+
"thought": "research and analyse can run in parallel",
|
|
597
|
+
"actions": [
|
|
598
|
+
{"tool": "delegate_research", "args": {"task": "find baseline metrics"}},
|
|
599
|
+
{"tool": "delegate_analyse", "args": {"task": "score recent incidents"}}
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
Both sub-agent streams interleave through a fan-in helper
|
|
605
|
+
(`harness/streaming.py:fan_in`) so the parent's event stream stays a
|
|
606
|
+
single sequence even when multiple sub-agents are working concurrently.
|
|
607
|
+
|
|
608
|
+
**Sub-agents as tools vs. Orchestrator — which to pick?**
|
|
609
|
+
|
|
610
|
+
| | Sub-agents as tools | Orchestrator |
|
|
611
|
+
|---|---|---|
|
|
612
|
+
| Plan timing | Per step (dynamic) | Upfront DAG |
|
|
613
|
+
| Who plans | The main agent's LLM | A separate planner LLM |
|
|
614
|
+
| Best for | Exploratory work, "I don't know what I need until I see partial results" | Known workflows (audits, ETL, scheduled jobs) |
|
|
615
|
+
| Replan-on-failure | Implicit — main agent reacts to sub's failure | Explicit `on_failure="replan"` |
|
|
616
|
+
| Recursion guard | `max_subagent_depth` on `AgentConfig` | N/A — DAG is flat |
|
|
617
|
+
|
|
618
|
+
Both are first-class. Most real systems combine them — the orchestrator
|
|
619
|
+
plans a high-level DAG, individual tasks within it use sub-agent tools
|
|
620
|
+
for finer dynamic decomposition.
|
|
621
|
+
|
|
622
|
+
### 6. Persistent chat sessions — `PersistentAgent`
|
|
623
|
+
|
|
624
|
+
`PersistentAgent` is a wrapper around a coordinator `BaseAgent`, not a new
|
|
625
|
+
agent constructor. Build agents, sub-agents, MCP tools, and auth exactly as
|
|
626
|
+
usual; then wrap the top-level coordinator to add durable chat/session state.
|
|
627
|
+
|
|
628
|
+
```python
|
|
629
|
+
from harness.persistent import PersistentAgent, SQLiteSessionStore
|
|
630
|
+
|
|
631
|
+
app = PersistentAgent(
|
|
632
|
+
coordinator=coordinator_agent,
|
|
633
|
+
session_store=SQLiteSessionStore("~/.agent-harness/sessions.sqlite"),
|
|
634
|
+
memory=memory_manager,
|
|
635
|
+
llm=llm,
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
async for event in app.chat("I like the above; can you do X?", session_id="thread-1"):
|
|
639
|
+
renderer.render(event)
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
Use `app.capabilities()` to inspect the already-wired coordinator,
|
|
643
|
+
sub-agents, and MCP tools. The demo exposes this with
|
|
644
|
+
`--show-capabilities`.
|
|
645
|
+
|
|
646
|
+
Persistent sessions also expose a small control surface for user interfaces:
|
|
647
|
+
|
|
648
|
+
```python
|
|
649
|
+
state = await app.session_state("thread-1")
|
|
650
|
+
print(state.tokens_in_total, state.tokens_out_total)
|
|
651
|
+
sessions = await app.list_sessions()
|
|
652
|
+
matches = await app.list_sessions(query="research")
|
|
653
|
+
cached = app.cached_memory_context("thread-1")
|
|
654
|
+
await app.save_to_memory("thread-1") # reconcile pending turns, keep cache warm
|
|
655
|
+
await app.force_compact("thread-1") # structural reorg (summary + trim + reconcile + evict)
|
|
656
|
+
app.forget_memory_cache("thread-1")
|
|
657
|
+
await app.clear_session("thread-1") # clear transcript only; memory retained
|
|
658
|
+
await app.delete_session("thread-1") # delete transcript only; memory retained
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
There is deliberately no `close()` method — the SQLite transcript is the
|
|
662
|
+
durable record, and any of `chat`/`save_to_memory`/`force_compact` on the
|
|
663
|
+
same `session_id` later will resume from it. To exit, just stop calling
|
|
664
|
+
`chat` (and let the process end).
|
|
665
|
+
|
|
666
|
+
For simple REPLs, `PersistentCommandHandler` maps slash commands to those
|
|
667
|
+
primitives and returns structured results:
|
|
668
|
+
|
|
669
|
+
```python
|
|
670
|
+
from harness.persistent_controls import PersistentCommandHandler
|
|
671
|
+
|
|
672
|
+
controls = PersistentCommandHandler(app)
|
|
673
|
+
result = await controls.handle("/sessions research", session_id=session_id)
|
|
674
|
+
if result.session_id:
|
|
675
|
+
session_id = result.session_id
|
|
676
|
+
if result.text:
|
|
677
|
+
print(result.text)
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
The command surface is defined once in `SLASH_COMMAND_SPECS` and exposed via
|
|
681
|
+
`slash_command_specs()`. Tab-completion in the demo binds those specs to
|
|
682
|
+
`prompt_toolkit` via `SlashCommandCompleter`:
|
|
683
|
+
|
|
684
|
+
```python
|
|
685
|
+
from prompt_toolkit import PromptSession
|
|
686
|
+
from prompt_toolkit.history import FileHistory
|
|
687
|
+
from harness.persistent_completion import SlashCommandCompleter
|
|
688
|
+
|
|
689
|
+
session = PromptSession(
|
|
690
|
+
history=FileHistory("~/.agent-harness/demo_history"),
|
|
691
|
+
completer=SlashCommandCompleter(app),
|
|
692
|
+
complete_while_typing=False, # Tab-triggered; doesn't query the store every keystroke
|
|
693
|
+
)
|
|
694
|
+
message = (await session.prompt_async("> ")).strip()
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
Name completion comes from the spec registry; session-id arguments call
|
|
698
|
+
`app.list_sessions(query=...)` (SQLite pushes the filter down to
|
|
699
|
+
`lower(session_id) LIKE ?` so per-keystroke cost stays bounded). Other UIs
|
|
700
|
+
(web autocomplete, fzf, IDE plugins) should consume `slash_command_specs()`
|
|
701
|
+
directly without importing the prompt_toolkit binding.
|
|
702
|
+
|
|
703
|
+
The demo uses that utility for:
|
|
704
|
+
|
|
705
|
+
- `/capabilities`, `/agents`, `/mcp` inspect wired agents and tools
|
|
706
|
+
- `/session` shows turns, context-pressure estimate, reconcile cadence, and summary
|
|
707
|
+
- `/usage` shows persisted total and last-run provider-reported token usage
|
|
708
|
+
- `/sessions [query]` lists known session ids, optionally filtered by id text
|
|
709
|
+
- `/memory` shows the cached per-session memory context
|
|
710
|
+
- `/save` flushes turns after the last reconcile checkpoint into long-term memory **without** evicting the cached prior (foreground prefix stays warm)
|
|
711
|
+
- `/compact` forces a structural reorg — summary + trim + reconcile + cache evict — used when the transcript is bloating, not for routine "save"
|
|
712
|
+
- `/forget` evicts cached memory context so the next turn refetches it
|
|
713
|
+
- `/switch <id>` resumes or creates a logical session id
|
|
714
|
+
- `/new [id]` starts a fresh session id and refuses to collide with an existing id
|
|
715
|
+
- `/clear` clears the current transcript/summary/counters; long-term memory is retained
|
|
716
|
+
- `/delete [id] confirm` deletes a transcript row; long-term memory is retained
|
|
717
|
+
- `/end` exits the demo — no auto-flush; call `/save` first if you want pending facts persisted
|
|
718
|
+
|
|
719
|
+
Each chat turn gets a fresh `WorkingMemory`. Continuity comes from the
|
|
720
|
+
SQLite session state (rolling summary + recent messages) and normal
|
|
721
|
+
`MemoryManager` recall, not from carrying old ReAct scratchpads forever.
|
|
722
|
+
|
|
723
|
+
**Prefix-cache aware.** The full prompt stays byte-identical across plain
|
|
724
|
+
chat turns within a compaction window. Four things make that work:
|
|
725
|
+
|
|
726
|
+
1. The accumulated session transcript is sent to the coordinator as real
|
|
727
|
+
`user`/`assistant` role messages — not folded into one inline-rendered
|
|
728
|
+
text blob. Each turn extends the message list by exactly the previous
|
|
729
|
+
turn's user+assistant pair plus the new user task.
|
|
730
|
+
2. Memory context (`MemoryManager.build_context` result) lives in a
|
|
731
|
+
pinned user-message prior, **not in the system prompt**. The system
|
|
732
|
+
prompt is now pure agent identity + tool list + ReAct format — purely
|
|
733
|
+
static. Memory context is fetched once per session, cached on the
|
|
734
|
+
`PersistentAgent`, and refreshed only at compaction or explicit
|
|
735
|
+
"remember" signals.
|
|
736
|
+
3. **Compaction triggers on context-size pressure, not turn counts.**
|
|
737
|
+
`compact_at_context_fraction=0.5` (default) reads the coordinator
|
|
738
|
+
LLM's `input_token_budget` and fires when the transcript crosses
|
|
739
|
+
~50% of it. After compaction, `retain_context_fraction=0.15`
|
|
740
|
+
keeps the newest messages that fit in ~15% of the input budget
|
|
741
|
+
verbatim and folds older messages into the rolling summary.
|
|
742
|
+
Chat-only sessions go thousands of turns between
|
|
743
|
+
compactions; browser-heavy sessions compact when budget pressure
|
|
744
|
+
actually warrants it.
|
|
745
|
+
4. **Background memory accumulation, foreground cache stability.**
|
|
746
|
+
Every `async_reconcile_every_turns` turns (default 10), a
|
|
747
|
+
non-blocking `write_run_end` samples the last N turn-pairs from the
|
|
748
|
+
durable transcript and updates long-term memory — but does **not**
|
|
749
|
+
evict the per-session memory cache. New facts are immediately
|
|
750
|
+
visible to OTHER sessions; THIS session sees them at the next
|
|
751
|
+
compaction (where the cache is already breaking for the summary
|
|
752
|
+
refresh).
|
|
753
|
+
|
|
754
|
+
OpenAI's automatic prefix cache and Anthropic's `cache_control` markers
|
|
755
|
+
both match on longest-identical prefix. Together these four changes let
|
|
756
|
+
a typical session pay one cold compaction when the transcript actually
|
|
757
|
+
fills the context window, with warm cache hits on every turn in
|
|
758
|
+
between, while still accumulating memory in the background.
|
|
759
|
+
|
|
760
|
+
The legacy `reconcile_every_turns`, `compact_every_turns`, and
|
|
761
|
+
`compact_message_threshold` knobs have been **removed** — passing them
|
|
762
|
+
to `PersistentAgentConfig` is a clear `TypeError` rather than a silent
|
|
763
|
+
no-op so existing user code can be updated explicitly. Reconciliation
|
|
764
|
+
fires on (a) user-explicit `remember` / `prefer` / `always` / etc.
|
|
765
|
+
signals (immediate, evicts cache), (b) periodic background async path
|
|
766
|
+
(non-blocking, no eviction), or (c) compaction (with the summary LLM
|
|
767
|
+
call, evicts cache).
|
|
768
|
+
|
|
769
|
+
The demo stores local state under `~/.agent-harness` by default:
|
|
770
|
+
|
|
771
|
+
- `sessions.sqlite` for chat/session state
|
|
772
|
+
- `memory/semantic.sqlite` for semantic facts/preferences
|
|
773
|
+
- `memory/lance_episodic` for searchable episodic summaries
|
|
774
|
+
|
|
775
|
+
By default the demo uses `OpenAILLM` and requires `OPENAI_API_KEY`.
|
|
776
|
+
To run it with stored OpenAI subscription credentials instead:
|
|
777
|
+
|
|
778
|
+
```bash
|
|
779
|
+
python -m harness.cli login openai-codex
|
|
780
|
+
python examples/persistent_agent_demo.py --provider openai-codex
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
Or with stored Claude Code credentials:
|
|
784
|
+
|
|
785
|
+
```bash
|
|
786
|
+
python -m harness.cli login claude-code
|
|
787
|
+
python examples/persistent_agent_demo.py --provider claude-code
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
The wrapper owns cadence:
|
|
791
|
+
|
|
792
|
+
- session transcript is written every turn without an LLM;
|
|
793
|
+
- `MemoryManager.write_run_end(...)` runs synchronously only for explicit
|
|
794
|
+
durable user signals such as "remember" / "prefer" / "always";
|
|
795
|
+
- background async reconciliation samples the durable transcript every
|
|
796
|
+
`async_reconcile_every_turns` turns without evicting the current
|
|
797
|
+
session's memory-context cache;
|
|
798
|
+
- session compaction runs under context pressure and updates the stored
|
|
799
|
+
summary while trimming older transcript messages.
|
|
800
|
+
|
|
801
|
+
For MCP, put MCP tools on the coordinator or sub-agents before wrapping.
|
|
802
|
+
`PersistentAgent` does not special-case MCP auth; it preserves the existing
|
|
803
|
+
tool wiring model.
|
|
804
|
+
|
|
544
805
|
---
|
|
545
806
|
|
|
546
807
|
Event types by path:
|
|
@@ -600,9 +861,27 @@ a string to `n` characters with a trailing `…`.
|
|
|
600
861
|
|
|
601
862
|
## Working memory budget
|
|
602
863
|
|
|
603
|
-
`AgentConfig.working_memory_max_tokens` controls per-agent eviction
|
|
604
|
-
`
|
|
605
|
-
|
|
864
|
+
`AgentConfig.working_memory_max_tokens` controls per-agent eviction. **Default
|
|
865
|
+
is `None` — auto-derived from the LLM's context window at runtime** so the
|
|
866
|
+
threshold adapts when you swap models (a 128K `gpt-5.4-mini` gets ~99K of WM
|
|
867
|
+
headroom; a 200K `claude-sonnet-4-6` gets ~159K; a tiny 8K fallback gets ~6K).
|
|
868
|
+
Concretely the WM compacts at `0.8 × llm.input_token_budget`, leaving 20%
|
|
869
|
+
headroom for system prompt, memory context, tool schemas, and tokeniser
|
|
870
|
+
variance.
|
|
871
|
+
|
|
872
|
+
Each shipped adapter (`OpenAILLM`, `AnthropicLLM`, `ClaudeCodeLLM`,
|
|
873
|
+
`OpenAICodexLLM`) exposes `context_window` and `input_token_budget`
|
|
874
|
+
properties driven by a per-provider lookup table. For models the table
|
|
875
|
+
doesn't know (new releases, fine-tunes), pass `context_window=N` explicitly:
|
|
876
|
+
|
|
877
|
+
```python
|
|
878
|
+
llm = OpenAILLM(model="gpt-6-preview", context_window=256_000)
|
|
879
|
+
# or hard-cap WM independent of the LLM:
|
|
880
|
+
AgentConfig(..., working_memory_max_tokens=16_000)
|
|
881
|
+
```
|
|
882
|
+
|
|
883
|
+
Counting defaults to a `chars/4` heuristic (stable for code/JSON/text within
|
|
884
|
+
~10–20% of real BPE counts, zero deps). For exact counts plug your own
|
|
606
885
|
counter into `WorkingMemory` directly:
|
|
607
886
|
|
|
608
887
|
```python
|
|
@@ -1376,7 +1655,7 @@ agents alongside HITL on the shell tool.
|
|
|
1376
1655
|
| `max_wall_time_seconds` | (guardrail) | See `GuardrailConfig` |
|
|
1377
1656
|
| `memory_context_enabled` | `True` | Prepend relevant long-term memory to the system prompt |
|
|
1378
1657
|
| `confidence_from_llm` | `True` | Use the `confidence` field from the LLM response; set `False` to always return `1.0` |
|
|
1379
|
-
| `working_memory_max_tokens` | `
|
|
1658
|
+
| `working_memory_max_tokens` | `None` (auto-derive from `llm.input_token_budget × 0.8`; pass an int to hard-cap) | Token budget for in-context working memory before rolling summarisation kicks in |
|
|
1380
1659
|
| `hitl_tools` | `[]` | Tool names that require human approval before execution |
|
|
1381
1660
|
| `checkpoint_every` | `0` | Write a crash-resumable checkpoint every N steps; `0` disables periodic checkpoints |
|
|
1382
1661
|
| `stream_tokens` | `False` | Emit `TOKEN` events as the LLM streams. Disabled by default — enable if you want to render partial output in real time: `AgentConfig(..., stream_tokens=True)` |
|