react-agent-harness 0.10.0__tar.gz → 0.10.1__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.
Files changed (105) hide show
  1. {react_agent_harness-0.10.0/react_agent_harness.egg-info → react_agent_harness-0.10.1}/PKG-INFO +1 -1
  2. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/README.md +24 -0
  3. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/persistent.py +170 -1
  4. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/persistent_completion.py +25 -0
  5. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/persistent_controls.py +92 -4
  6. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/pyproject.toml +1 -1
  7. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1/react_agent_harness.egg-info}/PKG-INFO +1 -1
  8. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_persistent_agent.py +199 -0
  9. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_persistent_completion.py +14 -1
  10. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_persistent_controls.py +108 -0
  11. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/LICENSE +0 -0
  12. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/agents/__init__.py +0 -0
  13. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/agents/base.py +0 -0
  14. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/__init__.py +0 -0
  15. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/annotation.py +0 -0
  16. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/cancellation.py +0 -0
  17. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/checkpoint.py +0 -0
  18. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/cli.py +0 -0
  19. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/console.py +0 -0
  20. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/events.py +0 -0
  21. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/executor_bridge.py +0 -0
  22. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/hitl.py +0 -0
  23. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/__init__.py +0 -0
  24. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/_streaming.py +0 -0
  25. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/anthropic.py +0 -0
  26. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/auth.py +0 -0
  27. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/claude_code.py +0 -0
  28. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/fallback.py +0 -0
  29. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/openai.py +0 -0
  30. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/openai_codex.py +0 -0
  31. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/llm/routing.py +0 -0
  32. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/oauth_browser.py +0 -0
  33. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/otel.py +0 -0
  34. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/persistent_prompt.py +0 -0
  35. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/runtime.py +0 -0
  36. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/steering.py +0 -0
  37. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/streaming.py +0 -0
  38. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/tool_policy.py +0 -0
  39. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/trace.py +0 -0
  40. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/trace_viewer.py +0 -0
  41. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/harness/utils.py +0 -0
  42. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/__init__.py +0 -0
  43. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/episodic_lance.py +0 -0
  44. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/manager.py +0 -0
  45. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/redis_store.py +0 -0
  46. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/stores.py +0 -0
  47. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/memory/working.py +0 -0
  48. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/orchestrator/__init__.py +0 -0
  49. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/orchestrator/planner.py +0 -0
  50. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/react_agent_harness.egg-info/SOURCES.txt +0 -0
  51. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/react_agent_harness.egg-info/dependency_links.txt +0 -0
  52. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/react_agent_harness.egg-info/entry_points.txt +0 -0
  53. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/react_agent_harness.egg-info/requires.txt +0 -0
  54. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/react_agent_harness.egg-info/top_level.txt +0 -0
  55. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/setup.cfg +0 -0
  56. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_agents_base.py +0 -0
  57. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_annotation.py +0 -0
  58. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_anthropic_llm.py +0 -0
  59. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_budget_guard.py +0 -0
  60. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_cancellation.py +0 -0
  61. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_checkpoint_resume.py +0 -0
  62. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_claude_code_llm.py +0 -0
  63. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_cli.py +0 -0
  64. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_console_renderer.py +0 -0
  65. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_executor_bridge.py +0 -0
  66. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_fallback_llm.py +0 -0
  67. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_fan_in.py +0 -0
  68. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_http_fetch.py +0 -0
  69. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_llm_auth.py +0 -0
  70. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_mcp_adapter.py +0 -0
  71. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_mcp_auth.py +0 -0
  72. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_memory.py +0 -0
  73. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_memory_reconciler.py +0 -0
  74. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_memory_touchpoints.py +0 -0
  75. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_oauth_browser.py +0 -0
  76. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_openai_codex_llm.py +0 -0
  77. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_openai_llm.py +0 -0
  78. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_orchestrator.py +0 -0
  79. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_otel.py +0 -0
  80. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_parse_action_json.py +0 -0
  81. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_per_call_site_llm.py +0 -0
  82. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_persistent_prompt.py +0 -0
  83. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_plan_approval.py +0 -0
  84. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_plan_mode.py +0 -0
  85. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_redis_store.py +0 -0
  86. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_resume_hint_banner.py +0 -0
  87. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_routing_llm.py +0 -0
  88. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_steering.py +0 -0
  89. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_streaming.py +0 -0
  90. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_subagent_tool.py +0 -0
  91. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_system_prompt_routing.py +0 -0
  92. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_tool_policy.py +0 -0
  93. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_trace.py +0 -0
  94. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_trailing_assistant_state.py +0 -0
  95. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_utils.py +0 -0
  96. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_vision.py +0 -0
  97. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tests/test_working_memory.py +0 -0
  98. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/__init__.py +0 -0
  99. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/builtin/__init__.py +0 -0
  100. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/builtin/fetch_image.py +0 -0
  101. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/builtin/http_fetch.py +0 -0
  102. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/builtin/subagent.py +0 -0
  103. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/mcp/__init__.py +0 -0
  104. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/mcp/adapter.py +0 -0
  105. {react_agent_harness-0.10.0 → react_agent_harness-0.10.1}/tools/mcp/auth.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: react-agent-harness
3
- Version: 0.10.0
3
+ Version: 0.10.1
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
@@ -633,6 +633,11 @@ app = PersistentAgent(
633
633
  session_store=SQLiteSessionStore("~/.agent-harness/sessions.sqlite"),
634
634
  memory=memory_manager,
635
635
  llm=llm,
636
+ llm_registry={
637
+ "fast": lambda: OpenAILLM(model="gpt-5.4-mini"),
638
+ "deep": lambda: OpenAILLM(model="gpt-5"),
639
+ },
640
+ default_model="fast",
636
641
  )
637
642
 
638
643
  async for event in app.chat("I like the above; can you do X?", session_id="thread-1"):
@@ -643,6 +648,23 @@ Use `app.capabilities()` to inspect the already-wired coordinator,
643
648
  sub-agents, and MCP tools. The demo exposes this with
644
649
  `--show-capabilities`.
645
650
 
651
+ Model switching is session-scoped when an `llm_registry` is configured:
652
+
653
+ ```python
654
+ await app.switch_model("thread-1", "coordinator", "deep")
655
+ await app.clear_model_override("thread-1", "coordinator")
656
+ ```
657
+
658
+ Registry values are zero-argument factories. Model names `default`,
659
+ `reset`, and `clear` are reserved for clearing overrides in interactive
660
+ controls.
661
+
662
+ The durable session stores only `{agent_id: model_name}` overrides; the
663
+ transcript is unchanged. At the start of each turn, `PersistentAgent`
664
+ resets agents to their construction-time LLMs, then applies that session's
665
+ overrides. The facade assumes one active chat turn at a time for a given
666
+ `PersistentAgent` instance.
667
+
646
668
  Persistent sessions also expose a small control surface for user interfaces:
647
669
 
648
670
  ```python
@@ -705,6 +727,8 @@ The demo uses that utility for:
705
727
  - `/capabilities`, `/agents`, `/mcp` inspect wired agents and tools
706
728
  - `/session` shows turns, context-pressure estimate, reconcile cadence, and summary
707
729
  - `/usage` shows persisted total and last-run provider-reported token usage
730
+ - `/models` lists switchable model names when an LLM registry is configured
731
+ - `/model [agent_id] [model|default]` shows or changes a session-scoped model override
708
732
  - `/sessions [query]` lists known session ids, optionally filtered by id text
709
733
  - `/memory` shows the cached per-session memory context
710
734
  - `/save` flushes turns after the last reconcile checkpoint into long-term memory **without** evicting the cached prior (foreground prefix stays warm)
@@ -247,6 +247,10 @@ class SessionState:
247
247
  last_run_tokens_in: int = 0
248
248
  last_run_tokens_out: int = 0
249
249
  last_usage: dict[str, Any] = field(default_factory=dict)
250
+ # Session-scoped model overrides: agent_id -> model registry key.
251
+ # Applied at chat-turn start so switching models does not mutate the
252
+ # durable transcript.
253
+ model_overrides: dict[str, str] = field(default_factory=dict)
250
254
  # When True, ``PersistentAgent.chat`` proposes a plan and gates
251
255
  # execution on HITL approval before running the ReAct loop. Per
252
256
  # session so plan-mode preference is sticky across process restarts
@@ -290,6 +294,10 @@ class SessionStore(Protocol):
290
294
 
291
295
  async def set_plan_mode(self, session_id: str, enabled: bool) -> SessionState: ...
292
296
 
297
+ async def set_model_override(
298
+ self, session_id: str, agent_id: str, model_name: str | None
299
+ ) -> SessionState: ...
300
+
293
301
 
294
302
  class InMemorySessionStore:
295
303
  """Small test/demo session store."""
@@ -393,6 +401,17 @@ class InMemorySessionStore:
393
401
  state.updated_at = _now()
394
402
  return _copy_state(state)
395
403
 
404
+ async def set_model_override(
405
+ self, session_id: str, agent_id: str, model_name: str | None
406
+ ) -> SessionState:
407
+ state = self._sessions.setdefault(session_id, SessionState(session_id=session_id))
408
+ if model_name:
409
+ state.model_overrides[agent_id] = model_name
410
+ else:
411
+ state.model_overrides.pop(agent_id, None)
412
+ state.updated_at = _now()
413
+ return _copy_state(state)
414
+
396
415
 
397
416
  class SQLiteSessionStore:
398
417
  """Durable local session store using stdlib SQLite."""
@@ -597,6 +616,29 @@ class SQLiteSessionStore:
597
616
  )
598
617
  return self._load_locked(conn, session_id)
599
618
 
619
+ async def set_model_override(
620
+ self, session_id: str, agent_id: str, model_name: str | None
621
+ ) -> SessionState:
622
+ self._ensure_schema()
623
+ with self._connect() as conn:
624
+ self._ensure_session(conn, session_id)
625
+ state = self._load_locked(conn, session_id)
626
+ overrides = dict(state.model_overrides)
627
+ if model_name:
628
+ overrides[agent_id] = model_name
629
+ else:
630
+ overrides.pop(agent_id, None)
631
+ conn.execute(
632
+ """
633
+ UPDATE sessions
634
+ SET model_overrides_json = ?,
635
+ updated_at = ?
636
+ WHERE session_id = ?
637
+ """,
638
+ (json.dumps(overrides, sort_keys=True), _now(), session_id),
639
+ )
640
+ return self._load_locked(conn, session_id)
641
+
600
642
  async def _mark(self, session_id: str, column: str, turn_count: int) -> SessionState:
601
643
  self._ensure_schema()
602
644
  if column not in {"last_reconcile_turn", "last_compact_turn"}:
@@ -632,6 +674,7 @@ class SQLiteSessionStore:
632
674
  last_run_tokens_in INTEGER NOT NULL DEFAULT 0,
633
675
  last_run_tokens_out INTEGER NOT NULL DEFAULT 0,
634
676
  last_usage_json TEXT NOT NULL DEFAULT '{}',
677
+ model_overrides_json TEXT NOT NULL DEFAULT '{}',
635
678
  plan_mode_enabled INTEGER NOT NULL DEFAULT 0,
636
679
  updated_at TEXT NOT NULL
637
680
  )
@@ -672,6 +715,7 @@ class SQLiteSessionStore:
672
715
  "last_run_tokens_in": "INTEGER NOT NULL DEFAULT 0",
673
716
  "last_run_tokens_out": "INTEGER NOT NULL DEFAULT 0",
674
717
  "last_usage_json": "TEXT NOT NULL DEFAULT '{}'",
718
+ "model_overrides_json": "TEXT NOT NULL DEFAULT '{}'",
675
719
  "plan_mode_enabled": "INTEGER NOT NULL DEFAULT 0",
676
720
  }
677
721
  for column, ddl in additions.items():
@@ -693,7 +737,7 @@ class SQLiteSessionStore:
693
737
  SELECT session_id, summary, turn_count, last_reconcile_turn,
694
738
  last_compact_turn, tokens_in_total, tokens_out_total,
695
739
  last_run_tokens_in, last_run_tokens_out, last_usage_json,
696
- plan_mode_enabled, updated_at
740
+ model_overrides_json, plan_mode_enabled, updated_at
697
741
  FROM sessions
698
742
  WHERE session_id = ?
699
743
  """,
@@ -727,6 +771,7 @@ class SQLiteSessionStore:
727
771
  last_run_tokens_in=row["last_run_tokens_in"],
728
772
  last_run_tokens_out=row["last_run_tokens_out"],
729
773
  last_usage=json.loads(row["last_usage_json"] or "{}"),
774
+ model_overrides=json.loads(row["model_overrides_json"] or "{}"),
730
775
  plan_mode_enabled=bool(row["plan_mode_enabled"]),
731
776
  updated_at=row["updated_at"],
732
777
  )
@@ -781,13 +826,39 @@ class PersistentAgent:
781
826
  llm: Any | None = None,
782
827
  guard_factory: Callable[[], Any] | None = None,
783
828
  config: PersistentAgentConfig | None = None,
829
+ llm_registry: dict[str, Callable[[], Any]] | None = None,
830
+ default_model: str | None = None,
784
831
  ) -> None:
785
832
  self._coordinator = coordinator
786
833
  self._session_store = session_store
787
834
  self._memory = memory
835
+ self._explicit_llm = llm is not None
788
836
  self._llm = llm or coordinator._llm
789
837
  self._guard_factory = guard_factory
790
838
  self._config = config or PersistentAgentConfig()
839
+ self._llm_registry = dict(llm_registry or {})
840
+ reserved_models = {"default", "reset", "clear"}
841
+ collisions = sorted(
842
+ model for model in self._llm_registry if model.lower() in reserved_models
843
+ )
844
+ if collisions:
845
+ joined = ", ".join(repr(model) for model in collisions)
846
+ raise ValueError(f"model names are reserved for clearing overrides: {joined}")
847
+ non_factories = sorted(
848
+ model for model, factory in self._llm_registry.items() if not callable(factory)
849
+ )
850
+ if non_factories:
851
+ joined = ", ".join(repr(model) for model in non_factories)
852
+ raise TypeError(f"llm_registry entries must be zero-argument factories: {joined}")
853
+ if (
854
+ default_model is not None
855
+ and self._llm_registry
856
+ and default_model not in self._llm_registry
857
+ ):
858
+ raise ValueError(f"default_model {default_model!r} is not present in llm_registry")
859
+ self._default_model = default_model
860
+ self._llm_instances: dict[str, Any] = {}
861
+ self._default_agent_llms = self._snapshot_agent_llms()
791
862
  # Per-session memory-context cache. Memory retrieval used to fire
792
863
  # on every turn (inside ``_build_system_prompt``), which made the
793
864
  # system prompt content-dependent on whatever ``build_context``
@@ -825,6 +896,48 @@ class PersistentAgent:
825
896
  state = await self._session_store.load(session_id)
826
897
  return state.plan_mode_enabled
827
898
 
899
+ def available_models(self) -> list[str]:
900
+ """Return model names available for session-scoped switching."""
901
+ return sorted(self._llm_registry)
902
+
903
+ def default_model(self) -> str | None:
904
+ """Return the label for the construction-time/default model, if supplied."""
905
+ return self._default_model
906
+
907
+ def model_switching_enabled(self) -> bool:
908
+ """True when an LLM registry was supplied at construction time."""
909
+ return bool(self._llm_registry)
910
+
911
+ def context_token_budget(self) -> int | None:
912
+ """Return the live coordinator input budget used for compaction."""
913
+ return self._coordinator_input_token_budget()
914
+
915
+ async def model_overrides(self, session_id: str) -> dict[str, str]:
916
+ """Return session-scoped agent_id -> model_name overrides."""
917
+ state = await self._session_store.load(session_id)
918
+ return dict(state.model_overrides)
919
+
920
+ async def switch_model(
921
+ self,
922
+ session_id: str,
923
+ agent_id: str,
924
+ model_name: str,
925
+ ) -> SessionState:
926
+ """Persist and apply a session-scoped model override for one agent."""
927
+ if model_name not in self._llm_registry:
928
+ raise ValueError(f"unknown model {model_name!r}")
929
+ if self._find_agent(agent_id) is None:
930
+ raise ValueError(f"unknown agent {agent_id!r}")
931
+ state = await self._session_store.set_model_override(session_id, agent_id, model_name)
932
+ self._apply_model_overrides(state)
933
+ return state
934
+
935
+ async def clear_model_override(self, session_id: str, agent_id: str) -> SessionState:
936
+ """Remove and apply a session-scoped model override for one agent."""
937
+ state = await self._session_store.set_model_override(session_id, agent_id, None)
938
+ self._apply_model_overrides(state)
939
+ return state
940
+
828
941
  async def chat(
829
942
  self,
830
943
  message: str,
@@ -840,6 +953,7 @@ class PersistentAgent:
840
953
  ``ERROR`` and returns without writing to the session store.
841
954
  """
842
955
  state = await self._session_store.load(session_id)
956
+ self._apply_model_overrides(state)
843
957
  run_id = run_id or str(uuid.uuid4())
844
958
  memory_context_text = await self._get_session_memory_context(session_id, message=message)
845
959
  prior_messages, pinned_priors = self._build_prior_messages(
@@ -1190,6 +1304,60 @@ class PersistentAgent:
1190
1304
  self._evict_session_memory_context(session_id)
1191
1305
  return deleted
1192
1306
 
1307
+ def _snapshot_agent_llms(self) -> dict[str, Any]:
1308
+ return {
1309
+ agent.config.agent_id: getattr(agent, "_llm", None) for agent in self._iter_agents()
1310
+ }
1311
+
1312
+ def _iter_agents(self) -> list[BaseAgent]:
1313
+ agents: list[BaseAgent] = []
1314
+ seen: set[int] = set()
1315
+
1316
+ def visit(agent: BaseAgent) -> None:
1317
+ if id(agent) in seen:
1318
+ return
1319
+ seen.add(id(agent))
1320
+ agents.append(agent)
1321
+ for tool in getattr(agent, "_tools", {}).values():
1322
+ sub = _subagent_tool_agent(tool)
1323
+ if sub is not None:
1324
+ visit(sub)
1325
+
1326
+ visit(self._coordinator)
1327
+ return agents
1328
+
1329
+ def _find_agent(self, agent_id: str) -> BaseAgent | None:
1330
+ for agent in self._iter_agents():
1331
+ if agent.config.agent_id == agent_id:
1332
+ return agent
1333
+ return None
1334
+
1335
+ def _make_registered_llm(self, model_name: str) -> Any:
1336
+ llm = self._llm_instances.get(model_name)
1337
+ if llm is None:
1338
+ llm = self._llm_registry[model_name]()
1339
+ self._llm_instances[model_name] = llm
1340
+ return llm
1341
+
1342
+ def _apply_model_overrides(self, state: SessionState) -> None:
1343
+ # Reset first so switching sessions cannot leak a previous
1344
+ # session's model choice into this one.
1345
+ for agent in self._iter_agents():
1346
+ self._default_agent_llms.setdefault(agent.config.agent_id, getattr(agent, "_llm", None))
1347
+ agent._llm = self._default_agent_llms[agent.config.agent_id]
1348
+
1349
+ for agent_id, model_name in state.model_overrides.items():
1350
+ agent = self._find_agent(agent_id)
1351
+ if agent is None or model_name not in self._llm_registry:
1352
+ continue
1353
+ agent._llm = self._make_registered_llm(model_name)
1354
+ guard = getattr(agent, "_guard", None)
1355
+ if guard is not None and hasattr(agent._llm, "set_budget"):
1356
+ agent._llm.set_budget(guard)
1357
+
1358
+ if not self._explicit_llm:
1359
+ self._llm = self._coordinator._llm
1360
+
1193
1361
  def _assign_guard(self, guard: Any) -> None:
1194
1362
  seen_agents: set[int] = set()
1195
1363
 
@@ -1674,6 +1842,7 @@ def _copy_state(state: SessionState) -> SessionState:
1674
1842
  last_run_tokens_in=state.last_run_tokens_in,
1675
1843
  last_run_tokens_out=state.last_run_tokens_out,
1676
1844
  last_usage=dict(state.last_usage),
1845
+ model_overrides=dict(state.model_overrides),
1677
1846
  plan_mode_enabled=state.plan_mode_enabled,
1678
1847
  updated_at=state.updated_at,
1679
1848
  )
@@ -113,12 +113,37 @@ class SlashCommandCompleter(Completer):
113
113
  start_position=-len(current_word),
114
114
  display_meta="enable" if literal == "on" else "disable",
115
115
  )
116
+ elif spec.arg_kind == "model_switch":
117
+ if arg_index == 0:
118
+ for agent_id in self._agent_ids():
119
+ if agent_id.startswith(current_word):
120
+ yield Completion(
121
+ agent_id,
122
+ start_position=-len(current_word),
123
+ display_meta="agent",
124
+ )
125
+ elif arg_index == 1:
126
+ for model in [*self._app.available_models(), "default"]:
127
+ if model.startswith(current_word):
128
+ yield Completion(
129
+ model,
130
+ start_position=-len(current_word),
131
+ display_meta="model" if model != "default" else "clear override",
132
+ )
116
133
  elif spec.arg_kind == "query":
117
134
  # Free text — suggest session ids as a hint for /sessions filter.
118
135
  if arg_index == 0:
119
136
  async for completion in self._session_id_completions(current_word):
120
137
  yield completion
121
138
 
139
+ def _agent_ids(self) -> list[str]:
140
+ try:
141
+ caps = self._app.capabilities()
142
+ except Exception: # noqa: BLE001 — completer must never raise into the prompt loop
143
+ return []
144
+ agents = [caps.get("coordinator", {}), *caps.get("subagents", [])]
145
+ return sorted(str(agent.get("agent_id")) for agent in agents if agent.get("agent_id"))
146
+
122
147
  async def _session_id_completions(
123
148
  self,
124
149
  prefix: str,
@@ -14,7 +14,6 @@ from __future__ import annotations
14
14
 
15
15
  from collections.abc import Awaitable, Callable
16
16
  from dataclasses import dataclass, field
17
- from typing import Any
18
17
  from uuid import uuid4
19
18
 
20
19
  from harness.persistent import PersistentAgent, PersistentAgentConfig, SessionState
@@ -40,6 +39,7 @@ class SlashCommandSpec:
40
39
  - ``"session_id_then_confirm"`` — optional session id + required ``confirm`` (e.g. ``/delete``)
41
40
  - ``"query"`` — one optional free-text token (e.g. ``/sessions [query]``)
42
41
  - ``"plan_toggle"`` — one optional ``on`` / ``off`` literal (e.g. ``/plan``)
42
+ - ``"model_switch"`` — agent id plus model name/default (e.g. ``/model researcher gpt-5``)
43
43
  """
44
44
 
45
45
  name: str
@@ -74,6 +74,14 @@ SLASH_COMMAND_SPECS: tuple[SlashCommandSpec, ...] = (
74
74
  "Show token usage totals + last-run breakdown",
75
75
  category="Inspect",
76
76
  ),
77
+ SlashCommandSpec("/models", "List switchable models", category="Inspect"),
78
+ SlashCommandSpec(
79
+ "/model",
80
+ "Show or switch a session-scoped agent model",
81
+ category="Session",
82
+ arg_hint="[agent_id] [model|default]",
83
+ arg_kind="model_switch",
84
+ ),
77
85
  SlashCommandSpec(
78
86
  "/sessions",
79
87
  "List known sessions",
@@ -158,11 +166,9 @@ class PersistentCommandHandler:
158
166
  app: PersistentAgent,
159
167
  *,
160
168
  config: PersistentAgentConfig | None = None,
161
- llm: Any | None = None,
162
169
  ) -> None:
163
170
  self._app = app
164
171
  self._config = config or app.config
165
- self._llm = llm or app.llm
166
172
  self._dispatch: dict[str, _CommandHandler] = self._build_dispatch()
167
173
 
168
174
  def _build_dispatch(self) -> dict[str, _CommandHandler]:
@@ -177,6 +183,8 @@ class PersistentCommandHandler:
177
183
  "/session": self._cmd_session,
178
184
  "/memory": self._cmd_memory,
179
185
  "/usage": self._cmd_usage,
186
+ "/models": self._cmd_models,
187
+ "/model": self._cmd_model,
180
188
  "/sessions": self._cmd_sessions,
181
189
  "/save": self._cmd_save,
182
190
  "/compact": self._cmd_compact,
@@ -245,6 +253,40 @@ class PersistentCommandHandler:
245
253
  ) -> PersistentCommandResult:
246
254
  return self._result(session_id, await self._format_usage(session_id))
247
255
 
256
+ async def _cmd_models(
257
+ self, *, message: str, command: str, session_id: str
258
+ ) -> PersistentCommandResult:
259
+ return self._result(session_id, _format_models(self._app))
260
+
261
+ async def _cmd_model(
262
+ self, *, message: str, command: str, session_id: str
263
+ ) -> PersistentCommandResult:
264
+ parts = message[len(command) :].strip().split()
265
+ if not parts:
266
+ return self._result(session_id, await _format_model_overrides(self._app, session_id))
267
+ if len(parts) == 1:
268
+ return self._result(
269
+ session_id,
270
+ await _format_model_overrides(self._app, session_id, agent_id=parts[0]),
271
+ )
272
+ if len(parts) != 2:
273
+ return self._result(session_id, "usage: /model [agent_id] [model|default]")
274
+ agent_id, model_name = parts
275
+ try:
276
+ if model_name.lower() in {"default", "reset", "clear"}:
277
+ await self._app.clear_model_override(session_id, agent_id)
278
+ return self._result(
279
+ session_id,
280
+ f"model override cleared for {agent_id} in session {session_id}",
281
+ )
282
+ await self._app.switch_model(session_id, agent_id, model_name)
283
+ return self._result(
284
+ session_id,
285
+ f"model override set for {agent_id} in session {session_id}: {model_name}",
286
+ )
287
+ except ValueError as exc:
288
+ return self._result(session_id, f"cannot switch model: {exc}")
289
+
248
290
  async def _cmd_sessions(
249
291
  self, *, message: str, command: str, session_id: str
250
292
  ) -> PersistentCommandResult:
@@ -397,7 +439,7 @@ class PersistentCommandHandler:
397
439
  async def _format_session(self, session_id: str) -> str:
398
440
  state = await self._app.session_state(session_id)
399
441
  tokens = _estimate_session_tokens(state)
400
- budget = getattr(self._llm, "input_token_budget", None)
442
+ budget = self._app.context_token_budget()
401
443
  if isinstance(budget, int) and budget > 0:
402
444
  pct = (tokens / budget) * 100
403
445
  token_line = f"{tokens:,} / {budget:,} tokens ({pct:.1f}%)"
@@ -409,6 +451,11 @@ class PersistentCommandHandler:
409
451
  reconcile = f"turn {state.turn_count + remaining} ({remaining} turn(s))"
410
452
  else:
411
453
  reconcile = "disabled"
454
+ model_line = (
455
+ ", ".join(f"{agent}={model}" for agent, model in sorted(state.model_overrides.items()))
456
+ if state.model_overrides
457
+ else "(none)"
458
+ )
412
459
  return "\n".join(
413
460
  [
414
461
  f"session_id: {state.session_id}",
@@ -416,6 +463,7 @@ class PersistentCommandHandler:
416
463
  f"transcript: {token_line}",
417
464
  f"usage total: in={state.tokens_in_total:,} out={state.tokens_out_total:,}",
418
465
  f"last run: in={state.last_run_tokens_in:,} out={state.last_run_tokens_out:,}",
466
+ f"model overrides: {model_line}",
419
467
  f"last reconcile turn: {state.last_reconcile_turn or 'never'}",
420
468
  f"next async reconcile: {reconcile}",
421
469
  f"last compaction turn: {state.last_compact_turn or 'never'}",
@@ -523,6 +571,46 @@ def _format_mcp(app: PersistentAgent) -> str:
523
571
  return "\n".join(lines)
524
572
 
525
573
 
574
+ def _format_models(app: PersistentAgent) -> str:
575
+ models = app.available_models()
576
+ default = app.default_model()
577
+ if not models:
578
+ return "No model registry is configured for this PersistentAgent."
579
+ lines = ["available models:"]
580
+ for model in models:
581
+ suffix = " (default)" if default and model == default else ""
582
+ lines.append(f" - {model}{suffix}")
583
+ lines.append("switch with: /model <agent_id> <model>")
584
+ return "\n".join(lines)
585
+
586
+
587
+ async def _format_model_overrides(
588
+ app: PersistentAgent,
589
+ session_id: str,
590
+ *,
591
+ agent_id: str | None = None,
592
+ ) -> str:
593
+ caps = app.capabilities()
594
+ agents = [caps["coordinator"], *caps["subagents"]]
595
+ known_ids = {str(agent["agent_id"]) for agent in agents}
596
+ if agent_id is not None and agent_id not in known_ids:
597
+ return f"unknown agent: {agent_id}"
598
+ overrides = await app.model_overrides(session_id)
599
+ default = app.default_model() or "(construction default)"
600
+ selected = [agent for agent in agents if agent_id is None or agent["agent_id"] == agent_id]
601
+ lines = [f"session model overrides for {session_id}:"]
602
+ for agent in selected:
603
+ aid = str(agent["agent_id"])
604
+ model = overrides.get(aid)
605
+ suffix = f"{model} (override)" if model else default
606
+ lines.append(f" - {aid}: {suffix}")
607
+ if app.available_models():
608
+ lines.append("available: " + ", ".join(app.available_models()))
609
+ else:
610
+ lines.append("available: (no model registry configured)")
611
+ return "\n".join(lines)
612
+
613
+
526
614
  def _format_memory(app: PersistentAgent, *, session_id: str) -> str:
527
615
  context = app.cached_memory_context(session_id)
528
616
  if context is None:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "react-agent-harness"
7
- version = "0.10.0"
7
+ version = "0.10.1"
8
8
  description = "Multi-agent LLM orchestration: hybrid DAG planning, two-tier memory, streaming, cost/token budgets with per-call-site breakdown"
9
9
  requires-python = ">=3.10"
10
10
  dependencies = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: react-agent-harness
3
- Version: 0.10.0
3
+ Version: 0.10.1
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