react-agent-harness 0.10.0__tar.gz → 0.10.2__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 (107) hide show
  1. {react_agent_harness-0.10.0/react_agent_harness.egg-info → react_agent_harness-0.10.2}/PKG-INFO +1 -1
  2. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/README.md +72 -0
  3. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/agents/base.py +12 -0
  4. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/persistent.py +176 -1
  5. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/persistent_completion.py +25 -0
  6. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/persistent_controls.py +104 -4
  7. react_agent_harness-0.10.2/harness/skills.py +161 -0
  8. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/pyproject.toml +1 -1
  9. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2/react_agent_harness.egg-info}/PKG-INFO +1 -1
  10. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/react_agent_harness.egg-info/SOURCES.txt +2 -0
  11. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_agents_base.py +30 -0
  12. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_persistent_agent.py +229 -0
  13. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_persistent_completion.py +14 -1
  14. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_persistent_controls.py +128 -0
  15. react_agent_harness-0.10.2/tests/test_skills.py +120 -0
  16. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/LICENSE +0 -0
  17. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/agents/__init__.py +0 -0
  18. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/__init__.py +0 -0
  19. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/annotation.py +0 -0
  20. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/cancellation.py +0 -0
  21. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/checkpoint.py +0 -0
  22. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/cli.py +0 -0
  23. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/console.py +0 -0
  24. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/events.py +0 -0
  25. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/executor_bridge.py +0 -0
  26. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/hitl.py +0 -0
  27. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/__init__.py +0 -0
  28. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/_streaming.py +0 -0
  29. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/anthropic.py +0 -0
  30. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/auth.py +0 -0
  31. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/claude_code.py +0 -0
  32. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/fallback.py +0 -0
  33. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/openai.py +0 -0
  34. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/openai_codex.py +0 -0
  35. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/llm/routing.py +0 -0
  36. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/oauth_browser.py +0 -0
  37. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/otel.py +0 -0
  38. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/persistent_prompt.py +0 -0
  39. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/runtime.py +0 -0
  40. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/steering.py +0 -0
  41. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/streaming.py +0 -0
  42. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/tool_policy.py +0 -0
  43. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/trace.py +0 -0
  44. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/trace_viewer.py +0 -0
  45. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/harness/utils.py +0 -0
  46. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/__init__.py +0 -0
  47. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/episodic_lance.py +0 -0
  48. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/manager.py +0 -0
  49. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/redis_store.py +0 -0
  50. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/stores.py +0 -0
  51. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/memory/working.py +0 -0
  52. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/orchestrator/__init__.py +0 -0
  53. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/orchestrator/planner.py +0 -0
  54. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/react_agent_harness.egg-info/dependency_links.txt +0 -0
  55. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/react_agent_harness.egg-info/entry_points.txt +0 -0
  56. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/react_agent_harness.egg-info/requires.txt +0 -0
  57. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/react_agent_harness.egg-info/top_level.txt +0 -0
  58. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/setup.cfg +0 -0
  59. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_annotation.py +0 -0
  60. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_anthropic_llm.py +0 -0
  61. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_budget_guard.py +0 -0
  62. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_cancellation.py +0 -0
  63. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_checkpoint_resume.py +0 -0
  64. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_claude_code_llm.py +0 -0
  65. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_cli.py +0 -0
  66. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_console_renderer.py +0 -0
  67. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_executor_bridge.py +0 -0
  68. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_fallback_llm.py +0 -0
  69. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_fan_in.py +0 -0
  70. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_http_fetch.py +0 -0
  71. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_llm_auth.py +0 -0
  72. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_mcp_adapter.py +0 -0
  73. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_mcp_auth.py +0 -0
  74. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_memory.py +0 -0
  75. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_memory_reconciler.py +0 -0
  76. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_memory_touchpoints.py +0 -0
  77. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_oauth_browser.py +0 -0
  78. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_openai_codex_llm.py +0 -0
  79. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_openai_llm.py +0 -0
  80. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_orchestrator.py +0 -0
  81. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_otel.py +0 -0
  82. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_parse_action_json.py +0 -0
  83. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_per_call_site_llm.py +0 -0
  84. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_persistent_prompt.py +0 -0
  85. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_plan_approval.py +0 -0
  86. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_plan_mode.py +0 -0
  87. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_redis_store.py +0 -0
  88. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_resume_hint_banner.py +0 -0
  89. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_routing_llm.py +0 -0
  90. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_steering.py +0 -0
  91. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_streaming.py +0 -0
  92. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_subagent_tool.py +0 -0
  93. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_system_prompt_routing.py +0 -0
  94. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_tool_policy.py +0 -0
  95. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_trace.py +0 -0
  96. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_trailing_assistant_state.py +0 -0
  97. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_utils.py +0 -0
  98. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_vision.py +0 -0
  99. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tests/test_working_memory.py +0 -0
  100. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/__init__.py +0 -0
  101. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/builtin/__init__.py +0 -0
  102. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/builtin/fetch_image.py +0 -0
  103. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/builtin/http_fetch.py +0 -0
  104. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/builtin/subagent.py +0 -0
  105. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/mcp/__init__.py +0 -0
  106. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/tools/mcp/adapter.py +0 -0
  107. {react_agent_harness-0.10.0 → react_agent_harness-0.10.2}/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.2
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
@@ -114,6 +114,53 @@ agents.register(AgentConfig(
114
114
  result = await runtime.dispatch("my goal")
115
115
  ```
116
116
 
117
+ Agents can also attach reusable prompt skills from Agent Skills-style
118
+ directories:
119
+
120
+ ```text
121
+ skills/
122
+ web-research/
123
+ SKILL.md
124
+ references/ # optional
125
+ scripts/ # optional
126
+ ```
127
+
128
+ ```md
129
+ ---
130
+ name: web-research
131
+ description: Research current information from primary sources.
132
+ allowed-tools:
133
+ - browser_navigate
134
+ - browser_snapshot
135
+ ---
136
+
137
+ Prefer primary sources, capture dates, and cite URLs.
138
+ ```
139
+
140
+ ```python
141
+ from harness.skills import load_skill, load_skills
142
+
143
+ web_research = load_skill("skills/web-research")
144
+ # Or load every immediate child directory with a SKILL.md:
145
+ # skills = load_skills("skills")
146
+ # Calling load_skills() with no path loads ~/.agent-harness/skills
147
+ # and returns [] when that default directory does not exist.
148
+
149
+ agents.register(AgentConfig(
150
+ agent_id="researcher",
151
+ role="researches current information",
152
+ system_prompt="You are a careful research agent.",
153
+ allowed_tools=["browser_navigate", "browser_snapshot"],
154
+ skills=[web_research],
155
+ ))
156
+ ```
157
+
158
+ Skills add reusable instructions and tool hints to that agent's system prompt.
159
+ They do not grant tools; `allowed-tools` in `SKILL.md` is treated as a hint
160
+ only. Tool access still comes from the wired tool map and the agent's
161
+ configured tool surface. You can also construct `Skill(...)` directly when a
162
+ programmatic skill is more convenient.
163
+
117
164
  ## LLM clients
118
165
 
119
166
  The harness is **BYO-LLM.** Any object with
@@ -633,6 +680,11 @@ app = PersistentAgent(
633
680
  session_store=SQLiteSessionStore("~/.agent-harness/sessions.sqlite"),
634
681
  memory=memory_manager,
635
682
  llm=llm,
683
+ llm_registry={
684
+ "fast": lambda: OpenAILLM(model="gpt-5.4-mini"),
685
+ "deep": lambda: OpenAILLM(model="gpt-5"),
686
+ },
687
+ default_model="fast",
636
688
  )
637
689
 
638
690
  async for event in app.chat("I like the above; can you do X?", session_id="thread-1"):
@@ -643,6 +695,23 @@ Use `app.capabilities()` to inspect the already-wired coordinator,
643
695
  sub-agents, and MCP tools. The demo exposes this with
644
696
  `--show-capabilities`.
645
697
 
698
+ Model switching is session-scoped when an `llm_registry` is configured:
699
+
700
+ ```python
701
+ await app.switch_model("thread-1", "coordinator", "deep")
702
+ await app.clear_model_override("thread-1", "coordinator")
703
+ ```
704
+
705
+ Registry values are zero-argument factories. Model names `default`,
706
+ `reset`, and `clear` are reserved for clearing overrides in interactive
707
+ controls.
708
+
709
+ The durable session stores only `{agent_id: model_name}` overrides; the
710
+ transcript is unchanged. At the start of each turn, `PersistentAgent`
711
+ resets agents to their construction-time LLMs, then applies that session's
712
+ overrides. The facade assumes one active chat turn at a time for a given
713
+ `PersistentAgent` instance.
714
+
646
715
  Persistent sessions also expose a small control surface for user interfaces:
647
716
 
648
717
  ```python
@@ -705,6 +774,8 @@ The demo uses that utility for:
705
774
  - `/capabilities`, `/agents`, `/mcp` inspect wired agents and tools
706
775
  - `/session` shows turns, context-pressure estimate, reconcile cadence, and summary
707
776
  - `/usage` shows persisted total and last-run provider-reported token usage
777
+ - `/models` lists switchable model names when an LLM registry is configured
778
+ - `/model [agent_id] [model|default]` shows or changes a session-scoped model override
708
779
  - `/sessions [query]` lists known session ids, optionally filtered by id text
709
780
  - `/memory` shows the cached per-session memory context
710
781
  - `/save` flushes turns after the last reconcile checkpoint into long-term memory **without** evicting the cached prior (foreground prefix stays warm)
@@ -1704,6 +1775,7 @@ agents alongside HITL on the shell tool.
1704
1775
  | `role` | required | Plain-English description used by the planner for agent selection |
1705
1776
  | `system_prompt` | required | Base system prompt for the agent |
1706
1777
  | `allowed_tools` | required | Tool names the agent may call |
1778
+ | `skills` | `[]` | Reusable prompt/context bundles attached to this agent; skills do not grant tools |
1707
1779
  | `max_steps` | `10` | Maximum ReAct iterations before the run is terminated |
1708
1780
  | `max_wall_time_seconds` | (guardrail) | See `GuardrailConfig` |
1709
1781
  | `memory_context_enabled` | `True` | Prepend relevant long-term memory to the system prompt |
@@ -39,6 +39,7 @@ from typing import Any, Final
39
39
 
40
40
  from harness.checkpoint import _ResumeHint
41
41
  from harness.events import BusEvent, EventType
42
+ from harness.skills import Skill
42
43
  from harness.utils import fire
43
44
  from memory.manager import MemoryManager
44
45
  from memory.working import WorkingMemory
@@ -89,6 +90,10 @@ class AgentConfig:
89
90
  # other's lookups (HTTPFetch on stable URLs, ``kubectl get …`` style
90
91
  # discovery, MCP filesystem reads).
91
92
  cache_tool_results: bool = False
93
+ # Prompt/context bundles attached explicitly to this agent. Skills do
94
+ # not grant tools; they only add reusable instructions and hints to the
95
+ # system prompt.
96
+ skills: list[Skill] = None
92
97
  # Hard cap on how deep a SubAgentTool chain may recurse. Depth 0 = the
93
98
  # top-level agent invoked by AgentRuntime; depth 1 = a sub-agent
94
99
  # delegated to from the top; depth 2 = a sub-agent that itself
@@ -100,6 +105,8 @@ class AgentConfig:
100
105
  def __post_init__(self):
101
106
  if self.hitl_tools is None:
102
107
  self.hitl_tools = []
108
+ if self.skills is None:
109
+ self.skills = []
103
110
 
104
111
 
105
112
  # ── ReAct Response Schema ─────────────────────────────────────────────────────
@@ -441,6 +448,11 @@ class BaseAgent:
441
448
  """
442
449
  parts = [self.config.system_prompt]
443
450
 
451
+ if self.config.skills:
452
+ rendered_skills = "\n\n".join(skill.render() for skill in self.config.skills)
453
+ if rendered_skills:
454
+ parts.append("## Skills\n" + rendered_skills)
455
+
444
456
  memory_in_system_prompt = (
445
457
  self.config.memory_context_enabled and precomputed_memory_context != "_skip_"
446
458
  )
@@ -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(
@@ -1075,6 +1189,7 @@ class PersistentAgent:
1075
1189
  sub_info = {
1076
1190
  "agent_id": sub.config.agent_id,
1077
1191
  "role": sub.role,
1192
+ "skills": _describe_skills(sub),
1078
1193
  "tool_name": tool_name,
1079
1194
  "parent_agent_id": parent_agent_id,
1080
1195
  "tools": sorted(getattr(sub, "_tools", {}).keys()),
@@ -1190,6 +1305,60 @@ class PersistentAgent:
1190
1305
  self._evict_session_memory_context(session_id)
1191
1306
  return deleted
1192
1307
 
1308
+ def _snapshot_agent_llms(self) -> dict[str, Any]:
1309
+ return {
1310
+ agent.config.agent_id: getattr(agent, "_llm", None) for agent in self._iter_agents()
1311
+ }
1312
+
1313
+ def _iter_agents(self) -> list[BaseAgent]:
1314
+ agents: list[BaseAgent] = []
1315
+ seen: set[int] = set()
1316
+
1317
+ def visit(agent: BaseAgent) -> None:
1318
+ if id(agent) in seen:
1319
+ return
1320
+ seen.add(id(agent))
1321
+ agents.append(agent)
1322
+ for tool in getattr(agent, "_tools", {}).values():
1323
+ sub = _subagent_tool_agent(tool)
1324
+ if sub is not None:
1325
+ visit(sub)
1326
+
1327
+ visit(self._coordinator)
1328
+ return agents
1329
+
1330
+ def _find_agent(self, agent_id: str) -> BaseAgent | None:
1331
+ for agent in self._iter_agents():
1332
+ if agent.config.agent_id == agent_id:
1333
+ return agent
1334
+ return None
1335
+
1336
+ def _make_registered_llm(self, model_name: str) -> Any:
1337
+ llm = self._llm_instances.get(model_name)
1338
+ if llm is None:
1339
+ llm = self._llm_registry[model_name]()
1340
+ self._llm_instances[model_name] = llm
1341
+ return llm
1342
+
1343
+ def _apply_model_overrides(self, state: SessionState) -> None:
1344
+ # Reset first so switching sessions cannot leak a previous
1345
+ # session's model choice into this one.
1346
+ for agent in self._iter_agents():
1347
+ self._default_agent_llms.setdefault(agent.config.agent_id, getattr(agent, "_llm", None))
1348
+ agent._llm = self._default_agent_llms[agent.config.agent_id]
1349
+
1350
+ for agent_id, model_name in state.model_overrides.items():
1351
+ agent = self._find_agent(agent_id)
1352
+ if agent is None or model_name not in self._llm_registry:
1353
+ continue
1354
+ agent._llm = self._make_registered_llm(model_name)
1355
+ guard = getattr(agent, "_guard", None)
1356
+ if guard is not None and hasattr(agent._llm, "set_budget"):
1357
+ agent._llm.set_budget(guard)
1358
+
1359
+ if not self._explicit_llm:
1360
+ self._llm = self._coordinator._llm
1361
+
1193
1362
  def _assign_guard(self, guard: Any) -> None:
1194
1363
  seen_agents: set[int] = set()
1195
1364
 
@@ -1674,6 +1843,7 @@ def _copy_state(state: SessionState) -> SessionState:
1674
1843
  last_run_tokens_in=state.last_run_tokens_in,
1675
1844
  last_run_tokens_out=state.last_run_tokens_out,
1676
1845
  last_usage=dict(state.last_usage),
1846
+ model_overrides=dict(state.model_overrides),
1677
1847
  plan_mode_enabled=state.plan_mode_enabled,
1678
1848
  updated_at=state.updated_at,
1679
1849
  )
@@ -1705,6 +1875,7 @@ def _describe_agent(agent: BaseAgent) -> dict[str, Any]:
1705
1875
  return {
1706
1876
  "agent_id": agent.config.agent_id,
1707
1877
  "role": agent.role,
1878
+ "skills": _describe_skills(agent),
1708
1879
  "tools": sorted(tools.keys()),
1709
1880
  "mcp_tools": [
1710
1881
  _describe_mcp_tool(tool, owner_agent_id=agent.config.agent_id)
@@ -1714,6 +1885,10 @@ def _describe_agent(agent: BaseAgent) -> dict[str, Any]:
1714
1885
  }
1715
1886
 
1716
1887
 
1888
+ def _describe_skills(agent: BaseAgent) -> list[dict[str, Any]]:
1889
+ return [skill.summary() for skill in getattr(agent.config, "skills", [])]
1890
+
1891
+
1717
1892
  def _subagent_tool_agent(tool: Any) -> BaseAgent | None:
1718
1893
  if tool.__class__.__name__ != "SubAgentTool":
1719
1894
  return None
@@ -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'}",
@@ -481,12 +529,16 @@ def _format_capabilities(app: PersistentAgent) -> str:
481
529
  caps = app.capabilities()
482
530
  coordinator = caps["coordinator"]
483
531
  lines = [f"Coordinator: {coordinator['agent_id']}"]
532
+ if coordinator.get("skills"):
533
+ lines.append(f" skills: {_format_skill_names(coordinator['skills'])}")
484
534
  for tool in coordinator.get("tools", []):
485
535
  sub = next((s for s in caps["subagents"] if s["tool_name"] == tool), None)
486
536
  if sub is None:
487
537
  lines.append(f" - {tool}")
488
538
  continue
489
539
  lines.append(f" - {tool} -> {sub['agent_id']}")
540
+ if sub.get("skills"):
541
+ lines.append(f" skills: {_format_skill_names(sub['skills'])}")
490
542
  for sub_tool in sub.get("tools", []):
491
543
  lines.append(f" - {sub_tool}")
492
544
  return "\n".join(lines)
@@ -496,11 +548,19 @@ def _format_agents(app: PersistentAgent) -> str:
496
548
  caps = app.capabilities()
497
549
  coordinator = caps["coordinator"]
498
550
  lines = [f"{coordinator['agent_id']}: {coordinator['role']}"]
551
+ if coordinator.get("skills"):
552
+ lines.append(f" skills: {_format_skill_names(coordinator['skills'])}")
499
553
  for sub in caps["subagents"]:
500
554
  lines.append(f"{sub['agent_id']}: {sub['role']} (via {sub['tool_name']})")
555
+ if sub.get("skills"):
556
+ lines.append(f" skills: {_format_skill_names(sub['skills'])}")
501
557
  return "\n".join(lines)
502
558
 
503
559
 
560
+ def _format_skill_names(skills: list[dict]) -> str:
561
+ return ", ".join(str(skill["name"]) for skill in skills)
562
+
563
+
504
564
  def _format_mcp(app: PersistentAgent) -> str:
505
565
  tools = app.capabilities()["mcp_tools"]
506
566
  if not tools:
@@ -523,6 +583,46 @@ def _format_mcp(app: PersistentAgent) -> str:
523
583
  return "\n".join(lines)
524
584
 
525
585
 
586
+ def _format_models(app: PersistentAgent) -> str:
587
+ models = app.available_models()
588
+ default = app.default_model()
589
+ if not models:
590
+ return "No model registry is configured for this PersistentAgent."
591
+ lines = ["available models:"]
592
+ for model in models:
593
+ suffix = " (default)" if default and model == default else ""
594
+ lines.append(f" - {model}{suffix}")
595
+ lines.append("switch with: /model <agent_id> <model>")
596
+ return "\n".join(lines)
597
+
598
+
599
+ async def _format_model_overrides(
600
+ app: PersistentAgent,
601
+ session_id: str,
602
+ *,
603
+ agent_id: str | None = None,
604
+ ) -> str:
605
+ caps = app.capabilities()
606
+ agents = [caps["coordinator"], *caps["subagents"]]
607
+ known_ids = {str(agent["agent_id"]) for agent in agents}
608
+ if agent_id is not None and agent_id not in known_ids:
609
+ return f"unknown agent: {agent_id}"
610
+ overrides = await app.model_overrides(session_id)
611
+ default = app.default_model() or "(construction default)"
612
+ selected = [agent for agent in agents if agent_id is None or agent["agent_id"] == agent_id]
613
+ lines = [f"session model overrides for {session_id}:"]
614
+ for agent in selected:
615
+ aid = str(agent["agent_id"])
616
+ model = overrides.get(aid)
617
+ suffix = f"{model} (override)" if model else default
618
+ lines.append(f" - {aid}: {suffix}")
619
+ if app.available_models():
620
+ lines.append("available: " + ", ".join(app.available_models()))
621
+ else:
622
+ lines.append("available: (no model registry configured)")
623
+ return "\n".join(lines)
624
+
625
+
526
626
  def _format_memory(app: PersistentAgent, *, session_id: str) -> str:
527
627
  context = app.cached_memory_context(session_id)
528
628
  if context is None: