@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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/python/harness/__init__.py +2 -2
- package/python/harness/bench.py +2 -2
- package/python/harness/builtin/benches/README.md +1 -2
- package/python/harness/builtin/configs/default.toml +4 -19
- package/python/harness/builtin/configs/deploy/example-api.toml +1 -1
- package/python/harness/builtin/configs/models/deepseek-flash.toml +1 -1
- package/python/harness/builtin/configs/models/grok-low.toml +1 -1
- package/python/harness/builtin/configs/models/grok-medium.toml +3 -6
- package/python/harness/builtin/environment/README.md +8 -25
- package/python/harness/builtin/prompts/conversation/core.md +6 -5
- package/python/harness/builtin/prompts/core/core.md +147 -203
- package/python/harness/builtin/prompts/core/pack.toml +0 -1
- package/python/harness/builtin/prompts/reflect/core.md +8 -32
- package/python/harness/builtin/prompts/reflect/pack.toml +2 -4
- package/python/harness/builtin/prompts/shared/agent-skills.md +5 -3
- package/python/harness/builtin/prompts/shared/agents.md +20 -10
- package/python/harness/builtin/prompts/shared/checklist.md +13 -17
- package/python/harness/builtin/prompts/shared/environments.md +20 -15
- package/python/harness/builtin/prompts/shared/learning-goal.md +2 -3
- package/python/harness/builtin/prompts/shared/learning.md +73 -23
- package/python/harness/builtin/prompts/shared/mcp.md +11 -6
- package/python/harness/builtin/prompts/shared/reflex-method.md +243 -0
- package/python/harness/builtin/prompts/shared/units.md +138 -0
- package/python/harness/builtin/prompts/shared/web.md +5 -6
- package/python/harness/builtin/skills/agents/__init__.py +18 -3
- package/python/harness/builtin/skills/agents/skill.toml +3 -3
- package/python/harness/builtin/skills/checklist/__init__.py +34 -32
- package/python/harness/builtin/skills/checklist/skill.toml +9 -9
- package/python/harness/builtin/skills/environments/__init__.py +9 -5
- package/python/harness/builtin/skills/environments/skill.toml +1 -1
- package/python/harness/builtin/skills/experience/skill.toml +1 -1
- package/python/harness/builtin/skills/learning/__init__.py +19 -5
- package/python/harness/builtin/skills/mcp/skill.toml +1 -1
- package/python/harness/builtin/skills/memory/__init__.py +4 -1
- package/python/harness/builtin/skills/memory/skill.toml +0 -5
- package/python/harness/builtin/skills/verify/skill.toml +1 -0
- package/python/harness/builtin/skills/web/__init__.py +4 -1
- package/python/harness/builtin/third_party/sources.toml +2 -40
- package/python/harness/cli.py +16 -25
- package/python/harness/config/__init__.py +2 -2
- package/python/harness/config/agent.py +59 -47
- package/python/harness/core/__init__.py +1 -1
- package/python/harness/core/codec.py +4 -4
- package/python/harness/core/contracts.py +1 -1
- package/python/harness/core/media.py +1 -1
- package/python/harness/core/ports.py +2 -2
- package/python/harness/core/procs.py +1 -1
- package/python/harness/core/remote.py +1 -1
- package/python/harness/core/worker.py +19 -13
- package/python/harness/embodiments.py +53 -44
- package/python/harness/extensions.py +22 -0
- package/python/harness/host/__init__.py +1 -1
- package/python/harness/host/http.py +6 -12
- package/python/harness/host/sessions.py +1 -1
- package/python/harness/host/tasks.py +15 -11
- package/python/harness/host/workspaces.py +36 -8
- package/python/harness/packages/__init__.py +5 -5
- package/python/harness/packages/environments.py +30 -18
- package/python/harness/packages/manager.py +1 -1
- package/python/harness/packages/manifest.py +6 -6
- package/python/harness/packages/provision.py +1 -1
- package/python/harness/packages/sources.py +1 -1
- package/python/harness/paths.py +1 -1
- package/python/harness/runtime/decision/loop.py +95 -5
- package/python/harness/runtime/decision/messages.py +128 -2
- package/python/harness/runtime/decision/model.py +4 -5
- package/python/harness/runtime/decision/prompts.py +20 -32
- package/python/harness/runtime/events.py +7 -5
- package/python/harness/runtime/execution/attached.py +3 -3
- package/python/harness/runtime/execution/entries.py +189 -8
- package/python/harness/runtime/execution/kernel.py +26 -1
- package/python/harness/runtime/execution/results.py +2 -3
- package/python/harness/runtime/execution/session.py +417 -32
- package/python/harness/runtime/execution/skills.py +63 -16
- package/python/harness/runtime/learning/active.py +7 -7
- package/python/harness/runtime/learning/learner.py +3 -2
- package/python/harness/runtime/learning/library.py +9 -4
- package/python/harness/runtime/learning/reflect.py +10 -9
- package/python/harness/runtime/reactive/rules.py +4 -4
- package/python/harness/runtime/reactive/tree.py +506 -25
- package/python/harness/runtime/safety/input.py +1 -1
- package/python/harness/runtime/safety/isolation.py +3 -3
- package/python/harness/runtime/safety/shield.py +4 -50
- package/python/harness/runtime/task/delegation.py +5 -5
- package/python/harness/runtime/task/environments.py +10 -0
- package/python/harness/runtime/task/run.py +222 -27
- package/python/harness/runtime/tick.py +24 -1
- package/python/harness/sdk/__init__.py +2 -5
- package/python/harness/services/registry.py +23 -19
- package/python/harness/settings.py +9 -9
- package/python/harness/builtin/environment/constraints.txt +0 -31
- package/python/harness/builtin/prompts/shared/world.md +0 -1
|
@@ -7,7 +7,7 @@ A skill is a package `skills/<name>/` in the source checkout with
|
|
|
7
7
|
turn_report(session): what the skill adds to the model's next turn
|
|
8
8
|
after every program)
|
|
9
9
|
|
|
10
|
-
A skill runs on the embodiment kinds its `embodiments` names (
|
|
10
|
+
A skill runs on the embodiment kinds its `embodiments` names ("*" for every kind). The
|
|
11
11
|
kernel's session class is the embodiment's session (runtime/execution/session.py) plus the mixin of
|
|
12
12
|
every skill for that embodiment, so skills can call each other's methods. Which skills a
|
|
13
13
|
program sees is decided per run: the system names them (or the interface layers do), and
|
|
@@ -40,8 +40,8 @@ LAYERS = ("learned", "reactive", "handlers")
|
|
|
40
40
|
LAYER_DEFAULTS = {"learned": False, "reactive": True, "handlers": True}
|
|
41
41
|
# Service kinds a skill can need (services/<name>/service.toml `kind`).
|
|
42
42
|
SERVICE_KINDS = ("segmenter", "vision", "pointer", "vlm", "verifier", "policy", "world_model", "mcp")
|
|
43
|
-
# What
|
|
44
|
-
# the agent learned itself (runtime/learning/learner.py), no skill written for
|
|
43
|
+
# What the agent knows of an environment whose kind declares `knowledge`: "learned", only what
|
|
44
|
+
# the agent learned itself (runtime/learning/learner.py), no skill written for it by hand
|
|
45
45
|
# loaded; "handwritten", those skills (a reference baseline's) may load.
|
|
46
46
|
KNOWLEDGE = ("learned", "handwritten")
|
|
47
47
|
# The keys of skills/<name>/skill.toml.
|
|
@@ -51,7 +51,8 @@ SKILL_KEYS = {
|
|
|
51
51
|
"layer": "base, or the interface layer that turns it on: learned, reactive or handlers",
|
|
52
52
|
"mixin": "the class with its methods, as \"module:Class\" (e.g. \"skills.motion:Motion\")",
|
|
53
53
|
"exports": "the names programs see: the mixin's methods, or names its exports(session) returns",
|
|
54
|
-
"interface": "per-embodiment overrides for summary, mixin and exports"
|
|
54
|
+
"interface": "per-embodiment overrides for summary, mixin and exports (a kind's package can declare its own "
|
|
55
|
+
"in kinds.toml: interfaces)",
|
|
55
56
|
"required": "never dropped: the session cannot run without it (core)",
|
|
56
57
|
"needs": "service kinds that must all be available",
|
|
57
58
|
"needs_any": "service kinds of which at least one must be available",
|
|
@@ -59,15 +60,20 @@ SKILL_KEYS = {
|
|
|
59
60
|
"conflicts": "skills it cannot be enabled with: they export some of the same names",
|
|
60
61
|
"optional": "not among the skills of its layer: only a configuration that enables it by name has it",
|
|
61
62
|
"order": "position in the session's method resolution and in the prompt (lower first)",
|
|
62
|
-
"embodiments": f"the embodiment kinds it runs on, among {', '.join(KINDS)} or [\"*\"] for all installed kinds
|
|
63
|
+
"embodiments": f"the embodiment kinds it runs on, among {', '.join(KINDS)} or [\"*\"] for all installed kinds",
|
|
63
64
|
"requirements": "a skill a user installs: pip requirements, installed into its own .deps folder",
|
|
64
|
-
"knowledge": "\"handwritten\":
|
|
65
|
-
"agent learns the
|
|
65
|
+
"knowledge": "\"handwritten\": knowledge of an environment written by hand, left out (not even imported) when "
|
|
66
|
+
"the agent learns the environment itself (its kind's knowledge = \"learned\")",
|
|
67
|
+
"guides": "pages of instructions a program reads on demand with guide(name): a table by page name, each "
|
|
68
|
+
"{file (a path from the skill's folder), before (optional: the skill's exports that are refused "
|
|
69
|
+
"until the page was read)}",
|
|
66
70
|
"probe": "a table: the skill is its body's probe, which a run that learns its environment turns on "
|
|
67
71
|
"(runtime/learning/active.py); it exports probe and probe_summary, and its keys say that run's lines for this "
|
|
68
72
|
"body: try (what probe() measures), skills (the basic skills to write) and drills (how a drill's "
|
|
69
73
|
"result is checked)",
|
|
70
74
|
}
|
|
75
|
+
# The pages of the core (runtime/execution/session.py GUIDES): a skill's page takes another name.
|
|
76
|
+
CORE_GUIDES = ("tree", "units")
|
|
71
77
|
# The names a body's probe exports, and the keys of its [probe] table (all but try optional).
|
|
72
78
|
PROBE_EXPORTS = ("probe", "probe_summary")
|
|
73
79
|
PROBE_KEYS = ("try", "skills", "drills")
|
|
@@ -95,16 +101,25 @@ class Skill:
|
|
|
95
101
|
optional: bool = False
|
|
96
102
|
order: int = 100
|
|
97
103
|
# The embodiment kinds it runs on (embodiments.KINDS).
|
|
98
|
-
embodiments: tuple[str, ...] = (
|
|
99
|
-
# "handwritten":
|
|
104
|
+
embodiments: tuple[str, ...] = ()
|
|
105
|
+
# "handwritten": knowledge of an environment written by hand (KNOWLEDGE); "" otherwise.
|
|
100
106
|
knowledge: str = ""
|
|
101
107
|
# The body's probe: its [probe] table as (key, text) pairs; empty for any other skill.
|
|
102
108
|
probe: tuple[tuple[str, str], ...] = ()
|
|
109
|
+
# Its pages of instructions, read on demand (guide(name)): (name, file, the exports that
|
|
110
|
+
# wait for the page) for each.
|
|
111
|
+
guides: tuple[tuple[str, str, tuple[str, ...]], ...] = ()
|
|
103
112
|
path: Path = field(default=None, compare=False)
|
|
104
113
|
interface: dict = field(default_factory=dict, compare=False, hash=False)
|
|
105
114
|
|
|
106
115
|
def for_embodiment(self, embodiment: str | None) -> "Skill":
|
|
107
|
-
|
|
116
|
+
"""The skill as an embodiment kind has it: the variant the kind declares for it
|
|
117
|
+
(Kind.interfaces), else the skill's own for that kind (`interface`), else the skill."""
|
|
118
|
+
kind = KINDS.get(embodiment)
|
|
119
|
+
declared = dict(kind.interfaces.get(self.name, {})) if kind is not None else {}
|
|
120
|
+
if "exports" in declared:
|
|
121
|
+
declared["exports"] = tuple(declared["exports"])
|
|
122
|
+
given = declared or self.interface.get(embodiment)
|
|
108
123
|
return replace(self, **given) if given else self
|
|
109
124
|
|
|
110
125
|
@property
|
|
@@ -129,12 +144,14 @@ def _skill(path: Path) -> Skill:
|
|
|
129
144
|
bad = set(data.get(key, ())) - set(SERVICE_KINDS)
|
|
130
145
|
if bad:
|
|
131
146
|
raise ValueError(f"{path}: {key} names unknown service kinds {sorted(bad)}")
|
|
132
|
-
|
|
147
|
+
if "embodiments" not in data:
|
|
148
|
+
raise ValueError(f"{path}: needs `embodiments`: the embodiment kinds the skill runs on, or [\"*\"] for every kind")
|
|
149
|
+
embodiments = tuple(data["embodiments"])
|
|
133
150
|
universal = embodiments == ("*",)
|
|
134
151
|
if universal:
|
|
135
152
|
embodiments = tuple(KINDS)
|
|
136
153
|
# Kinds by name: a kind a package registers may not be installed here (a built-in skill
|
|
137
|
-
#
|
|
154
|
+
# without that kind's package), and the skill is then for the kinds there are.
|
|
138
155
|
if not embodiments or not all(isinstance(kind, str) and kind.isidentifier() for kind in embodiments):
|
|
139
156
|
raise ValueError(f"{path}: embodiments names embodiment kinds (such as {', '.join(sorted(KINDS))})")
|
|
140
157
|
if data.get("knowledge", "") not in ("", "handwritten"):
|
|
@@ -159,6 +176,21 @@ def _skill(path: Path) -> Skill:
|
|
|
159
176
|
missing = set(PROBE_EXPORTS) - set(data["exports"])
|
|
160
177
|
if missing:
|
|
161
178
|
raise ValueError(f"{path}: a body's probe exports {list(PROBE_EXPORTS)}; {sorted(missing)} missing")
|
|
179
|
+
guides = data.get("guides", {})
|
|
180
|
+
if not isinstance(guides, dict):
|
|
181
|
+
raise ValueError(f"{path}: guides is a table of pages by name")
|
|
182
|
+
for name, page in guides.items():
|
|
183
|
+
if (not isinstance(page, dict) or set(page) - {"file", "before"} or not isinstance(page.get("file"), str)
|
|
184
|
+
or not isinstance(page.get("before", []), list)):
|
|
185
|
+
raise ValueError(f"{path}: guide {name!r} is {{file, before}}: a path from the skill's folder and, "
|
|
186
|
+
"optionally, the exports that wait for the page")
|
|
187
|
+
if name in CORE_GUIDES:
|
|
188
|
+
raise ValueError(f"{path}: guide {name!r} is a page of the core")
|
|
189
|
+
if not (path.parent / page["file"]).is_file():
|
|
190
|
+
raise ValueError(f"{path}: guide {name!r}: no file {page['file']}")
|
|
191
|
+
missing = [export for export in page.get("before", []) if export not in data["exports"]]
|
|
192
|
+
if missing:
|
|
193
|
+
raise ValueError(f"{path}: guide {name!r}: before names {missing}, which the skill does not export")
|
|
162
194
|
return Skill(name=data["name"], summary=data.get("summary", ""), layer=layer, mixin=data["mixin"],
|
|
163
195
|
exports=tuple(data["exports"]), required=bool(data.get("required", False)),
|
|
164
196
|
needs=tuple(data.get("needs", ())), needs_any=tuple(data.get("needs_any", ())),
|
|
@@ -166,6 +198,7 @@ def _skill(path: Path) -> Skill:
|
|
|
166
198
|
optional=bool(data.get("optional", False)), order=int(data.get("order", 100)),
|
|
167
199
|
embodiments=embodiments, knowledge=data.get("knowledge", ""),
|
|
168
200
|
probe=tuple((key, probe[key].strip()) for key in PROBE_KEYS if key in probe) if probe else (),
|
|
201
|
+
guides=tuple((name, page["file"], tuple(page.get("before", []))) for name, page in guides.items()),
|
|
169
202
|
path=path.parent, interface=interface)
|
|
170
203
|
|
|
171
204
|
|
|
@@ -250,7 +283,7 @@ def _load_root(root: Path) -> dict[str, Skill]:
|
|
|
250
283
|
return dict(sorted(by_name.items(), key=lambda pair: (pair[1].order, pair[0])))
|
|
251
284
|
|
|
252
285
|
|
|
253
|
-
def skills_for_layers(layers: dict | None, root: Path = SKILLS_ROOT, *, embodiment: str = "
|
|
286
|
+
def skills_for_layers(layers: dict | None, root: Path = SKILLS_ROOT, *, embodiment: str = "none") -> list[str]:
|
|
254
287
|
"""The skills of the interface layers given as switches ({"learned": bool, ...} over
|
|
255
288
|
LAYER_DEFAULTS) for an embodiment kind, without the optional ones."""
|
|
256
289
|
layers = {**LAYER_DEFAULTS, **(layers or {})}
|
|
@@ -294,7 +327,7 @@ class Resolution:
|
|
|
294
327
|
|
|
295
328
|
|
|
296
329
|
def resolve(requested, services: set[str], *, strict: bool = False, root: Path = SKILLS_ROOT,
|
|
297
|
-
embodiment: str = "
|
|
330
|
+
embodiment: str = "none") -> Resolution:
|
|
298
331
|
"""The requested skills that can run on this embodiment kind with these services. A
|
|
299
332
|
skill is dropped when it does not run on the embodiment, a service it needs is missing
|
|
300
333
|
or a skill it requires is not enabled (repeated until nothing changes); the
|
|
@@ -372,7 +405,7 @@ def _unavailable(skill: str, export: str, why: str):
|
|
|
372
405
|
return call
|
|
373
406
|
|
|
374
407
|
|
|
375
|
-
def mixins(root: Path = SKILLS_ROOT, *, embodiment: str = "
|
|
408
|
+
def mixins(root: Path = SKILLS_ROOT, *, embodiment: str = "none", knowledge: str = "handwritten") -> list[type]:
|
|
376
409
|
"""The mixin class of every skill for an embodiment kind, imported, in the skills'
|
|
377
410
|
order (the session's method resolution order); with knowledge "learned", none of the
|
|
378
411
|
handwritten ones (their modules are not imported). A skill whose module cannot be
|
|
@@ -385,7 +418,7 @@ def mixins(root: Path = SKILLS_ROOT, *, embodiment: str = "robot", knowledge: st
|
|
|
385
418
|
|
|
386
419
|
|
|
387
420
|
def handwritten(root: Path = SKILLS_ROOT) -> list[str]:
|
|
388
|
-
"""The skills that are
|
|
421
|
+
"""The skills that are knowledge of an environment written by hand."""
|
|
389
422
|
return [name for name, skill in load_skills(root).items() if skill.knowledge == "handwritten"]
|
|
390
423
|
|
|
391
424
|
|
|
@@ -411,6 +444,20 @@ def namespace(session, names, root: Path = SKILLS_ROOT) -> dict:
|
|
|
411
444
|
return result
|
|
412
445
|
|
|
413
446
|
|
|
447
|
+
def guides(names, root: Path = SKILLS_ROOT) -> dict:
|
|
448
|
+
"""The pages of instructions the skills `names` bring: {page: (its file, the exports that
|
|
449
|
+
are refused until it was read)}. Two skills that name the same page is an error."""
|
|
450
|
+
known = load_skills(root)
|
|
451
|
+
pages = {}
|
|
452
|
+
for name in names:
|
|
453
|
+
skill = known[name]
|
|
454
|
+
for page, file, before in skill.guides:
|
|
455
|
+
if page in pages:
|
|
456
|
+
raise ValueError(f"Skill {name}: guide {page!r} is another enabled skill's page")
|
|
457
|
+
pages[page] = (skill.path / file, before)
|
|
458
|
+
return pages
|
|
459
|
+
|
|
460
|
+
|
|
414
461
|
def reporters(names, root: Path = SKILLS_ROOT) -> list:
|
|
415
462
|
"""The turn reports of the skills `names`, in skill order: each skill module's
|
|
416
463
|
turn_report(session) -> {"text", "images"} or None, which the session calls after
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""The active trigger of learning (runtime/learning/learner.py): a run whose goal is to get to know the
|
|
2
2
|
environment for a task, before the runs that do the task. It is an ordinary run of the
|
|
3
|
-
task's environment with `trigger = "active"`: its instruction says that it is practice
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
task's environment with `trigger = "active"`: its instruction says that it is practice
|
|
4
|
+
(prompts/shared/learning-goal.md of the core; the task's own instruction stays in it as
|
|
5
|
+
what to learn for). How to learn and what counts as learned are not said there: they are on
|
|
6
|
+
the library's page (prompts/shared/learning.md), in every run. It is bounded by live time, not by the task's
|
|
7
7
|
budget. What it learns goes into the same library, through
|
|
8
8
|
the same learner, as what the task runs learn passively.
|
|
9
9
|
|
|
@@ -24,8 +24,8 @@ embodiment's package with a [probe] table (runtime/execution/skills.py), which a
|
|
|
24
24
|
probe_summary(table) -> text the table's lines
|
|
25
25
|
|
|
26
26
|
and its table's `try` text (what probe() measures) is the body's line of the learning goal.
|
|
27
|
-
A
|
|
28
|
-
|
|
27
|
+
A body's package says what its probe measures (its inputs, from what the body shows). A body
|
|
28
|
+
without a probe
|
|
29
29
|
has no such line. A probe is bounded by its live time: Deadline(max_seconds).check()
|
|
30
30
|
raises OutOfTime once it is over, and the probe stops with what it measured.
|
|
31
31
|
|
|
@@ -43,7 +43,7 @@ DEFAULT_MINUTES = 30.0
|
|
|
43
43
|
# this suffix (bench.py Bench.active_task). A worker allows its sandbox only in such an
|
|
44
44
|
# episode, never in a task run.
|
|
45
45
|
LEARN = "-learn"
|
|
46
|
-
# The lines of a body without a probe
|
|
46
|
+
# The lines of a body without a probe: none.
|
|
47
47
|
GENERIC = {"try": ""}
|
|
48
48
|
|
|
49
49
|
|
|
@@ -426,7 +426,7 @@ class Learner:
|
|
|
426
426
|
"sha256": hashlib.sha256(candidate.text.encode("utf-8")).hexdigest()}
|
|
427
427
|
if admitted:
|
|
428
428
|
# The library's log of what entered it (the audit's evidence that an entry
|
|
429
|
-
# was admitted
|
|
429
|
+
# was admitted): section, file, its bytes' sha256.
|
|
430
430
|
with (self.directory / ADMISSIONS).open("a", encoding="utf-8") as log:
|
|
431
431
|
log.write(json.dumps({**self.record_of(outcome), "source": candidate.source,
|
|
432
432
|
"origin": candidate.origin, "at": _now()}) + "\n")
|
|
@@ -690,7 +690,8 @@ class Learner:
|
|
|
690
690
|
summary=request.get("summary", ""), attachments=files, source=source, origin="model",
|
|
691
691
|
run=run)
|
|
692
692
|
if executable(entry.key):
|
|
693
|
-
if not entry.test:
|
|
693
|
+
if not entry.test and entry.kind != "reactive":
|
|
694
|
+
# (A reactive entry is kept on the trials its nodes had in the tree.)
|
|
694
695
|
raise ValueError("an executable proposal needs a verification condition")
|
|
695
696
|
return self.admit(entry, "proposed", pending=True)
|
|
696
697
|
return self.admit(entry, "proposed")
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""A versioned library of what the harness has learned, for any action scenario (a
|
|
2
|
-
a desktop, a website, a game): one learner fills it (runtime/learning/learner.py), in a run (in-context:
|
|
1
|
+
"""A versioned library of what the harness has learned, for any action scenario: one learner fills it (runtime/learning/learner.py), in a run (in-context:
|
|
3
2
|
an entry admitted takes effect at once) and between runs (self-improvement on development
|
|
4
3
|
seeds), and evaluation reads it frozen.
|
|
5
4
|
|
|
@@ -280,7 +279,13 @@ def stage_entries(items, namespace, active, reactive, *, api=None):
|
|
|
280
279
|
for child in _initialization(node):
|
|
281
280
|
if isinstance(child, ast.Call):
|
|
282
281
|
if not isinstance(child.func, ast.Name) or child.func.id not in SETS:
|
|
283
|
-
|
|
282
|
+
called = ast.unparse(child.func) if hasattr(ast, "unparse") else "a function"
|
|
283
|
+
raise ValueError(
|
|
284
|
+
f"{item.key}, line {getattr(child, 'lineno', '?')}, calls {called}(...): while the "
|
|
285
|
+
f"entry is loaded only {' and '.join(name + '(...)' for name in SETS)} are "
|
|
286
|
+
"called. Give a function by its name or as a lambda instead of calling one "
|
|
287
|
+
"(report=my_report, not report=make_report(...)), and leave out what only "
|
|
288
|
+
"prints")
|
|
284
289
|
if isinstance(child, (ast.Attribute, ast.Subscript)) and isinstance(child.ctx, ast.Store):
|
|
285
290
|
raise ValueError(f"{item.key} cannot modify live objects during activation")
|
|
286
291
|
if staged_rules is not None:
|
|
@@ -304,7 +309,7 @@ def stage_entries(items, namespace, active, reactive, *, api=None):
|
|
|
304
309
|
|
|
305
310
|
# What a learned entry may call while it is loaded: the call that puts a node into the tree
|
|
306
311
|
# of reflexes. Everything else runs later, inside a callable (a function, a lambda).
|
|
307
|
-
SETS = ("set_reflex",)
|
|
312
|
+
SETS = ("set_reflex", "situations")
|
|
308
313
|
|
|
309
314
|
|
|
310
315
|
def _outside_callables(node):
|
|
@@ -6,9 +6,11 @@ seed) and the current library, and may propose one entry:
|
|
|
6
6
|
<note name="...">one or two sentences</note> -> notes/<name>.md
|
|
7
7
|
<memory name="...">situation and what worked</memory> -> memory/<name>.md
|
|
8
8
|
<skill name="...">def f(...): ...</skill> -> skills/<name>.py
|
|
9
|
-
<reactive name="...">def g(obs): ...</reactive> -> reactive/<name>.py
|
|
10
9
|
<none/>
|
|
11
10
|
|
|
11
|
+
(The nodes of a tree of reflexes are not proposed here: they are kept from the tree the
|
|
12
|
+
agent set, library.propose "reactive".)
|
|
13
|
+
|
|
12
14
|
The reply gives its kind, name and text; the learner checks them as every candidate
|
|
13
15
|
(runtime/learning/learner.py candidate()). A candidate only enters the library after it improves
|
|
14
16
|
the score on held-out development seeds (harness self-improve).
|
|
@@ -25,19 +27,18 @@ from harness.runtime.learning.learner import KINDS, MEMORY_MAX_CHARS, NOTE_MAX_C
|
|
|
25
27
|
from harness.runtime.learning.library import Library, eligible, executable
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
# The request
|
|
29
|
-
# bench, the run's skills). A robot's is the request of the robot harness unchanged.
|
|
30
|
+
# The request: the same whatever the agent acts in (the pack's markers name the run's skills).
|
|
30
31
|
PACK = ROOT / "prompts" / "reflect"
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
def system_prompt(names=(
|
|
34
|
+
def system_prompt(names=()) -> str:
|
|
34
35
|
"""The reflection request for a run whose embodiment kind, bench and enabled skills
|
|
35
|
-
are `names` (prompts/reflect):
|
|
36
|
+
are `names` (prompts/reflect): a note, a memory entry or a skill."""
|
|
36
37
|
from harness.runtime.decision.prompts import assemble_prompt
|
|
37
38
|
|
|
38
39
|
text = assemble_prompt(PACK, list(names), features=())
|
|
39
|
-
|
|
40
|
-
return
|
|
40
|
+
request = "\n".join(line.strip() for line in text.splitlines() if line.strip())
|
|
41
|
+
return request.replace("{note_max_chars}", str(NOTE_MAX_CHARS)).replace(
|
|
41
42
|
"{memory_max_chars}", str(MEMORY_MAX_CHARS))
|
|
42
43
|
|
|
43
44
|
|
|
@@ -109,7 +110,7 @@ def library_text(library, holdings=None):
|
|
|
109
110
|
return "\n".join(lines)[:8000] or "(empty)"
|
|
110
111
|
|
|
111
112
|
|
|
112
|
-
def propose(chat, run: Path, library, embodiment=
|
|
113
|
+
def propose(chat, run: Path, library, embodiment=(), *, since=0, holdings=None):
|
|
113
114
|
"""Use the same reflection request for online and offline learning."""
|
|
114
115
|
names = [embodiment] if isinstance(embodiment, str) else list(embodiment)
|
|
115
116
|
prompt = (f"Current library:\n{library_text(library, holdings)}\n\n"
|
|
@@ -120,7 +121,7 @@ def propose(chat, run: Path, library, embodiment="robot", *, since=0, holdings=N
|
|
|
120
121
|
|
|
121
122
|
trace = None if getattr(chat, "thinks", False) else Trace(run / "reflection" / new_name(), EVENTS)
|
|
122
123
|
reply = think(chat, system_prompt(names), [{"role": "user", "content": prompt}], trace=trace)
|
|
123
|
-
return parse_candidate(reply.text
|
|
124
|
+
return parse_candidate(reply.text), reply.text
|
|
124
125
|
|
|
125
126
|
|
|
126
127
|
def parse_candidate(text: str, *, require_test=True):
|
|
@@ -11,10 +11,10 @@ from typing import Any, Callable
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
# Guard actions a session takes itself: every embodiment stops and holds; an embodiment
|
|
15
|
-
#
|
|
16
|
-
STOP, HOLD
|
|
17
|
-
BUILTIN_ACTIONS = (STOP, HOLD
|
|
14
|
+
# Guard actions a session takes itself: every embodiment stops and holds; an embodiment's
|
|
15
|
+
# package names its own beside them (its session's guard_actions).
|
|
16
|
+
STOP, HOLD = "stop", "hold"
|
|
17
|
+
BUILTIN_ACTIONS = (STOP, HOLD)
|
|
18
18
|
|
|
19
19
|
_FORBIDDEN_PREFIXES = (
|
|
20
20
|
"open", "os.", "shutil.", "socket.", "subprocess.", "urllib.", "http.", "ftplib.",
|