@lmmslab/harness 0.0.0-stage → 0.81.1
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 +1356 -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 +232 -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,268 @@
|
|
|
1
|
+
"""Other environments of one conversation, and its sub-agents on request (host side).
|
|
2
|
+
|
|
3
|
+
A conversation works in the environment its user chose. A program may ask for another
|
|
4
|
+
kind (skills/environments: use_environment); the request reaches the conversation as a
|
|
5
|
+
note, and this module decides and does it:
|
|
6
|
+
|
|
7
|
+
permission the user's setting environments.attach and its rules by kind: never,
|
|
8
|
+
ask_each, ask_once_session (the default: once per conversation and kind),
|
|
9
|
+
allow. A user who chose to skip confirmations (their physical-input level
|
|
10
|
+
is `allow`, in the settings or for this run) is not asked; a `never` level
|
|
11
|
+
still refuses. Where nobody can be asked (a run without a user) and the
|
|
12
|
+
level asks, the request is refused with the reason: it never waits and is
|
|
13
|
+
never allowed silently.
|
|
14
|
+
the place the session host's (Place): a workspace of that kind from the same pools,
|
|
15
|
+
under the same limits as conversations and sub-agents, until release or
|
|
16
|
+
the conversation's end.
|
|
17
|
+
the session the kernel builds the kind's session beside its own (runtime/execution/
|
|
18
|
+
attached.py); every call of it comes back here as a worker request, so the
|
|
19
|
+
host's checks and the user's approvals apply as they do to the
|
|
20
|
+
conversation's own worker. The kind's own prompt sections join the system
|
|
21
|
+
prompt while it is attached.
|
|
22
|
+
|
|
23
|
+
Every attachment, its reason and how it was allowed is a record of the trace
|
|
24
|
+
(environment_attached, environment_refused, environment_released) and a span of the
|
|
25
|
+
timeline, asked or not.
|
|
26
|
+
|
|
27
|
+
Sub-agents are off unless the user switched them on (settings, the conversation's start
|
|
28
|
+
or while it runs); request_agents asks the user, and a yes loads their calls and prompt.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
import threading
|
|
32
|
+
|
|
33
|
+
from harness.embodiments import KINDS, embodiment_kind
|
|
34
|
+
|
|
35
|
+
LEVELS = ("never", "ask_each", "ask_once_session", "allow")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Refused(ValueError):
|
|
39
|
+
"""Why an environment was not attached; the program gets it as the call's error."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Place:
|
|
43
|
+
"""What a server gives a conversation that asks for another environment. This one
|
|
44
|
+
gives none (a conversation run in a process of its own)."""
|
|
45
|
+
|
|
46
|
+
def kinds(self) -> dict:
|
|
47
|
+
"""{kind: {"label", "about", optionally "folder"}} of what may be attached."""
|
|
48
|
+
return {}
|
|
49
|
+
|
|
50
|
+
def level(self, kind, runtime) -> tuple:
|
|
51
|
+
"""(the level of LEVELS for `kind`, whether the user skips confirmations)."""
|
|
52
|
+
return "never", False
|
|
53
|
+
|
|
54
|
+
def begin(self, conversation, kind, folder, cancelled) -> dict:
|
|
55
|
+
"""Take a workspace of `kind`: {"env" (its worker, with the host's key), "embodiment",
|
|
56
|
+
"task", "skills" (its session's), "prompt" (its own sections), "release" (give it
|
|
57
|
+
back), optionally "metadata"}."""
|
|
58
|
+
raise Refused(f"this conversation has no place to take {kind} from")
|
|
59
|
+
|
|
60
|
+
def agents(self) -> dict:
|
|
61
|
+
"""{"mode": off or on (the setting), "depth": how deep sub-agents may go}."""
|
|
62
|
+
return {"mode": "off", "depth": 0}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Environments:
|
|
66
|
+
"""The environments attached to one conversation (TaskRun.environments)."""
|
|
67
|
+
|
|
68
|
+
def __init__(self, conversation, place: Place):
|
|
69
|
+
self.conversation, self.place = conversation, place
|
|
70
|
+
self.attached = {}
|
|
71
|
+
self.granted = set()
|
|
72
|
+
self._lock = threading.RLock()
|
|
73
|
+
|
|
74
|
+
# What the conversation calls.
|
|
75
|
+
|
|
76
|
+
def handle(self, request: dict) -> dict:
|
|
77
|
+
"""Answer a program's request: {"value": ...} or {"error": why}."""
|
|
78
|
+
action = request.get("action")
|
|
79
|
+
try:
|
|
80
|
+
if action == "use":
|
|
81
|
+
value = self.use(str(request.get("environment") or ""), str(request.get("why") or ""),
|
|
82
|
+
request.get("folder"))
|
|
83
|
+
elif action == "release":
|
|
84
|
+
value = self.release(str(request.get("environment") or ""), failed=request.get("failed"))
|
|
85
|
+
elif action == "agents":
|
|
86
|
+
value = self.enable_agents(str(request.get("why") or ""), asked_by="model")
|
|
87
|
+
else:
|
|
88
|
+
raise Refused(f"no operation {action!r}")
|
|
89
|
+
except Refused as error:
|
|
90
|
+
return {"error": str(error)}
|
|
91
|
+
except Exception as error:
|
|
92
|
+
return {"error": f"{type(error).__name__}: {error}"}
|
|
93
|
+
return {"value": value}
|
|
94
|
+
|
|
95
|
+
def of(self, name):
|
|
96
|
+
"""The attached environment `name`: {"env", "plain", "episode", "slot"}, or Refused."""
|
|
97
|
+
found = self.attached.get(name)
|
|
98
|
+
if found is None:
|
|
99
|
+
raise Refused(f"{name} is not attached to this conversation")
|
|
100
|
+
return found
|
|
101
|
+
|
|
102
|
+
def any_managed(self) -> bool:
|
|
103
|
+
return any(getattr(row["env"], "approval_key", None) for row in self.attached.values())
|
|
104
|
+
|
|
105
|
+
def states(self) -> dict:
|
|
106
|
+
"""{name: label} of what is attached now."""
|
|
107
|
+
return {name: row["label"] for name, row in self.attached.items()}
|
|
108
|
+
|
|
109
|
+
def close(self) -> None:
|
|
110
|
+
"""The conversation ended: every attached environment goes back."""
|
|
111
|
+
for kind in list(self.attached):
|
|
112
|
+
try:
|
|
113
|
+
self.release(kind, reason="the conversation ended")
|
|
114
|
+
except Exception as error:
|
|
115
|
+
self.conversation.trace.emit("cleanup_error", message=f"{kind}: {type(error).__name__}: {error}")
|
|
116
|
+
|
|
117
|
+
# Attaching.
|
|
118
|
+
|
|
119
|
+
def use(self, kind: str, why: str, folder=None) -> dict:
|
|
120
|
+
conversation, trace = self.conversation, self.conversation.trace
|
|
121
|
+
kinds = self.place.kinds()
|
|
122
|
+
with self._lock:
|
|
123
|
+
if kind in self.attached:
|
|
124
|
+
return self.attached[kind]["answer"]
|
|
125
|
+
primary = conversation.workspace_kind
|
|
126
|
+
|
|
127
|
+
def refuse(reason, **detail):
|
|
128
|
+
trace.emit("environment_refused", kind=kind, why=why, reason=reason, **detail)
|
|
129
|
+
raise Refused(reason)
|
|
130
|
+
|
|
131
|
+
if kind not in kinds:
|
|
132
|
+
refuse(f"no installed package gives the environment {kind!r}; there are {', '.join(kinds) or 'none'}")
|
|
133
|
+
label = kinds[kind].get("label") or kind
|
|
134
|
+
if kind == primary:
|
|
135
|
+
refuse(f"this conversation already works in {kind}: its calls are the plain ones")
|
|
136
|
+
if not why:
|
|
137
|
+
refuse("say why in one sentence: the user reads it when they are asked")
|
|
138
|
+
if kinds[kind].get("folder") and not folder:
|
|
139
|
+
refuse(f"{label} works in one folder. Ask the user which folder in plain text, then "
|
|
140
|
+
f"use_environment({kind!r}, why, folder=PATH)")
|
|
141
|
+
level, skips = self.place.level(kind, conversation.config.runtime)
|
|
142
|
+
asked = False
|
|
143
|
+
if level == "never":
|
|
144
|
+
refuse(f"the user's settings never allow taking {label} into a conversation (environments.attach). "
|
|
145
|
+
"Go on without it and say what you could not confirm.", level=level)
|
|
146
|
+
with self._lock:
|
|
147
|
+
granted = kind in self.granted
|
|
148
|
+
if not (skips or level == "allow" or level == "ask_once_session" and granted):
|
|
149
|
+
if not conversation.interactive:
|
|
150
|
+
refuse(f"the user's settings ask before {label} is taken (environments.attach = {level}), and "
|
|
151
|
+
"nobody can be asked in this run. Go on without it and say what you could not confirm.",
|
|
152
|
+
level=level)
|
|
153
|
+
asked = True
|
|
154
|
+
target = f"use {label}" + (f" in {folder}" if folder else "")
|
|
155
|
+
accepted, reason = conversation._ask_user("environment", target, why=why, environment=kind,
|
|
156
|
+
**({"folder": str(folder)} if folder else {}))
|
|
157
|
+
if not accepted:
|
|
158
|
+
refuse(f"the user did not allow {label}" + (f": {reason}" if reason else "")
|
|
159
|
+
+ ". Go on without it and say what you could not confirm.", level=level, asked=True)
|
|
160
|
+
if level == "ask_once_session":
|
|
161
|
+
with self._lock:
|
|
162
|
+
self.granted.add(kind)
|
|
163
|
+
try:
|
|
164
|
+
with conversation._span("env", f"use {kind}", why=why[:200]):
|
|
165
|
+
taken = self.place.begin(conversation, kind, folder, lambda: conversation._closing)
|
|
166
|
+
try:
|
|
167
|
+
row = self._start(kind, label, taken)
|
|
168
|
+
except BaseException:
|
|
169
|
+
taken["release"]()
|
|
170
|
+
raise
|
|
171
|
+
except Refused as error:
|
|
172
|
+
refuse(str(error), level=level, asked=asked)
|
|
173
|
+
except Exception as error:
|
|
174
|
+
refuse(f"{label} could not be prepared: {type(error).__name__}: {error}", level=level, asked=asked)
|
|
175
|
+
with self._lock:
|
|
176
|
+
self.attached[kind] = row
|
|
177
|
+
conversation._prompt_added(row["prompt"])
|
|
178
|
+
trace.emit("environment_attached", kind=kind, label=label, why=why, level=level, asked=asked,
|
|
179
|
+
skipped_confirmation=bool(skips and level not in ("allow",) and not granted),
|
|
180
|
+
**{**(taken.get("metadata") or {}), **({"folder": str(folder)} if folder else {})})
|
|
181
|
+
return row["answer"]
|
|
182
|
+
|
|
183
|
+
def _start(self, kind, label, taken) -> dict:
|
|
184
|
+
"""The episode of an attached environment on its worker, and what its session needs."""
|
|
185
|
+
conversation = self.conversation
|
|
186
|
+
env = taken["env"]
|
|
187
|
+
env.tools()
|
|
188
|
+
observation = env.reset(taken.get("task") or "free", conversation.seed)
|
|
189
|
+
profile = env.call("profile")
|
|
190
|
+
if embodiment_kind(profile) != taken["embodiment"]:
|
|
191
|
+
raise RuntimeError(f"the worker drives a {embodiment_kind(profile)} embodiment, not {taken['embodiment']}")
|
|
192
|
+
runtime = conversation.config.runtime
|
|
193
|
+
if profile.get("physical"):
|
|
194
|
+
# Whose steps these are and the run's physical-input policy: the real mouse and
|
|
195
|
+
# keyboard stay under it after the environment is attached.
|
|
196
|
+
identity, policy = conversation.identity or {}, dict(runtime.get("physical") or {})
|
|
197
|
+
seen = dict(runtime.get("privacy") or {})
|
|
198
|
+
env.call("physical", op="identify", episode_id=observation.episode_id, session=identity.get("session"),
|
|
199
|
+
agent=identity.get("agent"), level=policy.get("level"), rules=policy.get("rules") or [],
|
|
200
|
+
interactive=conversation.interactive,
|
|
201
|
+
**({"privacy": {key: seen[key] for key in ("level", "rules") if seen.get(key)}} if seen else {}))
|
|
202
|
+
session = {"episode_id": observation.episode_id, "embodiment": taken["embodiment"],
|
|
203
|
+
"skills": list(taken["skills"]), "timeout_seconds": float(getattr(env, "timeout", 300.0)),
|
|
204
|
+
"host_controls": sorted(getattr(env, "host_controls", ())),
|
|
205
|
+
"reactive_budget_ms": runtime.get("reactive_budget_ms", 5.0),
|
|
206
|
+
"default_max_seconds": runtime.get("default_max_seconds", 30.0),
|
|
207
|
+
"views": {"mode": "demand", "cameras": list(KINDS[taken["embodiment"]].cameras)}}
|
|
208
|
+
prompt = (f"\n\nEnvironment `{kind}` ({label}) is attached to this conversation. Its calls are the ones "
|
|
209
|
+
f"described below, each called as {kind}.NAME(...), never by the bare name; this conversation's "
|
|
210
|
+
f"own calls stay as they are. release_environment({kind!r}) gives it back."
|
|
211
|
+
+ (f" {kind}.look() puts its view in your next turn; nothing of it is shown otherwise."
|
|
212
|
+
if KINDS[taken["embodiment"]].cameras else "") + "\n"
|
|
213
|
+
+ (taken.get("prompt") or "").strip() + "\n")
|
|
214
|
+
from harness.core.remote import RemoteEnvironment
|
|
215
|
+
|
|
216
|
+
endpoint = getattr(env, "endpoint", None)
|
|
217
|
+
return {"env": env, "episode": observation.episode_id, "label": label, "release": taken["release"],
|
|
218
|
+
# Calls the worker serves to anyone go without the host's key, as the kernel
|
|
219
|
+
# itself would make them.
|
|
220
|
+
"plain": RemoteEnvironment(endpoint, timeout=float(getattr(env, "timeout", 300.0)))
|
|
221
|
+
if endpoint else env,
|
|
222
|
+
"slot": threading.BoundedSemaphore(8), "prompt": prompt,
|
|
223
|
+
"answer": {"session": session,
|
|
224
|
+
"about": f"{kind} ({label}) is attached: call it as {kind}.NAME(...). Its calls are "
|
|
225
|
+
"described in your instructions from the next turn on; "
|
|
226
|
+
f"print({kind}) lists them now."}}
|
|
227
|
+
|
|
228
|
+
def release(self, kind: str, *, reason=None, failed=None) -> bool:
|
|
229
|
+
with self._lock:
|
|
230
|
+
row = self.attached.pop(kind, None)
|
|
231
|
+
if row is None:
|
|
232
|
+
return False
|
|
233
|
+
conversation = self.conversation
|
|
234
|
+
conversation._prompt_removed(row["prompt"])
|
|
235
|
+
try:
|
|
236
|
+
row["release"]()
|
|
237
|
+
finally:
|
|
238
|
+
conversation.trace.emit("environment_released", kind=kind, label=row["label"],
|
|
239
|
+
**({"reason": str(reason)} if reason else {}),
|
|
240
|
+
**({"failed": str(failed)[:300]} if failed else {}))
|
|
241
|
+
return True
|
|
242
|
+
|
|
243
|
+
# Sub-agents.
|
|
244
|
+
|
|
245
|
+
def enable_agents(self, why: str = "", *, asked_by="user") -> dict:
|
|
246
|
+
"""Switch sub-agents on for this conversation: at once for the user's own switch,
|
|
247
|
+
after their yes for the model's request. What the kernel loads."""
|
|
248
|
+
conversation = self.conversation
|
|
249
|
+
if "agents" in conversation._skills:
|
|
250
|
+
return {"skills": [], "about": "Sub-agents are on already."}
|
|
251
|
+
setting = self.place.agents()
|
|
252
|
+
if conversation.agents is None or setting["depth"] <= 0:
|
|
253
|
+
raise Refused("this conversation cannot start sub-agents (limits.agent_depth is 0, or it has no "
|
|
254
|
+
"workspaces to give them)")
|
|
255
|
+
if asked_by == "model":
|
|
256
|
+
if not why:
|
|
257
|
+
raise Refused("say why in one sentence: the user reads it")
|
|
258
|
+
if not conversation.interactive:
|
|
259
|
+
raise Refused("sub-agents are off, and nobody can be asked in this run")
|
|
260
|
+
accepted, reason = conversation._ask_user("agents", "switch sub-agents on for this conversation", why=why)
|
|
261
|
+
if not accepted:
|
|
262
|
+
conversation.trace.emit("agents_enabled", enabled=False, why=why, asked_by=asked_by, reason=reason)
|
|
263
|
+
raise Refused("the user did not switch sub-agents on" + (f": {reason}" if reason else "")
|
|
264
|
+
+ ". Do the task yourself.")
|
|
265
|
+
added = conversation._skill_added("agents")
|
|
266
|
+
conversation.trace.emit("agents_enabled", enabled=True, asked_by=asked_by, **({"why": why} if why else {}))
|
|
267
|
+
return {"skills": ["agents"], "about": "Sub-agents are on: delegate(task, ...), wait_agents(), send_agent(), "
|
|
268
|
+
"cancel_agent(). " + ("" if added else "")}
|