@lmmslab/harness 0.0.0-stage → 0.81.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/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/harness.js +71 -0
- package/package.json +34 -4
- package/python/harness/README.md +72 -0
- package/python/harness/__init__.py +8 -0
- package/python/harness/__main__.py +3 -0
- package/python/harness/bench.py +124 -0
- package/python/harness/builtin/benches/README.md +5 -0
- package/python/harness/builtin/benches/none/bench.toml +6 -0
- package/python/harness/builtin/configs/README.md +26 -0
- package/python/harness/builtin/configs/assistant.toml +11 -0
- package/python/harness/builtin/configs/default.toml +33 -0
- package/python/harness/builtin/configs/deploy/example-api.toml +10 -0
- package/python/harness/builtin/configs/models/deepseek-api.toml +21 -0
- package/python/harness/builtin/configs/models/deepseek-flash.toml +12 -0
- package/python/harness/builtin/configs/models/grok-low.toml +8 -0
- package/python/harness/builtin/configs/models/grok-medium.toml +43 -0
- package/python/harness/builtin/configs/models/opus-5.5.toml +11 -0
- package/python/harness/builtin/environment/README.md +53 -0
- package/python/harness/builtin/environment/constraints.txt +31 -0
- package/python/harness/builtin/model-settings.js +143 -0
- package/python/harness/builtin/prompts/conversation/core.md +5 -0
- package/python/harness/builtin/prompts/conversation/pack.toml +12 -0
- package/python/harness/builtin/prompts/core/core.md +88 -0
- package/python/harness/builtin/prompts/core/pack.toml +9 -0
- package/python/harness/builtin/prompts/reflect/core.md +45 -0
- package/python/harness/builtin/prompts/reflect/pack.toml +7 -0
- package/python/harness/builtin/prompts/shared/agent-skills.md +5 -0
- package/python/harness/builtin/prompts/shared/agents.md +14 -0
- package/python/harness/builtin/prompts/shared/checklist.md +21 -0
- package/python/harness/builtin/prompts/shared/entries.md +86 -0
- package/python/harness/builtin/prompts/shared/environments.md +21 -0
- package/python/harness/builtin/prompts/shared/learning-goal.md +31 -0
- package/python/harness/builtin/prompts/shared/learning.md +27 -0
- package/python/harness/builtin/prompts/shared/mcp.md +9 -0
- package/python/harness/builtin/prompts/shared/world.md +1 -0
- package/python/harness/builtin/skills/README.md +10 -0
- package/python/harness/builtin/skills/agents/__init__.py +88 -0
- package/python/harness/builtin/skills/agents/skill.toml +11 -0
- package/python/harness/builtin/skills/checklist/__init__.py +32 -0
- package/python/harness/builtin/skills/checklist/skill.toml +9 -0
- package/python/harness/builtin/skills/conversation/__init__.py +23 -0
- package/python/harness/builtin/skills/conversation/skill.toml +8 -0
- package/python/harness/builtin/skills/entries/__init__.py +62 -0
- package/python/harness/builtin/skills/entries/skill.toml +8 -0
- package/python/harness/builtin/skills/environments/__init__.py +69 -0
- package/python/harness/builtin/skills/environments/skill.toml +9 -0
- package/python/harness/builtin/skills/experience/__init__.py +27 -0
- package/python/harness/builtin/skills/experience/skill.toml +9 -0
- package/python/harness/builtin/skills/instructions/__init__.py +29 -0
- package/python/harness/builtin/skills/instructions/skill.toml +9 -0
- package/python/harness/builtin/skills/learning/__init__.py +189 -0
- package/python/harness/builtin/skills/learning/skill.toml +7 -0
- package/python/harness/builtin/skills/mcp/__init__.py +54 -0
- package/python/harness/builtin/skills/mcp/skill.toml +10 -0
- package/python/harness/builtin/skills/memory/__init__.py +130 -0
- package/python/harness/builtin/skills/memory/skill.toml +13 -0
- package/python/harness/builtin/skills/verify/__init__.py +31 -0
- package/python/harness/builtin/skills/verify/skill.toml +7 -0
- package/python/harness/builtin/third_party/sources.toml +40 -0
- package/python/harness/cli.py +1182 -0
- package/python/harness/config/__init__.py +224 -0
- package/python/harness/config/agent.py +777 -0
- package/python/harness/core/__init__.py +52 -0
- package/python/harness/core/artifacts.py +46 -0
- package/python/harness/core/codec.py +160 -0
- package/python/harness/core/contracts.py +75 -0
- package/python/harness/core/episodes.py +150 -0
- package/python/harness/core/format.py +51 -0
- package/python/harness/core/http.py +124 -0
- package/python/harness/core/lanes.py +324 -0
- package/python/harness/core/linux_sandbox.py +55 -0
- package/python/harness/core/media.py +96 -0
- package/python/harness/core/memory.py +147 -0
- package/python/harness/core/ports.py +63 -0
- package/python/harness/core/procs.py +227 -0
- package/python/harness/core/remote.py +102 -0
- package/python/harness/core/spans.py +166 -0
- package/python/harness/core/trace.py +139 -0
- package/python/harness/core/wait.py +12 -0
- package/python/harness/core/worker.py +388 -0
- package/python/harness/core/worker_pipe.py +119 -0
- package/python/harness/embodiments.py +217 -0
- package/python/harness/extensions.py +112 -0
- package/python/harness/host/__init__.py +397 -0
- package/python/harness/host/client.py +201 -0
- package/python/harness/host/http.py +720 -0
- package/python/harness/host/listing.py +68 -0
- package/python/harness/host/server.py +189 -0
- package/python/harness/host/sessions.py +406 -0
- package/python/harness/host/tasks.py +1308 -0
- package/python/harness/host/workers.py +257 -0
- package/python/harness/host/workspaces.py +256 -0
- package/python/harness/model_list.py +117 -0
- package/python/harness/packages/__init__.py +73 -0
- package/python/harness/packages/addons.py +121 -0
- package/python/harness/packages/archive.py +122 -0
- package/python/harness/packages/describe.py +46 -0
- package/python/harness/packages/environments.py +448 -0
- package/python/harness/packages/fetch.py +57 -0
- package/python/harness/packages/manager.py +587 -0
- package/python/harness/packages/manifest.py +221 -0
- package/python/harness/packages/migrate.py +68 -0
- package/python/harness/packages/provision.py +38 -0
- package/python/harness/packages/registry.py +275 -0
- package/python/harness/packages/resolve.py +89 -0
- package/python/harness/packages/sources.py +141 -0
- package/python/harness/packages/state.py +213 -0
- package/python/harness/packages/versions.py +112 -0
- package/python/harness/paths.py +218 -0
- package/python/harness/providers.py +303 -0
- package/python/harness/runtime/__init__.py +8 -0
- package/python/harness/runtime/decision/__init__.py +1 -0
- package/python/harness/runtime/decision/loop.py +198 -0
- package/python/harness/runtime/decision/messages.py +271 -0
- package/python/harness/runtime/decision/model.py +424 -0
- package/python/harness/runtime/decision/prompts.py +248 -0
- package/python/harness/runtime/decision/protocol.py +169 -0
- package/python/harness/runtime/decision/thoughts.py +199 -0
- package/python/harness/runtime/events.py +213 -0
- package/python/harness/runtime/execution/__init__.py +1 -0
- package/python/harness/runtime/execution/attached.py +96 -0
- package/python/harness/runtime/execution/control.py +211 -0
- package/python/harness/runtime/execution/entries.py +665 -0
- package/python/harness/runtime/execution/kernel.py +811 -0
- package/python/harness/runtime/execution/noenv.py +84 -0
- package/python/harness/runtime/execution/results.py +40 -0
- package/python/harness/runtime/execution/session.py +871 -0
- package/python/harness/runtime/execution/skills.py +436 -0
- package/python/harness/runtime/learning/__init__.py +1 -0
- package/python/harness/runtime/learning/active.py +314 -0
- package/python/harness/runtime/learning/experience.py +48 -0
- package/python/harness/runtime/learning/fixtures.py +167 -0
- package/python/harness/runtime/learning/learner.py +651 -0
- package/python/harness/runtime/learning/library.py +504 -0
- package/python/harness/runtime/learning/reflect.py +151 -0
- package/python/harness/runtime/learning/usage.py +30 -0
- package/python/harness/runtime/learning/views.py +89 -0
- package/python/harness/runtime/reactive/__init__.py +1 -0
- package/python/harness/runtime/reactive/rules.py +549 -0
- package/python/harness/runtime/safety/__init__.py +1 -0
- package/python/harness/runtime/safety/approval.py +131 -0
- package/python/harness/runtime/safety/input.py +62 -0
- package/python/harness/runtime/safety/isolation.py +419 -0
- package/python/harness/runtime/safety/shield.py +129 -0
- package/python/harness/runtime/status.py +23 -0
- package/python/harness/runtime/task/__init__.py +7 -0
- package/python/harness/runtime/task/context.py +431 -0
- package/python/harness/runtime/task/delegation.py +468 -0
- package/python/harness/runtime/task/environments.py +268 -0
- package/python/harness/runtime/task/run.py +2878 -0
- package/python/harness/runtime/tick.py +909 -0
- package/python/harness/sdk/__init__.py +281 -0
- package/python/harness/services/__init__.py +6 -0
- package/python/harness/services/broker.py +35 -0
- package/python/harness/services/connectors.py +88 -0
- package/python/harness/services/mcp.py +298 -0
- package/python/harness/services/mcp_stdio.py +131 -0
- package/python/harness/services/placement.py +82 -0
- package/python/harness/services/registry.py +156 -0
- package/python/harness/settings.py +536 -0
- package/python/harness/terminal.py +79 -0
- package/python/harness/transcript.py +297 -0
- package/python/harness/tui/__init__.py +68 -0
- package/python/harness/tui/chat.py +1181 -0
- package/python/harness/tui/pty.py +81 -0
- package/python/harness/tui/renderer.py +45 -0
- package/python/harness/tui/timeline_rows.py +58 -0
- package/python/harness/tui/views.py +434 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""In-context learning, in a program: the model proposes a library entry (a note, a memory
|
|
2
|
+
entry, a skill with its test, a reactive entry) while it works, the entry's own test runs
|
|
3
|
+
here, in the environment as it is, and an entry that passes is admitted to the library
|
|
4
|
+
(runtime/learning/learner.py) and takes effect at once: its code runs in this namespace, a memory
|
|
5
|
+
entry is recallable, a note joins the prompt from the next call. The same library and the
|
|
6
|
+
same learner as self-improvement between runs; the run's [runtime.library] settings say
|
|
7
|
+
whether a run learns at all (`learn = "on"`).
|
|
8
|
+
|
|
9
|
+
library.propose(kind, name, text, test=None, summary="", attachments=None, max_seconds=120, setup=None)
|
|
10
|
+
library.entries() / library.version() / library.attachment(sha256)
|
|
11
|
+
ClosedLoop the base class of a skill: confirm, do, check, retry, reason
|
|
12
|
+
sandbox(op, **arguments) the environment's practice sandbox, in an active run that has
|
|
13
|
+
one (else None): stages a scene through the worker
|
|
14
|
+
|
|
15
|
+
A test's `setup` runs in the sandbox before it, to stage its scene; it is kept with the test
|
|
16
|
+
(SETUP, at its start), and a replay where there is no sandbox (a task run) leaves such a
|
|
17
|
+
test alone instead of failing it.
|
|
18
|
+
|
|
19
|
+
The kernel may not write files: an admission goes to the conversation that runs the program
|
|
20
|
+
(a note it answers), which writes the library. A kernel without a host (a test, a script)
|
|
21
|
+
admits through a Learner of its own (the option `library_directory`)."""
|
|
22
|
+
|
|
23
|
+
import ast
|
|
24
|
+
import base64
|
|
25
|
+
import uuid
|
|
26
|
+
|
|
27
|
+
from harness.sdk import spans
|
|
28
|
+
from harness.sdk import control
|
|
29
|
+
|
|
30
|
+
from harness.sdk import ClosedLoop, Result, Stop, candidate, entry_key
|
|
31
|
+
|
|
32
|
+
# Default limit accepted for old proposal callers.
|
|
33
|
+
TEST_SECONDS = 120.0
|
|
34
|
+
# A kept test that stages its scene in the practice sandbox starts with its setup between these.
|
|
35
|
+
SETUP = "# setup: stages the scene in the practice sandbox"
|
|
36
|
+
SETUP_END = "# the test"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class LibraryApi:
|
|
40
|
+
"""The library as a program sees it (`library`)."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, session, given: dict):
|
|
43
|
+
self._session = session
|
|
44
|
+
self._given = dict(given or {})
|
|
45
|
+
|
|
46
|
+
# -- the host ---------------------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
def _ask(self, action, wait=True, **request):
|
|
49
|
+
# A note's own kind is its first argument: an entry's kind travels as "entry".
|
|
50
|
+
request = {("entry" if key == "kind" else key): value for key, value in request.items()}
|
|
51
|
+
if spans.connected():
|
|
52
|
+
identifier = uuid.uuid4().hex[:12]
|
|
53
|
+
spans.note("library", action=action, id=identifier, wait=wait, **request)
|
|
54
|
+
if not wait:
|
|
55
|
+
return None
|
|
56
|
+
answer = control.wait_answer(identifier)
|
|
57
|
+
if answer is None:
|
|
58
|
+
raise RuntimeError("the host did not answer (paused)")
|
|
59
|
+
if answer.get("error"):
|
|
60
|
+
raise RuntimeError(answer["error"])
|
|
61
|
+
return answer.get("value")
|
|
62
|
+
if not self._given.get("directory"):
|
|
63
|
+
raise RuntimeError("no library in this run")
|
|
64
|
+
from harness.sdk import Learner
|
|
65
|
+
|
|
66
|
+
learner = Learner(self._given["directory"], self._given.get("settings"))
|
|
67
|
+
return learner.handle({"action": action, **request}, source=learner.settings["trigger"])
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def _learning(self) -> bool:
|
|
71
|
+
return (self._given.get("settings") or {}).get("learn") == "on"
|
|
72
|
+
|
|
73
|
+
def propose(self, kind, name, text, test=None, summary="", attachments=None, max_seconds=TEST_SECONDS,
|
|
74
|
+
setup=None):
|
|
75
|
+
"""Store a note, memory, skill or rule proposal. Executable candidates need a test
|
|
76
|
+
and stay pending until a trusted host verifies their exact revision. An optional
|
|
77
|
+
setup is stored with the test for the verifier. Attachments are {filename: bytes}.
|
|
78
|
+
Returns {"ok", "evidence", "version", "queued"} or {"ok": False, "reason"}."""
|
|
79
|
+
if not self._learning:
|
|
80
|
+
return {"ok": False, "reason": "learning is off in this run: the library is frozen"}
|
|
81
|
+
try:
|
|
82
|
+
# The learner's checks (its kind, its name, ...), here before the test acts (the
|
|
83
|
+
# host checks again).
|
|
84
|
+
entry = candidate(kind, name, text, test, summary=summary, attachments=attachments)
|
|
85
|
+
except ValueError as error:
|
|
86
|
+
return {"ok": False, "reason": str(error)}
|
|
87
|
+
if setup:
|
|
88
|
+
if kind not in ("skill", "reactive") or not test:
|
|
89
|
+
return {"ok": False, "reason": "setup requires an executable proposal with a test"}
|
|
90
|
+
test = staged(setup, test)
|
|
91
|
+
if kind in ("skill", "reactive"):
|
|
92
|
+
if not test:
|
|
93
|
+
return {"ok": False, "reason": f"a {kind} entry needs its test"}
|
|
94
|
+
blind = blind_check(entry.text)
|
|
95
|
+
if blind:
|
|
96
|
+
return {"ok": False, "reason": blind}
|
|
97
|
+
files = {filename: base64.b64encode(value.encode("utf-8") if isinstance(value, str) else bytes(value))
|
|
98
|
+
.decode("ascii") for filename, value in (attachments or {}).items()}
|
|
99
|
+
try:
|
|
100
|
+
admitted = self._ask("admit", kind=kind, name=name, text=entry.text, test=test, summary=summary, attachments=files)
|
|
101
|
+
except (ValueError, RuntimeError) as error:
|
|
102
|
+
return {"ok": False, "reason": str(error)}
|
|
103
|
+
return {"ok": True, "evidence": admitted["evidence"], "version": admitted["version_after"],
|
|
104
|
+
**({"queued": True} if not admitted.get("admitted") else {})}
|
|
105
|
+
|
|
106
|
+
def entries(self):
|
|
107
|
+
"""The library's entries: [{"section", "name", "evidence", "source", "origin",
|
|
108
|
+
"summary", ...}] (evidence: proposed, provisional, replayed, validated)."""
|
|
109
|
+
return self._ask("entries")
|
|
110
|
+
|
|
111
|
+
def version(self):
|
|
112
|
+
"""The library's version now (each admission changes it)."""
|
|
113
|
+
return self._ask("version")
|
|
114
|
+
|
|
115
|
+
def attachment(self, sha256):
|
|
116
|
+
"""The bytes of an attachment in the library, by its sha256."""
|
|
117
|
+
return base64.b64decode(self._ask("attachment", sha256=str(sha256)))
|
|
118
|
+
|
|
119
|
+
def record(self, name, ok, detail=None, kind="skill"):
|
|
120
|
+
"""How a use of an entry went in play (its uses and success rate)."""
|
|
121
|
+
self._ask("record", wait=getattr(self._session, "embodiment", None) != "robot", key=entry_key(kind, name), ok=bool(ok),
|
|
122
|
+
detail=None if detail is None else str(detail)[:200])
|
|
123
|
+
|
|
124
|
+
def __repr__(self):
|
|
125
|
+
return "<library: propose(kind, name, text, test), entries(), version(), attachment(sha256), record(...)>"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def staged(setup, test) -> str:
|
|
129
|
+
"""A test with the setup that stages its scene in the sandbox, as it is kept."""
|
|
130
|
+
return f"{SETUP}\n{str(setup).strip()}\n{SETUP_END}\n{str(test).strip()}\n"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class Sandbox:
|
|
134
|
+
"""The environment's practice sandbox in an active run (`sandbox`): its bench's [sandbox]
|
|
135
|
+
(bench.py), each op a worker call that the worker allows only in the active run's
|
|
136
|
+
episode. sandbox(op, **arguments) returns the worker's answer."""
|
|
137
|
+
|
|
138
|
+
def __init__(self, session, given: dict):
|
|
139
|
+
self._session = session
|
|
140
|
+
self.what = str(given.get("what") or "")
|
|
141
|
+
self.ops = dict(given.get("ops") or {})
|
|
142
|
+
|
|
143
|
+
def __call__(self, op, **arguments):
|
|
144
|
+
if op not in self.ops:
|
|
145
|
+
raise ValueError(f"the sandbox's ops are {sorted(self.ops)}, not {op!r}")
|
|
146
|
+
with spans.span("service", "sandbox", op=op):
|
|
147
|
+
return self._session.env.call("sandbox", episode_id=self._session.episode_id, op=op, **arguments)
|
|
148
|
+
|
|
149
|
+
def __repr__(self):
|
|
150
|
+
return f"<sandbox: {self.what} ops: {', '.join(f'{op} ({what})' for op, what in self.ops.items())}>"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def blind_check(code):
|
|
154
|
+
"""Why a ClosedLoop of a code entry checks nothing (None when each checks something):
|
|
155
|
+
its check() is missing or always True, so every try "succeeds" whatever happened. A
|
|
156
|
+
text that does not parse is left to the run."""
|
|
157
|
+
try:
|
|
158
|
+
entry = ast.parse(code)
|
|
159
|
+
except SyntaxError:
|
|
160
|
+
return None
|
|
161
|
+
for node in entry.body:
|
|
162
|
+
if not isinstance(node, ast.ClassDef) or not any(
|
|
163
|
+
getattr(base, "id", getattr(base, "attr", None)) == "ClosedLoop" for base in node.bases):
|
|
164
|
+
continue
|
|
165
|
+
check = next((item for item in node.body if isinstance(item, ast.FunctionDef) and item.name == "check"), None)
|
|
166
|
+
body = [statement for statement in (check.body if check else []) if not (
|
|
167
|
+
isinstance(statement, ast.Expr) and isinstance(statement.value, ast.Constant))]
|
|
168
|
+
if check is None or (len(body) == 1 and isinstance(body[0], ast.Return)
|
|
169
|
+
and isinstance(body[0].value, ast.Constant) and body[0].value.value is True):
|
|
170
|
+
return (f"{node.name}.check() always says True: a closed loop looks at the world after do() (the "
|
|
171
|
+
f"screen, a value it reads) and returns True or why not")
|
|
172
|
+
return None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class Learning:
|
|
176
|
+
def _library_api(self):
|
|
177
|
+
api = self.__dict__.get("_library_api_data")
|
|
178
|
+
if api is None:
|
|
179
|
+
api = self.__dict__["_library_api_data"] = LibraryApi(self, getattr(self, "library_given", None) or {})
|
|
180
|
+
return api
|
|
181
|
+
|
|
182
|
+
def _sandbox(self):
|
|
183
|
+
"""The practice sandbox, in an active run whose environment has one; else None."""
|
|
184
|
+
given = getattr(self, "sandbox_given", None) or {}
|
|
185
|
+
return Sandbox(self, given) if given.get("ops") else None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def exports(session):
|
|
189
|
+
return {"library": session._library_api(), "ClosedLoop": ClosedLoop, "sandbox": session._sandbox()}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
name = "learning"
|
|
2
|
+
summary = "Propose notes, memory, skills and rules. Executable proposals wait for trusted verification of their revision. ClosedLoop defines bounded skills. A compatible practice environment can supply sandbox."
|
|
3
|
+
layer = "base"
|
|
4
|
+
mixin = "skills.learning:Learning"
|
|
5
|
+
exports = ["library", "ClosedLoop", "sandbox"]
|
|
6
|
+
order = 76
|
|
7
|
+
embodiments = ["*"]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""MCP tools configured and called by the conversation host."""
|
|
2
|
+
|
|
3
|
+
import uuid
|
|
4
|
+
|
|
5
|
+
from harness.core import spans
|
|
6
|
+
from harness.runtime.execution import control
|
|
7
|
+
from harness.sdk import McpError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class McpTools:
|
|
11
|
+
def _mcp_request(self, method, **detail):
|
|
12
|
+
from harness.runtime.reactive.rules import _restricted
|
|
13
|
+
|
|
14
|
+
if getattr(_restricted, "active", False) or not spans.connected():
|
|
15
|
+
raise McpError("An MCP call requires a running host program")
|
|
16
|
+
from harness.runtime.execution.entries import current_entry, Cancelled
|
|
17
|
+
owner = current_entry()
|
|
18
|
+
def cancelled():
|
|
19
|
+
return owner is not None and any(entry._cancel.is_set() for entry in owner.lineage())
|
|
20
|
+
identifier = uuid.uuid4().hex
|
|
21
|
+
answer = None
|
|
22
|
+
with control._answered:
|
|
23
|
+
control._mcp_calls.add(identifier)
|
|
24
|
+
try:
|
|
25
|
+
spans.note("mcp_request", id=identifier, method=method,
|
|
26
|
+
entry=owner.id if owner is not None else None, **detail)
|
|
27
|
+
answer = control.wait_answer(identifier, stop=lambda: cancelled() or
|
|
28
|
+
(owner is None and control.message_arrived()))
|
|
29
|
+
finally:
|
|
30
|
+
with control._answered:
|
|
31
|
+
control._mcp_calls.discard(identifier)
|
|
32
|
+
control._answers.pop(identifier, None)
|
|
33
|
+
if answer is None:
|
|
34
|
+
spans.note("mcp_cancel", id=identifier)
|
|
35
|
+
if cancelled():
|
|
36
|
+
raise Cancelled(f"entry {owner.id} was cancelled")
|
|
37
|
+
if answer is None:
|
|
38
|
+
raise control.stopped("mcp")
|
|
39
|
+
if "error" in answer:
|
|
40
|
+
raise McpError(answer["error"])
|
|
41
|
+
return answer["value"]
|
|
42
|
+
|
|
43
|
+
def mcp_tools(self):
|
|
44
|
+
"""List the host's enabled MCP tools and their input schemas."""
|
|
45
|
+
return self._mcp_request("list")
|
|
46
|
+
|
|
47
|
+
def mcp_call(self, tool, /, **arguments):
|
|
48
|
+
"""Call an enabled MCP tool through the conversation host."""
|
|
49
|
+
result = self._mcp_request("call", tool=tool, arguments=arguments)
|
|
50
|
+
for item in result.get("content", []):
|
|
51
|
+
if item.get("type") == "image" and item.get("data") and item.get("mimeType"):
|
|
52
|
+
self._attachments.append({"caption": f"MCP {tool}",
|
|
53
|
+
"image_url": f"data:{item['mimeType']};base64,{item['data']}"})
|
|
54
|
+
return result
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
name = "mcp"
|
|
2
|
+
summary = "Tools of MCP servers (Model Context Protocol, streamable HTTP): list them and call them from programs."
|
|
3
|
+
layer = "base"
|
|
4
|
+
mixin = "skills.mcp:McpTools"
|
|
5
|
+
exports = ["mcp_tools", "mcp_call"]
|
|
6
|
+
needs = ["mcp"]
|
|
7
|
+
optional = true
|
|
8
|
+
order = 150
|
|
9
|
+
# The robot's agent names MCP servers as services; the app's, its connectors.
|
|
10
|
+
embodiments = ["*"]
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Memory (runtime/task/context.py): what this run saw and where, and the library's memory
|
|
2
|
+
entries, through one interface. The run's working memory is the host's (shared with the
|
|
3
|
+
sub-agents); without a host (a test, a script) the kernel keeps one of its own."""
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
import uuid
|
|
8
|
+
|
|
9
|
+
from harness.sdk import Escalation, control, spans
|
|
10
|
+
|
|
11
|
+
# A request the host has not answered in this long fails (it never hangs a program).
|
|
12
|
+
ANSWER_SECONDS = 60.0
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ReadOnlyMemory:
|
|
16
|
+
def recall(self, query, k=5):
|
|
17
|
+
"""Search the same memory while keeping the original read-only call signature."""
|
|
18
|
+
return Memory._memory(self, "recall", query=query, k=k)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Memory:
|
|
22
|
+
def remember(self, kind, text="", where=None, name=None, confidence=0.5, keep=False):
|
|
23
|
+
"""Remember an observation or note. keep=True saves the same entry in a writable library."""
|
|
24
|
+
return self._memory_remember(kind, where, text, confidence, self._memory_writer(),
|
|
25
|
+
name=name, wait=True, keep=keep)
|
|
26
|
+
|
|
27
|
+
def recall(self, query=None, k=5, kind=None, near=None, radius=None):
|
|
28
|
+
"""Entries of this run's memory and the library's memory, best first: those of `kind`
|
|
29
|
+
(a name, or a family: "ore" finds "ore:iron"), nearest to `near` first (default:
|
|
30
|
+
where you are, when the worker says; "distance") within `radius`, else best for
|
|
31
|
+
`query` ("score"), else this run's newest first; entries without a position come
|
|
32
|
+
after the placed ones (none within a `radius`). Each {"id", "scope": "run" or
|
|
33
|
+
"library", "kind", "name", "text", "where", "evidence", ...}."""
|
|
34
|
+
here, space = self._memory_here()
|
|
35
|
+
if near is None and radius is not None:
|
|
36
|
+
near = here
|
|
37
|
+
return self._memory("recall", query=query, k=int(k), kind=kind, radius=radius, space=space,
|
|
38
|
+
near=None if near is None else [float(v) for v in near])
|
|
39
|
+
|
|
40
|
+
def forget(self, ident):
|
|
41
|
+
"""Forget a visible memory by ID. A kept entry requires a writable library."""
|
|
42
|
+
return self._memory("forget", id=ident, space=self._memory_here()[1])
|
|
43
|
+
|
|
44
|
+
# -- inside --------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
def _memory(self, action, wait=True, **request):
|
|
47
|
+
request = {key: value for key, value in request.items() if value is not None}
|
|
48
|
+
if spans.connected():
|
|
49
|
+
# A note's own fields are kind and id: an entry's travel as "of" and "entry".
|
|
50
|
+
identifier = uuid.uuid4().hex[:12]
|
|
51
|
+
spans.note("memory", action=action, id=identifier, wait=wait,
|
|
52
|
+
**{{"kind": "of", "id": "entry"}.get(key, key): value for key, value in request.items()})
|
|
53
|
+
if not wait:
|
|
54
|
+
return None
|
|
55
|
+
deadline = time.monotonic() + ANSWER_SECONDS
|
|
56
|
+
own = threading.current_thread() is threading.main_thread()
|
|
57
|
+
answer = control.wait_answer(identifier, poll=None, stop=control.message_arrived if own else None,
|
|
58
|
+
deadline=deadline)
|
|
59
|
+
if answer is None:
|
|
60
|
+
if control.pause_requested() or (own and control.message_arrived()):
|
|
61
|
+
raise control.stopped("memory")
|
|
62
|
+
raise RuntimeError("the host did not answer the memory request within 60 seconds")
|
|
63
|
+
if answer.get("error"):
|
|
64
|
+
raise RuntimeError(answer["error"])
|
|
65
|
+
return answer.get("value")
|
|
66
|
+
own = Memory._memory_own(self)
|
|
67
|
+
given = getattr(self, "library_given", None) or {}
|
|
68
|
+
persist = None
|
|
69
|
+
if given.get("directory") and (given.get("settings") or {}).get("learn") == "on":
|
|
70
|
+
from harness.sdk import Learner
|
|
71
|
+
|
|
72
|
+
learner = Learner(given["directory"], given.get("settings"))
|
|
73
|
+
def persist(item, *, forgotten=False):
|
|
74
|
+
changed = learner.store_memory(item, forgotten=forgotten)
|
|
75
|
+
own.library = [entry for entry in own.library if entry["id"] != item["id"]]
|
|
76
|
+
if not forgotten:
|
|
77
|
+
own.kept(changed)
|
|
78
|
+
return changed
|
|
79
|
+
return own.handle({"action": action, **request}, persist=persist)
|
|
80
|
+
|
|
81
|
+
def _memory_own(self):
|
|
82
|
+
"""The kernel's own store, without a host (a test, a script): the library's memory
|
|
83
|
+
entries as it starts."""
|
|
84
|
+
own = self.__dict__.get("_memory_own_store")
|
|
85
|
+
if own is None:
|
|
86
|
+
from harness.sdk import Learner, WorkingMemory, memory_entries
|
|
87
|
+
|
|
88
|
+
own = self.__dict__["_memory_own_store"] = WorkingMemory()
|
|
89
|
+
given = getattr(self, "library_given", None) or {}
|
|
90
|
+
if given.get("directory"):
|
|
91
|
+
own.library = memory_entries(Learner(given["directory"], given.get("settings")).library)
|
|
92
|
+
elif getattr(self, "memory", None):
|
|
93
|
+
from harness.runtime.task.context import entry
|
|
94
|
+
|
|
95
|
+
own.library = [entry({"kind": "memory", "id": item["name"], **item}, "library")
|
|
96
|
+
for item in self.memory]
|
|
97
|
+
return own
|
|
98
|
+
|
|
99
|
+
def _memory_remember(self, kind, where, text="", confidence=0.5, source=None, name=None, wait=False, keep=False):
|
|
100
|
+
"""A note from a skill, a service or the tick (no wait for the host by default)."""
|
|
101
|
+
space = self._memory_here()[1]
|
|
102
|
+
return self._memory("remember", wait=wait, kind=str(kind), text=str(text or ""), name=name,
|
|
103
|
+
where=where if where is None or isinstance(where, str) else [float(v) for v in where],
|
|
104
|
+
confidence=float(confidence), source=source, space=space, keep=keep)
|
|
105
|
+
|
|
106
|
+
def _memory_here(self):
|
|
107
|
+
"""(position, space) of the body now, when the worker's state says ("here")."""
|
|
108
|
+
state = getattr(self, "state", None) or {}
|
|
109
|
+
return (state.get("here"), state.get("space")) if isinstance(state, dict) else (None, None)
|
|
110
|
+
|
|
111
|
+
def _memory_writer(self):
|
|
112
|
+
"""Who writes, when the program does not say: None for the agent's own programs (the
|
|
113
|
+
host puts the agent's name), "<agent>/<entry>" inside an entry."""
|
|
114
|
+
entries = self.__dict__.get("_entries")
|
|
115
|
+
current = entries.current() if entries is not None else None
|
|
116
|
+
if current is None or current is getattr(entries, "root", None):
|
|
117
|
+
return None
|
|
118
|
+
return "program"
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def turn_report(session):
|
|
122
|
+
"""After each program: recent notes and the nearest fresh places."""
|
|
123
|
+
if getattr(session, "embodiment", None) == "robot":
|
|
124
|
+
return None
|
|
125
|
+
here, space = session._memory_here()
|
|
126
|
+
try:
|
|
127
|
+
text = session._memory("summary", near=here, space=space)
|
|
128
|
+
except (Escalation, RuntimeError):
|
|
129
|
+
return None # paused: the host answers nothing now
|
|
130
|
+
return {"text": "Memory: notes and nearby places (recall() for more):\n" + text} if text else None
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
name = "memory"
|
|
2
|
+
summary = "Memory, one interface for two kinds: what this run saw and where (remember, recall, forget; the host keeps it, shared with sub-agents) and the library's memory entries (recall; remember(..., keep=True) writes one through the learner)."
|
|
3
|
+
layer = "base"
|
|
4
|
+
mixin = "skills.memory:Memory"
|
|
5
|
+
exports = ["remember", "recall", "forget"]
|
|
6
|
+
required = true
|
|
7
|
+
order = 70
|
|
8
|
+
embodiments = ["*"]
|
|
9
|
+
|
|
10
|
+
[interface.robot]
|
|
11
|
+
summary = "Read-only entries of the library's memory (empty without a library)."
|
|
12
|
+
mixin = "skills.memory:ReadOnlyMemory"
|
|
13
|
+
exports = ["recall"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""The success verifier, asked from inside a program."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from harness.sdk import control
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Verify:
|
|
8
|
+
def verify(self, claim, cameras=None):
|
|
9
|
+
"""Ask the success verifier whether `claim` holds in the current camera views.
|
|
10
|
+
The verifier gets the instructions of this session's embodiment kind. Returns
|
|
11
|
+
(holds, answer): holds is True for yes, False for no, None when the verifier is
|
|
12
|
+
disabled in this configuration."""
|
|
13
|
+
if control.host_thoughts:
|
|
14
|
+
try:
|
|
15
|
+
evidence = self._evidence()
|
|
16
|
+
except Exception:
|
|
17
|
+
evidence = ""
|
|
18
|
+
reply = control.think("verifier", claim=str(claim), cameras=list(cameras) if cameras is not None else None,
|
|
19
|
+
evidence=evidence)
|
|
20
|
+
if reply is None:
|
|
21
|
+
return None, "The verifier is disabled in this configuration."
|
|
22
|
+
answer = reply.text.strip()
|
|
23
|
+
return answer.upper().startswith("YES"), answer
|
|
24
|
+
if self.verifier is None:
|
|
25
|
+
return None, "The verifier is disabled in this configuration."
|
|
26
|
+
from harness.embodiments import KINDS
|
|
27
|
+
|
|
28
|
+
observation = self.get_observation(cameras=cameras)
|
|
29
|
+
answer = self.verifier.ask([observation.images[c] for c in observation.images],
|
|
30
|
+
f"Claim: {claim}", system=KINDS[self.embodiment].verifier).strip()
|
|
31
|
+
return answer.upper().startswith("YES"), answer
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# External source coordinates for optional package provisioning; no vendored source.
|
|
2
|
+
|
|
3
|
+
[robodojo]
|
|
4
|
+
url = "https://github.com/RoboDojo-Benchmark/RoboDojo.git"
|
|
5
|
+
path = "third_party/RoboDojo"
|
|
6
|
+
revision = "ee67a1468510da7624a089164402359f2afc72c8"
|
|
7
|
+
|
|
8
|
+
[robodojo.nested]
|
|
9
|
+
XPolicyLab = "41f864e82315e99e772c7b93d6e5e7ba6ef586cd"
|
|
10
|
+
"third_party/IsaacLab" = "afca7b09d60d8beb9c1cb28b43066499940b969b"
|
|
11
|
+
"third_party/curobo" = "895c6517243f8cb091c73c018c8167192d39599a"
|
|
12
|
+
assets = "f8862d5c36e95f207195199ec08c250dc9a78ca1"
|
|
13
|
+
|
|
14
|
+
[robolab]
|
|
15
|
+
url = "https://github.com/NVlabs/RoboLab.git"
|
|
16
|
+
path = "third_party/RoboLab"
|
|
17
|
+
revision = "ad45d4f974725d020f82c2b0d77d78533aeba2b3"
|
|
18
|
+
runtime = "third_party/RoboLab/.venv/bin/python"
|
|
19
|
+
|
|
20
|
+
[sam3]
|
|
21
|
+
url = "https://github.com/Max-Fu/sam3.git"
|
|
22
|
+
path = "third_party/sam3"
|
|
23
|
+
revision = "6fe87d64a5beb9084923d7a9e002741178635b09"
|
|
24
|
+
|
|
25
|
+
[robotwin]
|
|
26
|
+
url = "https://github.com/RoboTwin-Platform/RoboTwin.git"
|
|
27
|
+
path = "third_party/RoboTwin"
|
|
28
|
+
revision = "ea8b21121ebb3cd201ff5b3fe361944ac94eda3f"
|
|
29
|
+
|
|
30
|
+
[osomni]
|
|
31
|
+
url = "https://github.com/OS-Copilot/OS-Omni.git"
|
|
32
|
+
path = "third_party/OS-Omni"
|
|
33
|
+
revision = "1b1dc33087d6d21cb3c0f50c3a0b63ff296f711d"
|
|
34
|
+
runtime = "third_party/OS-Omni/.venv/bin/python"
|
|
35
|
+
|
|
36
|
+
[osworld]
|
|
37
|
+
url = "https://github.com/xlang-ai/OSWorld.git"
|
|
38
|
+
path = "third_party/OSWorld"
|
|
39
|
+
revision = "705623ca18e0055dd995fd5a350d6588cff2caf5"
|
|
40
|
+
runtime = "third_party/OSWorld/.venv/bin/python"
|