@lmmslab/harness 0.85.0 → 0.86.0

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 (94) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/python/harness/__init__.py +2 -2
  4. package/python/harness/bench.py +2 -2
  5. package/python/harness/builtin/benches/README.md +1 -2
  6. package/python/harness/builtin/configs/default.toml +4 -19
  7. package/python/harness/builtin/configs/deploy/example-api.toml +1 -1
  8. package/python/harness/builtin/configs/models/deepseek-flash.toml +1 -1
  9. package/python/harness/builtin/configs/models/grok-low.toml +1 -1
  10. package/python/harness/builtin/configs/models/grok-medium.toml +3 -6
  11. package/python/harness/builtin/environment/README.md +8 -25
  12. package/python/harness/builtin/prompts/conversation/core.md +6 -5
  13. package/python/harness/builtin/prompts/core/core.md +147 -203
  14. package/python/harness/builtin/prompts/core/pack.toml +0 -1
  15. package/python/harness/builtin/prompts/reflect/core.md +8 -32
  16. package/python/harness/builtin/prompts/reflect/pack.toml +2 -4
  17. package/python/harness/builtin/prompts/shared/agent-skills.md +5 -3
  18. package/python/harness/builtin/prompts/shared/agents.md +20 -10
  19. package/python/harness/builtin/prompts/shared/checklist.md +13 -17
  20. package/python/harness/builtin/prompts/shared/environments.md +20 -15
  21. package/python/harness/builtin/prompts/shared/learning-goal.md +2 -3
  22. package/python/harness/builtin/prompts/shared/learning.md +73 -23
  23. package/python/harness/builtin/prompts/shared/mcp.md +11 -6
  24. package/python/harness/builtin/prompts/shared/reflex-method.md +243 -0
  25. package/python/harness/builtin/prompts/shared/units.md +138 -0
  26. package/python/harness/builtin/prompts/shared/web.md +5 -6
  27. package/python/harness/builtin/skills/agents/__init__.py +18 -3
  28. package/python/harness/builtin/skills/agents/skill.toml +3 -3
  29. package/python/harness/builtin/skills/checklist/__init__.py +34 -32
  30. package/python/harness/builtin/skills/checklist/skill.toml +9 -9
  31. package/python/harness/builtin/skills/environments/__init__.py +9 -5
  32. package/python/harness/builtin/skills/environments/skill.toml +1 -1
  33. package/python/harness/builtin/skills/experience/skill.toml +1 -1
  34. package/python/harness/builtin/skills/learning/__init__.py +19 -5
  35. package/python/harness/builtin/skills/mcp/skill.toml +1 -1
  36. package/python/harness/builtin/skills/memory/__init__.py +4 -1
  37. package/python/harness/builtin/skills/memory/skill.toml +0 -5
  38. package/python/harness/builtin/skills/verify/skill.toml +1 -0
  39. package/python/harness/builtin/skills/web/__init__.py +4 -1
  40. package/python/harness/builtin/third_party/sources.toml +2 -40
  41. package/python/harness/cli.py +16 -25
  42. package/python/harness/config/__init__.py +2 -2
  43. package/python/harness/config/agent.py +59 -47
  44. package/python/harness/core/__init__.py +1 -1
  45. package/python/harness/core/codec.py +4 -4
  46. package/python/harness/core/contracts.py +1 -1
  47. package/python/harness/core/media.py +1 -1
  48. package/python/harness/core/ports.py +2 -2
  49. package/python/harness/core/procs.py +1 -1
  50. package/python/harness/core/remote.py +1 -1
  51. package/python/harness/core/worker.py +19 -13
  52. package/python/harness/embodiments.py +53 -44
  53. package/python/harness/extensions.py +22 -0
  54. package/python/harness/host/__init__.py +1 -1
  55. package/python/harness/host/http.py +6 -12
  56. package/python/harness/host/sessions.py +1 -1
  57. package/python/harness/host/tasks.py +15 -11
  58. package/python/harness/host/workspaces.py +36 -8
  59. package/python/harness/packages/__init__.py +5 -5
  60. package/python/harness/packages/environments.py +30 -18
  61. package/python/harness/packages/manager.py +1 -1
  62. package/python/harness/packages/manifest.py +6 -6
  63. package/python/harness/packages/provision.py +1 -1
  64. package/python/harness/packages/sources.py +1 -1
  65. package/python/harness/paths.py +1 -1
  66. package/python/harness/runtime/decision/loop.py +95 -5
  67. package/python/harness/runtime/decision/messages.py +128 -2
  68. package/python/harness/runtime/decision/model.py +4 -5
  69. package/python/harness/runtime/decision/prompts.py +20 -32
  70. package/python/harness/runtime/events.py +7 -5
  71. package/python/harness/runtime/execution/attached.py +3 -3
  72. package/python/harness/runtime/execution/entries.py +189 -8
  73. package/python/harness/runtime/execution/kernel.py +26 -1
  74. package/python/harness/runtime/execution/results.py +2 -3
  75. package/python/harness/runtime/execution/session.py +417 -32
  76. package/python/harness/runtime/execution/skills.py +63 -16
  77. package/python/harness/runtime/learning/active.py +7 -7
  78. package/python/harness/runtime/learning/learner.py +3 -2
  79. package/python/harness/runtime/learning/library.py +9 -4
  80. package/python/harness/runtime/learning/reflect.py +10 -9
  81. package/python/harness/runtime/reactive/rules.py +4 -4
  82. package/python/harness/runtime/reactive/tree.py +506 -25
  83. package/python/harness/runtime/safety/input.py +1 -1
  84. package/python/harness/runtime/safety/isolation.py +3 -3
  85. package/python/harness/runtime/safety/shield.py +4 -50
  86. package/python/harness/runtime/task/delegation.py +5 -5
  87. package/python/harness/runtime/task/environments.py +10 -0
  88. package/python/harness/runtime/task/run.py +222 -27
  89. package/python/harness/runtime/tick.py +24 -1
  90. package/python/harness/sdk/__init__.py +2 -5
  91. package/python/harness/services/registry.py +23 -19
  92. package/python/harness/settings.py +9 -9
  93. package/python/harness/builtin/environment/constraints.txt +0 -31
  94. package/python/harness/builtin/prompts/shared/world.md +0 -1
@@ -36,8 +36,9 @@ from types import SimpleNamespace
36
36
  import uuid
37
37
 
38
38
  from harness.runtime.decision import loop as decisions
39
- from harness.runtime.decision.messages import _inbox_parts, content_parts
40
- from harness.runtime.decision.notices import LATER, NEXT, NOW, Notice, Notices
39
+ from harness.runtime.decision.messages import (_inbox_parts, content_parts, reflex_text, report_parts, taken_text,
40
+ without_pictures)
41
+ from harness.runtime.decision.notices import LATER, NEXT, NOW, PRIORITIES, Notice, Notices
41
42
  from harness.runtime.execution.results import _taken_over, _cell_usage, _wrap_up
42
43
  from harness.runtime.safety.approval import CONFIRMATION_POLICIES
43
44
  from harness.runtime.status import Closed, Interrupted
@@ -71,6 +72,16 @@ import harness.runtime.learning.views as library_view
71
72
 
72
73
  # What continues a conversation in another process, in its directory.
73
74
  CONVERSATION_FILE = "conversation.json"
75
+ # Everything the model was told and everything it replied, in order, one JSON line each
76
+ # ({"time", "role", "text", "images"}): compaction never rewrites it, and the summary that
77
+ # stands in for the earlier part of the conversation names it (decisions.COMPACTED), as
78
+ # Claude Code names its transcript.
79
+ RECORD_FILE = "record.jsonl"
80
+
81
+
82
+ def _guide_page(file) -> str:
83
+ """A page of instructions the model read on demand (Session.guide), from its file."""
84
+ return Path(file).read_text(encoding="utf-8")
74
85
 
75
86
 
76
87
  def saved(directory) -> dict | None:
@@ -154,6 +165,17 @@ class TaskRun:
154
165
  raise ValueError(f"runtime.tell_budget must be one of {decisions.TELL_BUDGET}, got {told!r}")
155
166
  # Whether the model is told what the run has left (its calls, its steps, its time).
156
167
  self._budget_told = told == "always"
168
+ purpose = config.runtime.get("purpose", "required")
169
+ if purpose not in decisions.PURPOSES:
170
+ raise ValueError(f"runtime.purpose must be one of {decisions.PURPOSES}, got {purpose!r}")
171
+ # Whether a program that does not say what it is for is started.
172
+ self._purpose_required = purpose == "required"
173
+ trials = config.runtime.get("reflex_method", "required")
174
+ if trials not in decisions.REFLEX_METHOD:
175
+ raise ValueError(f"runtime.reflex_method must be one of {decisions.REFLEX_METHOD}, got {trials!r}")
176
+ # The pages of instructions the model read (guide(name)), in the order it first read
177
+ # them: they are given again after a summary.
178
+ self._guides_read = {} # name -> the page's file
157
179
  longest = config.runtime.get("longest_wait_seconds", decisions.LONGEST_WAIT_SECONDS)
158
180
  if isinstance(longest, bool) or not isinstance(longest, (int, float)) or longest <= 0:
159
181
  raise ValueError(f"runtime.longest_wait_seconds must be a number of seconds > 0, got {longest!r}")
@@ -234,7 +256,7 @@ class TaskRun:
234
256
  self._units = {}
235
257
  self._programs = {}
236
258
  self._grace = float(grace)
237
- # The longest a <wait> of the model lasts.
259
+ # What a <wait> of the model without a time lasts.
238
260
  self._longest_wait = float(longest)
239
261
  # A unit ended the turn: "episode_ended", or ("finished", the summary its finish() gave).
240
262
  self._run_end = None
@@ -248,6 +270,17 @@ class TaskRun:
248
270
  self._cancelled_origins = set()
249
271
  self._logged = 0
250
272
  self._replaces = 0
273
+ # How much of the history the record file has: the messages written, and of the last
274
+ # of them, when it is one the model is told, how many parts.
275
+ self._recorded, self._recorded_last = 0, None
276
+ # When each kind of event (its kind and source) was told to the model in this run.
277
+ self._event_times = {}
278
+ # The model's plan as it last stood (the checklist skill's `plan` note), and the model
279
+ # call at which it last touched it or was last shown it.
280
+ self._plan_steps, self._plan_call = [], 0
281
+ # The values the state's situation (the profile's "situation") has had in this run, the
282
+ # last of them last.
283
+ self._situation_values = []
251
284
  # What the user said, in order: the instruction, then every message.
252
285
  self._said = []
253
286
  # The physical-input request waiting for the user's answer.
@@ -285,7 +318,7 @@ class TaskRun:
285
318
  self.workspace_kind = None
286
319
  place = EMBODIMENT_KINDS[config.embodiment].place if config.embodiment in EMBODIMENT_KINDS else ""
287
320
  if self.agents is None and parent is None and place and "agents" in (config.runtime.get("skills") or []):
288
- # Its kind gives the sub-agents a place (a game has one body: its sub-agents
321
+ # Its kind gives the sub-agents a place (a kind with one body: its sub-agents
289
322
  # only look, at a view of this episode, and never act).
290
323
  import importlib
291
324
 
@@ -729,6 +762,11 @@ class TaskRun:
729
762
  # The state as the kernel last had it (runtime/execution/session.py): told with every call.
730
763
  with self._condition:
731
764
  self._state_now = record.get("state")
765
+ # What the units that run say of themselves (until(report=)).
766
+ for identifier, says in (record.get("says") or {}).items():
767
+ if identifier in self._units:
768
+ self._units[identifier]["says"] = says
769
+ self._situation_seen(record.get("state"))
732
770
  elif note == "preempted":
733
771
  self._taken(record)
734
772
  elif note == "held_back":
@@ -748,6 +786,18 @@ class TaskRun:
748
786
  self._facts[record["name"]] = json.loads(data)
749
787
  self.trace.emit("fact", **record)
750
788
  elif note in EVENTS:
789
+ if note == "plan":
790
+ with self._condition:
791
+ self._plan_steps = [dict(step) for step in record.get("steps") or ()]
792
+ self._plan_call = self.summary["model_calls"] if self.summary is not None else 0
793
+ if note == "call_paused":
794
+ # A reflex took the environment from this unit, which goes on afterwards.
795
+ with self._condition:
796
+ unit = self._units.get(record.get("unit"))
797
+ if unit is not None:
798
+ by = str(record.get("rule") or record.get("by_name") or record.get("by"))
799
+ paused = unit.setdefault("paused_by", {})
800
+ paused[by] = paused.get(by, 0) + 1
751
801
  if note == "program_output":
752
802
  with self._condition:
753
803
  unit = self._units.get(record.get("unit"))
@@ -1157,7 +1207,7 @@ class TaskRun:
1157
1207
  return
1158
1208
  self._seen_events.add(identifier)
1159
1209
  self.trace.emit("escalation", **{key: value for key, value in record.items() if key != "event"},
1160
- reported=record["event"])
1210
+ reported={**record["event"], "detail": without_pictures(record["event"].get("detail"))})
1161
1211
  key = self._event_key(record)
1162
1212
  waiting = next((notice for notice in self._notices.pending(kinds=("event",))
1163
1213
  if self._event_key(notice.data) == key), None)
@@ -1167,6 +1217,12 @@ class TaskRun:
1167
1217
  return
1168
1218
  if priority == NOW and key in self._told_sources:
1169
1219
  priority = NEXT
1220
+ # What a node of the tree tells has the place in the queue the node gave it when it was
1221
+ # set (Reflex.tell, Reflex.tell_failed; an event a node tells carries it under "guard").
1222
+ detail = (record.get("event") or {}).get("detail") or {}
1223
+ said = detail.get("tell") or (detail.get("guard") or {}).get("tell")
1224
+ if said in PRIORITIES:
1225
+ priority = said
1170
1226
  self._put("event", priority, record, reason="unhandled escalation")
1171
1227
 
1172
1228
  def _held_back(self, record: dict) -> None:
@@ -1191,11 +1247,12 @@ class TaskRun:
1191
1247
  which unit and execution, whether that execution is started again, and the state."""
1192
1248
  record.pop("time", None)
1193
1249
  state = record.pop("state", None) or {}
1194
- self.trace.emit("preempted", **record)
1250
+ self.trace.emit("preempted", **without_pictures(record))
1195
1251
  if record.get("of_reflex"):
1196
1252
  # The call of a reflex's program: its node begins again by itself when its turn comes.
1197
1253
  return
1198
- told = {key: record[key] for key in ("rule", "by", "by_name", "unit", "name", "execution", "restart")
1254
+ told = {key: record[key] for key in ("rule", "by", "by_name", "unit", "name", "execution", "restart",
1255
+ "about", "says", "shows", "files", "done", "asked")
1199
1256
  if record.get(key) is not None}
1200
1257
  self._escalation({"id": uuid.uuid4().hex, "entry": record.get("unit"), "event": {
1201
1258
  "kind": "PREEMPTED", "source": record.get("rule") or record.get("by_name") or record.get("by"),
@@ -1423,13 +1480,17 @@ class TaskRun:
1423
1480
  return
1424
1481
 
1425
1482
  def _own_test_trial(self, learner, key, expected, cancelled):
1426
- """Verify one pending proposal by its own test, where the admission level is own_test:
1483
+ """Verify one pending proposal by its own test, where the admission level is own_test
1484
+ (a tree of reflexes: by the trials its nodes had when they were set, see below):
1427
1485
  the kernel stages the exact revision, the host runs its test on the staged revision
1428
1486
  as a cell of its own (Kernel.run_staged: bounded, counted as testing, the entry not
1429
1487
  yet in the programs' namespace) and reads the cell's result. The kernel never grades:
1430
1488
  a pass makes the host write the proof (method "own_test", this worker's profile, the
1431
1489
  receipt) and admit the revision as provisional, then commit it; anything else leaves
1432
- nothing loaded, and a test that ran and did not pass marks the proposal failed."""
1490
+ nothing loaded, and a test that ran and did not pass marks the proposal failed.
1491
+ A reactive entry has no test of its own and nothing of it is run: the kernel says
1492
+ whether the nodes it sets are the nodes in the tree and what their trials showed
1493
+ (Kernel.load_library "match"), and those trials are its receipt."""
1433
1494
  from harness.runtime.learning import fixtures
1434
1495
  from harness.runtime.learning.learner import OWN_TEST, OWN_TEST_SECONDS, STAGED_TEST
1435
1496
 
@@ -1442,9 +1503,10 @@ class TaskRun:
1442
1503
  entry = learner.candidate_from(key, pending=True)
1443
1504
  except (OSError, ValueError) as error:
1444
1505
  return pending(str(error))
1445
- if entry is None or not entry.test or entry.revision().revision != expected:
1506
+ tree = entry is not None and entry.kind == "reactive"
1507
+ if entry is None or not (entry.test or tree) or entry.revision().revision != expected:
1446
1508
  return
1447
- if entry.test.startswith(STAGED_TEST) and not sandbox_of(self.config.runtime):
1509
+ if entry.test and entry.test.startswith(STAGED_TEST) and not sandbox_of(self.config.runtime):
1448
1510
  return pending("its test stages a scene in the practice sandbox, and this run has none")
1449
1511
  item = entry.revision()
1450
1512
  budget = fixtures.Budget(self.seconds_left(), cancelled, limit=OWN_TEST_SECONDS + 60.0)
@@ -1455,6 +1517,15 @@ class TaskRun:
1455
1517
  limit = max(0.01, min(OWN_TEST_SECONDS, self.seconds_left()))
1456
1518
  self.trace.emit("library", action="trial_started", key=key, revision=expected, method=OWN_TEST)
1457
1519
  began = time.perf_counter()
1520
+ if tree:
1521
+ found = kernel.load_library("match")
1522
+ why = ("; ".join(found.get("problems") or ()) or None) if found["status"] == "ok" else str(found.get("error"))
1523
+ receipt = {"ok": why is None, "method": OWN_TEST, "run": str(self.directory), "episode_id": self.episode,
1524
+ "revision": expected, "seconds": round(time.perf_counter() - began, 3),
1525
+ "trials": found.get("trials") or {}, **({"error": why[-600:]} if why else {})}
1526
+ observed["receipt"] = receipt
1527
+ self.trace.emit("library", action="trial_observed", key=key, **receipt)
1528
+ return why
1458
1529
  try:
1459
1530
  with self._span("program", f"test of {key}") as end:
1460
1531
  # The test runs as a unit with `limit` as its time: the kernel ends it then.
@@ -1506,7 +1577,8 @@ class TaskRun:
1506
1577
  active = (self.config.runtime.get("library") or {}).get("trigger") == "active"
1507
1578
  if "admitted" in observed:
1508
1579
  if not active:
1509
- self._note(f"The host ran the test of your proposal {key} and it passed"
1580
+ self._note((f"Your proposal {key} is kept on the trials its nodes had in the tree" if tree else
1581
+ f"The host ran the test of your proposal {key} and it passed")
1510
1582
  + (": it is active from your next program." if outcome.get("status") == "activated"
1511
1583
  else "; it waits for validation before it is loaded."))
1512
1584
  return
@@ -1517,8 +1589,15 @@ class TaskRun:
1517
1589
  check=lambda: None)
1518
1590
  except (OSError, ValueError) as error:
1519
1591
  self.trace.emit("library", action="trial_pending", key=key, revision=expected, reason=str(error))
1520
- self._fixture_feedback[key] = f"Its own test failed when the host ran it: {receipt['error'][-300:]}"
1521
- if not active:
1592
+ self._fixture_feedback[key] = (f"Not kept: {receipt['error'][-300:]}" if tree else
1593
+ f"Its own test failed when the host ran it: {receipt['error'][-300:]}")
1594
+ if tree:
1595
+ # (The same lines are looked at again when they are proposed again.)
1596
+ self._fixture_attempts.discard(expected)
1597
+ if not active and tree:
1598
+ self._note(f"Your proposal {key} is not kept: {receipt['error'][-300:]}\n"
1599
+ "A tree is kept on the trials its nodes had when they were set: nothing of it is run again.")
1600
+ elif not active:
1522
1601
  self._note(f"The host ran the test of your proposal {key} and it failed: {receipt['error'][-300:]}\n"
1523
1602
  "It stays out of your library; rewrite it and propose it again if you still need it.")
1524
1603
  return
@@ -1913,10 +1992,67 @@ class TaskRun:
1913
1992
  finally:
1914
1993
  self.waiting_since = None
1915
1994
 
1995
+ def _situation_seen(self, state) -> None:
1996
+ """Tell the model when the part of the state the environment calls the agent's
1997
+ situation takes a value it has not had in this run (decisions.SITUATION_NEW): told
1998
+ with its next call, nothing is set aside for it."""
1999
+ key = (getattr(self, "profile", None) or {}).get("situation")
2000
+ if not key or not isinstance(state, dict) or state.get(key) is None:
2001
+ return
2002
+ now = state[key]
2003
+ with self._condition:
2004
+ seen = self._situation_values
2005
+ if now in seen:
2006
+ if seen[-1] != now:
2007
+ seen.remove(now)
2008
+ seen.append(now)
2009
+ return
2010
+ before = seen[-1] if seen else None
2011
+ seen.append(now)
2012
+ count = len(getattr(self, "_reflex_nodes", {}) or {})
2013
+ if before is None:
2014
+ return
2015
+ hint = str((getattr(self, "profile", None) or {}).get("situations_hint") or "").strip()
2016
+ self._note(decisions.SITUATION_NEW.format(
2017
+ key=key, now=json.dumps(now), before=json.dumps(before),
2018
+ nodes="no nodes" if not count else f"{count} node" + ("" if count == 1 else "s"),
2019
+ hint=" " + hint if hint else ""))
2020
+
1916
2021
  def _tell(self, content) -> None:
1917
2022
  """Add a user message to the history."""
1918
2023
  self.messages.append({"role": "user", "content": content})
1919
2024
 
2025
+ def _record(self) -> None:
2026
+ """Write to the record file (RECORD_FILE) what the history has that it has not: each
2027
+ message once, and what a message the model is told was given later (a notice that
2028
+ came while it was thinking) as a line of its own."""
2029
+ messages = self.messages
2030
+ start = min(self._recorded, len(messages))
2031
+ lines = []
2032
+
2033
+ def line(role, parts):
2034
+ text = "\n".join(part.get("text", "") for part in parts if part.get("type") in ("input_text", "text"))
2035
+ images = sum(part.get("type") == "input_image" for part in parts)
2036
+ if text or images:
2037
+ lines.append(json.dumps({"time": round(time.time(), 3), "role": role, "text": text,
2038
+ **({"images": images} if images else {})}, ensure_ascii=False))
2039
+
2040
+ if start and self._recorded_last is not None and self._recorded_last[0] == start - 1:
2041
+ parts = content_parts(messages[start - 1]["content"])
2042
+ line("user", parts[self._recorded_last[1]:])
2043
+ for message in messages[start:]:
2044
+ line(message["role"], content_parts(message["content"]))
2045
+ self._recorded = len(messages)
2046
+ last = messages[-1] if messages else None
2047
+ self._recorded_last = ((len(messages) - 1, len(content_parts(last["content"])))
2048
+ if last is not None and last["role"] == "user" else None)
2049
+ if lines:
2050
+ try:
2051
+ with open(self.directory / RECORD_FILE, "a", encoding="utf-8") as file:
2052
+ file.write("\n".join(lines) + "\n")
2053
+ except OSError:
2054
+ pass
2055
+
1920
2056
  def _came_to(self, content) -> None:
1921
2057
  """What the model's last output came to (its program's handle, the end of its wait,
1922
2058
  why nothing ran): the first thing its next call is told (_deliver)."""
@@ -2039,8 +2175,14 @@ class TaskRun:
2039
2175
  first["content"] = [
2040
2176
  *([{"type": "input_text", "text": content}] if isinstance(content, str)
2041
2177
  else [part for part in content if not part.get("summary")]),
2042
- {"type": "input_text", "text": decisions.COMPACTED.format(summary=text), "summary": True}]
2178
+ {"type": "input_text", "text": decisions.COMPACTED.format(
2179
+ summary=text, record=self.directory / RECORD_FILE), "summary": True},
2180
+ *[{"type": "input_text", "text": decisions.GUIDE_AGAIN.format(name=name, page=_guide_page(file)),
2181
+ "summary": True} for name, file in self._guides_read.items()]]
2182
+ self._record()
2043
2183
  messages[:] = [first, *tail]
2184
+ # (Everything that is left has been written: the summary itself is not a message.)
2185
+ self._recorded, self._recorded_last = len(messages), None
2044
2186
  # The next request's record replaces every message the trace has (rebuild_messages).
2045
2187
  self._replaces, self._logged = self._replaces + self._logged, 0
2046
2188
  self._context_tokens, self._compact_failures = 0, 0
@@ -2210,6 +2352,8 @@ class TaskRun:
2210
2352
  "reaction_delay_ms": float(runtime.get("reaction_delay_ms") or 0.0),
2211
2353
  "observer": dict(runtime.get("observer") or {}),
2212
2354
  "default_max_seconds": runtime.get("default_max_seconds", 30.0),
2355
+ "reflex_method": runtime.get("reflex_method", "required"),
2356
+ "purpose": runtime.get("purpose", "required"),
2213
2357
  "host_thoughts": True,
2214
2358
  # The model looks itself (look, watch) unless the configuration declares
2215
2359
  # a standing watch (runtime.cameras).
@@ -2228,14 +2372,14 @@ class TaskRun:
2228
2372
  "policy_progress_seconds": float(runtime.get("policy_progress_seconds") or 0.0),
2229
2373
  # Skills the user installed in the app, for read_skill (skills/instructions).
2230
2374
  **({"agent_skills": runtime["agent_skills"]} if runtime.get("agent_skills") else {}),
2231
- # A game the agent learns itself: none of its handwritten skills is loaded.
2375
+ # An environment the agent learns itself: none of its handwritten skills is loaded.
2232
2376
  **({"knowledge": runtime["knowledge"]} if runtime.get("knowledge") else {}),
2233
2377
  # The library and whether this run learns (skills/learning, runtime/learning/learner.py).
2234
2378
  **({"library": {"directory": str(library.directory), "settings": learning or {"learn": "off"}}}
2235
2379
  if library is not None else {}),
2236
2380
  # The practice sandbox: an active run's only (runtime/learning/active.py, the bench's [sandbox]).
2237
2381
  **({"sandbox": sandbox_of(runtime)} if sandbox_of(runtime) else {}),
2238
- # The worker's private files (a game's instance): never a program's.
2382
+ # The worker's private files: never a program's.
2239
2383
  **({"private_paths": self.profile["private_paths"]} if self.profile.get("private_paths") else {}),
2240
2384
  # What the environment gives to act with, where programs can read it (core/worker.py).
2241
2385
  **({"references": list(self.profile["references"])} if self.profile.get("references") else {}),
@@ -2351,6 +2495,7 @@ class TaskRun:
2351
2495
  # (How its last turn ended, until its next one ends.)
2352
2496
  summary["status"] = spent["status"]
2353
2497
  self._logged = len(self.messages)
2498
+ self._recorded, self._recorded_last = len(self.messages), None
2354
2499
  units = [str(unit) for unit in kept.get("units") or ()]
2355
2500
  self._say([{"type": "input_text", "text": decisions.CONTINUED.format(
2356
2501
  units=": " + "; ".join(units) if units else "") + "\n" + state}])
@@ -2562,7 +2707,7 @@ class TaskRun:
2562
2707
  if reply.usage.get("finish_reason") == "length":
2563
2708
  raise ProtocolError("The reply was truncated; nothing ran")
2564
2709
  parsed = parse_reply(reply.text, loop.kinds)
2565
- parsed.program = (loop.actions(parsed.body, allow_policy="vla" in loop.skills,
2710
+ parsed.program = (loop.actions(parsed.body, skills=frozenset(loop.skills),
2566
2711
  allow_skills=bool(self.config.runtime.get("fixed_skills", False)))
2567
2712
  if parsed.kind == "action" else parsed.body)
2568
2713
  presentation = {"kind": parsed.kind, "thought": (parsed.thought or "").strip(), "body": parsed.body}
@@ -2575,6 +2720,7 @@ class TaskRun:
2575
2720
  {"kind": "message" if plain else "invalid", "body": reply.text.strip() if plain else ""})
2576
2721
  self._record_reply(reply, loop.call + 1, thought=loop.thought, presentation=presentation)
2577
2722
  messages.append({"role": "assistant", "content": reply.text})
2723
+ self._record()
2578
2724
  if output == "invalid":
2579
2725
  if loop.malformed_from is None:
2580
2726
  loop.malformed_from = len(messages) - 1
@@ -2653,11 +2799,10 @@ class TaskRun:
2653
2799
  def _out_wait(self, reply, parsed, loop):
2654
2800
  """The model waits by choice: no call is made until a notice reaches it (the end of
2655
2801
  a unit it started, a message, an event, a note), or its time is over (the block's
2656
- seconds, at most the run's longest wait, which a wait without a time gets). It is
2657
- told which."""
2802
+ seconds: as long as it asks for; a wait without a time gets
2803
+ runtime.longest_wait_seconds). It is told which."""
2658
2804
  asked = wait_seconds(parsed.body)
2659
- limit = max(0.0, min(asked if asked is not None else self._longest_wait, self._longest_wait,
2660
- self.seconds_left()))
2805
+ limit = max(0.0, min(asked if asked is not None else self._longest_wait, self.seconds_left()))
2661
2806
  began = time.monotonic()
2662
2807
 
2663
2808
  def reached():
@@ -2819,6 +2964,11 @@ class TaskRun:
2819
2964
  the result then reaches the model when the unit ends (_unit_arrived)."""
2820
2965
  trace, summary, kernel = self.trace, self.summary, self.kernel
2821
2966
  program = parsed.program
2967
+ if self._purpose_required and not loop.direct and not decisions.says_purpose(program):
2968
+ trace.emit("program_refused", reason="no_purpose")
2969
+ self._came_to(decisions.NO_PURPOSE)
2970
+ self.reason = "rejected"
2971
+ return None
2822
2972
  if not self._approved(program):
2823
2973
  return None
2824
2974
  self._load_due_skills()
@@ -2878,7 +3028,8 @@ class TaskRun:
2878
3028
  number = result.get("cell")
2879
3029
  with self._condition:
2880
3030
  program = self._programs.pop(number, None) if number is not None else None
2881
- recorded = {key: value for key, value in result.items() if key not in ("attachments", "report", "looks")}
3031
+ recorded = {key: value for key, value in result.items()
3032
+ if key not in ("attachments", "report", "looks", "shows", "files", "pages")}
2882
3033
  if program is not None:
2883
3034
  if result.get("report"):
2884
3035
  recorded["report"] = {"text": result["report"].get("text", ""),
@@ -2927,8 +3078,27 @@ class TaskRun:
2927
3078
  more = {key: value for key, value in record.items() if key not in ("id", "event", "time")}
2928
3079
  if event.get("detail") not in (None, {}, ""):
2929
3080
  more["detail"] = event["detail"]
2930
- return [{"type": "input_text", "text": decisions.EVENT.format(
2931
- kind=event.get("kind"), source=event.get("source")) + (": " + json.dumps(more) if more else "")}]
3081
+ # The how-manieth of its kind in this run it is, and how long ago the earlier ones were.
3082
+ times = self._event_times.setdefault(self._event_key(record), [])
3083
+ now = time.time()
3084
+ count = len(times) + int(record.get("times") or 1)
3085
+ again = ""
3086
+ if times:
3087
+ earlier = ", ".join(f"{now - at:.0f} s" for at in times[-decisions.EARLIER_TOLD:])
3088
+ again = decisions.EVENT_AGAIN.format(count=decisions.ordinal(count), earlier=earlier)
3089
+ times.extend([now] * int(record.get("times") or 1))
3090
+ head = decisions.EVENT.format(kind=event.get("kind"), source=event.get("source")) + again
3091
+ detail = event.get("detail")
3092
+ if event.get("kind") in ("REFLEX_ACTED", "REFLEX_FAILED") and isinstance(detail, dict) and detail.get("reflex"):
3093
+ # A node of the tree: said in words, with what the node and the units it took the
3094
+ # environment from say of themselves.
3095
+ return [{"type": "input_text", "text": head + ":\n" + reflex_text(event["kind"], detail)},
3096
+ *report_parts(detail["reflex"], detail),
3097
+ *[part for row in detail.get("interrupted") or () for part in report_parts(row["name"], row)]]
3098
+ if event.get("kind") == "PREEMPTED" and isinstance(detail, dict) and detail.get("unit"):
3099
+ return [{"type": "input_text", "text": head + ":\n" + taken_text(detail)},
3100
+ *report_parts(str(detail.get("name") or detail["unit"]), detail)]
3101
+ return [{"type": "input_text", "text": head + (": " + json.dumps(more) if more else "")}]
2932
3102
  return [{"type": "input_text", "text": str(notice.data)}]
2933
3103
 
2934
3104
  def _deliver(self, loop) -> None:
@@ -2960,7 +3130,9 @@ class TaskRun:
2960
3130
  taken = taken or _taken_over(result)
2961
3131
  why = {"escalated": "escalation", "error": "error"}.get(status, "program_end")
2962
3132
  text = cell_feedback(result, program["number"])
2963
- if why == "program_end":
3133
+ with self._condition:
3134
+ others = any(unit.get("kind") == "program" for unit in self._units.values())
3135
+ if why == "program_end" and not others:
2964
3136
  text += decisions.PROGRAM_ENDED
2965
3137
  state = result.get("state") or state
2966
3138
  else:
@@ -2968,6 +3140,14 @@ class TaskRun:
2968
3140
  text = unit_feedback(result)
2969
3141
  reason = why if reason is None else max(reason, why, key=order.index)
2970
3142
  content.append({"type": "input_text", "text": text, "result": True})
3143
+ # The pages it asked for (guide(name)), whole: read from this message on.
3144
+ for page in result.get("pages") or ():
3145
+ content.append({"type": "input_text", "text": decisions.GUIDE_PAGE.format(
3146
+ name=page["name"], page=_guide_page(page["file"]))})
3147
+ with self._condition:
3148
+ self._guides_read.setdefault(page["name"], page["file"])
3149
+ # What the unit says of itself with pictures and files (its until(report=)).
3150
+ content.extend(report_parts((f"Program {program['number']}" if program else str(result.get("name") or "It")), result))
2971
3151
  for item in result.get("attachments", [])[:6]:
2972
3152
  content.append({"type": "input_text", "text": f"show(): {item['caption']}"})
2973
3153
  content.append({"type": "input_image", "image_url": item["image_url"], "detail": "auto"})
@@ -3038,6 +3218,7 @@ class TaskRun:
3038
3218
  with self._condition:
3039
3219
  calls_left = config.max_model_calls - self._iterations
3040
3220
  running = [unit_text(identifier, unit) for identifier, unit in self._units.items()]
3221
+ mine = [identifier for identifier, unit in self._units.items() if unit.get("kind") == "program"]
3041
3222
  tree = self._tree_told()
3042
3223
  state = self._state_now
3043
3224
  lines = []
@@ -3048,6 +3229,9 @@ class TaskRun:
3048
3229
  lines.append(steps_text(state, self.profile.get("control_hz")))
3049
3230
  if running:
3050
3231
  lines.append("Units running: " + latest(running))
3232
+ if mine:
3233
+ # The same words at every call while a program of the model runs.
3234
+ lines.append(decisions.WHILE_RUNNING.format(units=", ".join(mine), unit=mine[0]))
3051
3235
  if tree:
3052
3236
  lines.append(tree)
3053
3237
  # What was learned so far, where this run learns: whole when it changed, else its first line.
@@ -3055,6 +3239,16 @@ class TaskRun:
3055
3239
  if head:
3056
3240
  lines.append(head + ("\n" + body if body != self._learning_told else " as you were last told"))
3057
3241
  self._learning_told = body
3242
+ with self._condition:
3243
+ steps, calls = list(self._plan_steps), self.summary["model_calls"] - self._plan_call
3244
+ stale = bool(steps) and calls >= decisions.PLAN_STALE_CALLS and not all(step.get("done") for step in steps)
3245
+ if stale:
3246
+ self._plan_call = self.summary["model_calls"]
3247
+ if stale:
3248
+ on = next(index for index, step in enumerate(steps) if not step.get("done"))
3249
+ lines.append(decisions.PLAN_STALE.format(calls=calls, steps="\n".join(
3250
+ f" [{'x' if step.get('done') else ' '}] {index + 1}. {step.get('step')}"
3251
+ + (" (the one you are on)" if index == on else "") for index, step in enumerate(steps))))
3058
3252
  if self._budget_told:
3059
3253
  if self._post_from is not None and loop.post_calls:
3060
3254
  calls_left = min(calls_left, loop.post_calls - (self.summary["model_calls"] - self._post_from))
@@ -3098,6 +3292,7 @@ class TaskRun:
3098
3292
  library_version=getattr(self, "_library_version", None), revision=thought.revision,
3099
3293
  events=list(self._told_events), **self._replaced())
3100
3294
  self._logged = len(messages)
3295
+ self._record()
3101
3296
  summary["model_calls"] += 1
3102
3297
  summary["decisions"][trigger] = summary["decisions"].get(trigger, 0) + 1
3103
3298
  self._iterations += 1
@@ -3349,7 +3544,7 @@ class TaskRun:
3349
3544
  summary["status"] = "episode_ended"
3350
3545
  summary.pop("error", None)
3351
3546
  if outcome.get("unscorable") and summary["status"] != "interrupted":
3352
- # The environment dropped this episode (e.g. RoboDojo marked it unstable
3547
+ # The environment dropped this episode (e.g. it marked it unstable
3353
3548
  # mid-way): neither a success nor a failure of the policy.
3354
3549
  summary["status"] = "error"
3355
3550
  summary["error"] = f"Unscorable: {outcome['unscorable']}"
@@ -376,7 +376,15 @@ class Tick:
376
376
  self._holders.append(higher.owner)
377
377
  if lower.paused is not None:
378
378
  return
379
- if getattr(self.session, "pauses", False) and not (lower.restart and lower.make is not None):
379
+ # A node that says its program ends what it interrupts (set_reflex ends=True): the lower
380
+ # execution ends here, as where the environment does not pause, and the model is told.
381
+ layer, rule = getattr(self.session, "reactive", None), getattr(higher.owner, "rule", None)
382
+ node = layer.nodes.get(rule) if layer is not None and rule else None
383
+ # A program that says it ends when a reflex takes the environment from it
384
+ # (until(interrupted="stop")) ends here too.
385
+ ends = bool(getattr(node, "ends", False)) or getattr(lower.owner, "interrupted", None) == "stop"
386
+ if (getattr(self.session, "pauses", False) and not ends
387
+ and not (lower.restart and lower.make is not None)):
380
388
  self._pause(lower, higher)
381
389
  return
382
390
  try:
@@ -397,7 +405,13 @@ class Tick:
397
405
  lower.trace = trace
398
406
  self._end(lower)
399
407
  return
408
+ entries = getattr(self.session, "_entries", None)
409
+ told = {} if entries is None or lower.owner is None else {
410
+ "about": getattr(node, "about", "") or None, **entries.reports(lower.owner),
411
+ "done": entries._completed(lower.owner),
412
+ "asked": getattr(lower.owner, "interrupted", None) == "stop" or None}
400
413
  spans.note("preempted", unit=getattr(lower.owner, "id", None), name=getattr(lower.owner, "name", None),
414
+ **{key: value for key, value in told.items() if value is not None},
401
415
  execution=getattr(trace, "skill", None), by=by, by_name=getattr(higher.owner, "name", None),
402
416
  rule=getattr(higher.owner, "rule", None), priority=getattr(higher.owner, "priority", 0) or 0,
403
417
  restart=bool(lower.restart and lower.make is not None), state=dict(self.session.state or {}),
@@ -424,6 +438,12 @@ class Tick:
424
438
  except BaseException as error:
425
439
  self._fail(lower, error)
426
440
  return
441
+ if lower.owner is not None and hasattr(lower.owner, "pauses"):
442
+ # What the unit and the one that took the environment from it are told of later
443
+ # (runtime/reactive/tree.py interrupted_by).
444
+ lower.owner.pauses.append({"by": taker, "at": time.monotonic()})
445
+ if higher.owner is not None and hasattr(higher.owner, "took"):
446
+ higher.owner.took.append(lower.owner)
427
447
  spans.note("call_paused", unit=getattr(lower.owner, "id", None), name=getattr(lower.owner, "name", None),
428
448
  by=getattr(higher.owner, "id", None), by_name=getattr(higher.owner, "name", None),
429
449
  rule=getattr(higher.owner, "rule", None), priority=getattr(higher.owner, "priority", 0) or 0)
@@ -431,6 +451,9 @@ class Tick:
431
451
  def _resume(self, entry):
432
452
  """The unit that took the embodiment has ended: the paused execution goes on."""
433
453
  held, entry.paused = entry.paused["held"], None
454
+ pauses = getattr(entry.owner, "pauses", None)
455
+ if pauses and "until" not in pauses[-1]:
456
+ pauses[-1]["until"] = time.monotonic()
434
457
  try:
435
458
  self.session._resume_execution(held)
436
459
  except BaseException as error:
@@ -10,7 +10,7 @@ version. Its names, by what they are for:
10
10
  ProgramFinished, record_kind, ReactiveFault, call_reactive,
11
11
  json_list (the JSON list in a model's reply),
12
12
  Learner, candidate, entry_key, Library, SECTIONS, WorkingMemory, MemoryKind, memory_entries,
13
- keep_probe, BUILTIN_ACTIONS, OPEN_GRIPPER, STOP, HOLD, BACK_OFF, Refused
13
+ keep_probe, BUILTIN_ACTIONS, STOP, HOLD, Refused
14
14
  Sessions EpisodeCore, create_session, session_class (an embodiment kind's kernel
15
15
  session builds on the episode core), PhysicalInput, REMEMBER,
16
16
  Admission (the host side of a managed kernel: its proposals admitted as units)
@@ -25,7 +25,7 @@ version. Its names, by what they are for:
25
25
  (its hooks: the eval package's, imported only there); load_deploy,
26
26
  load_embodiment, TaskConfig, scripted_models, apply_sets, load_layered,
27
27
  DEFAULT_AGENT, resolve_agent, repo_modules, bench_environment, environments,
28
- read_toml, parse_set, service_names, embodiment_profile
28
+ read_toml, parse_set, service_names
29
29
  Services ensure, McpClient, McpError, McpSession, McpSessionGone, MCP_PROTOCOL_VERSION (an MCP
30
30
  session over another transport), load_services, SERVICES_ROOT, ServiceSpec
31
31
  Paths ROOT, CHECKOUT_ROOT, home, active_packages, import_roots, python_path, third_party, find,
@@ -95,10 +95,8 @@ _NAMES = {
95
95
  "MemoryKind": "harness.runtime.task.context:Kind",
96
96
  "SECTIONS": "harness.runtime.learning.library:SECTIONS",
97
97
  "BUILTIN_ACTIONS": "harness.runtime.reactive.rules:BUILTIN_ACTIONS",
98
- "OPEN_GRIPPER": "harness.runtime.reactive.rules:OPEN_GRIPPER",
99
98
  "STOP": "harness.runtime.reactive.rules:STOP",
100
99
  "HOLD": "harness.runtime.reactive.rules:HOLD",
101
- "BACK_OFF": "harness.runtime.reactive.rules:BACK_OFF",
102
100
  "Refused": "harness.runtime.tick:Refused",
103
101
  "keep_probe": "harness.runtime.learning.active:keep",
104
102
  # Sessions: what an embodiment kind's kernel session builds on.
@@ -165,7 +163,6 @@ _NAMES = {
165
163
  "toml_dumps": "harness.config:dumps",
166
164
  "parse_set": "harness.config:parse_set",
167
165
  "service_names": "harness.config.agent:_service_names",
168
- "embodiment_profile": "harness.embodiments:profile",
169
166
  "bench_environment": "harness.packages.provision:bench_environment",
170
167
  "environments": "harness.packages.environments",
171
168
  # Services.