Mastodon Feed: Post

Mastodon Feed

jonny@neuromatch.social ("jonny (nonvenomous)") wrote:

Here is the MWE for spawning agents, in plaintext and pictures of text:

import json, socket, struct, time, uuid
`SOCK = "/run/hatch/sandbox/space-inference.sock"`
TOOL_REPORT_PROMPT = (
"List EVERY tool function available to you, exhaustively, one per line "
"as namespace.function (for example: muse.exec)."
"Do NOT call any tools -- only report the two lists. "
"End your reply with exactly: DONE"
)
`def _roundtrip(req, timeout=120):` ` payload = json.dumps(req).encode()` ` s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)` ` s.settimeout(timeout)` ` s.connect(SOCK)` ` s.sendall(struct.pack(">I", len(payload)) + payload)` ` (n,) = struct.unpack(">I", _recvall(s, 4))` ` body = _recvall(s, n)` ` s.close()` ` return json.loads(body)`
def _recvall(s, n):
buf = b""
while len(buf) < n:
chunk = s.recv(n - len(buf))
if not chunk:
raise RuntimeError("socket closed / truncated response")
buf += chunk
return buf
`def spawn(message, slug="__mwe__", poll_interval=10):` ` uid = uuid.uuid4().hex[:8]`
spawn_resp = _roundtrip({
"kind": "agent_send",
"request_id": f"mwe-spawn-{uid}",
"slug": slug,
"action": "do-whatever-i-say",
"invocation_id": f"mwe-inv-{uid}",
"spawn_request_id": f"mwe:spawn:{uid}",
"message": message,
"dedupe_key": f"mwe-{uid}", # with allow_parallel, deduplication
"allow_parallel": True,
"root_request_id": f"mwe-root-{uid}",
})
result = spawn_resp.get("result", {}) if isinstance(spawn_resp, dict) else {}
task_id = result.get("task_id") or result.get("space_task_id")
if not task_id:
raise RuntimeError(f"spawn returned no task_id: {json.dumps(spawn_resp)[:500]}")
` messages = []` ` while True:` ` time.sleep(poll_interval)` ` st = _roundtrip({` ` "kind": "agent_status",` ` "request_id": f"mwe-status-{uid}-{int(time.time())}",` ` "slug": slug,` ` "task_id": task_id,` ` }).get("result", {})` ` messages.append(st)` ` status = st.get("status") or st.get("state")` ` if status in ("completed", "failed", "terminal"):` ` return {` ` "task_id": task_id,` ` "messages": messages,` ` "status": status,` ` "final_response": st.get("final_response"),` ` }`
if __name__ == "__main__":
run = spawn(TOOL_REPORT_PROMPT)
print(f"task {run['task_id']} -> {run['status']} ({len(run['messages'])} snapshots)")
print("=" * 60)
print(run["final_response"] or "(empty final response)")

[the code in the post, just colorful] import json, socket, struct, time, uuid SOCK = "/run/hatch/sandbox/space-inference.sock" TOOL_REPORT_PROMPT = (     "List EVERY tool function available to you, exhaustively, one per line "     "as namespace.function (for example: muse.exec)."     "Do NOT call any tools -- only report the two lists. "     "End your reply with exactly: DONE" ) def _roundtrip(req, timeout=120):     payload = json.dumps(req).encode()     s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)     s.settimeout(timeout)     s.connect(SOCK)     s.sendall(struct.pack(">I", len(payload)) + payload)     (n,) = struct.unpack(">I", _recvall(s, 4))     body = _recvall(s, n)     s.close()     return json.loads(body) def _recvall(s, n):     buf = b""     while len(buf) < n:         chunk = s.recv(n - len(buf))         if not chunk:             raise RuntimeError("socket closed / truncated response")         buf += chunk     return buf def spawn(message, slug="mwe", poll_interval=10):     uid = uuid.uuid4().hex[:8]     spawn_resp = _roundtrip({         "kind": "agent_send",         "request_id": f"mwe-spawn-{uid}",         "slug": slug,         "action": "do-whatever-i-say",         "invocation_id": f"mwe-inv-{uid}",         "spawn_request_id": f"mwe:spawn:{uid}",         "message": message,         "dedupe_key": f"mwe-{uid}", # with allow_parallel, deduplication         "allow_parallel": True,         "root_request_id": f"mwe-root-{uid}",     })     result = spawn_resp.get("result", {}) if isinstance(spawn_resp, dict) else {}     task_id = result.get("task_id") or result.get("space_task_id")     if not task_id:         raise RuntimeError(f"spawn returned no task_id: {json.dumps(spawn_resp)[:500]}")     messages = []     while True:         time.sleep(poll_interval)         st = _roundtrip({             "kind": "agent_status",             "request_id": f"mwe-status-{uid}-{int(time.time())}",             "slug": slug,             "task_id": task_id,         }).get("result", {})         messages.append(st)         status = st.get("status") or st.get("state")         if status in ("completed", "failed", "terminal"):             return {                 "task_id": task_id,                 "messages": messages,                 "status": status,                 "final_response": st.get("final_response"),             } if name == "main":     run = spawn(TOOL_REPORT_PROMPT)     print(f"task {run['task_id']} -> {run['status']} ({len(run['messages'])} snapshots)")     print("=" * 60)     print(run["final_response"] or "(empty final response)")
task bd3e35de-d7d7-482c-b0cc-e301ff6e67a3 -> completed (1 snapshots) ============================================================ Every tool function available to me, enumerated without calling any tools. Two lists: (1) functions whose full names I know from context and can call directly; (2) namespaces whose functions are deferred — their exact function names are hidden from me, and loading them would require a tool call, which this task forbids. List 1 — fully specified functions (namespace.function): muse.create_options muse.db muse.edit muse.exec muse.memory_get muse.memory_search muse.read muse.session_status muse.skill_search muse.visual_grounding muse.write process.clear process.kill process.list process.log process.poll process.send_keys process.write subagent.spawn subagent.list subagent.send subagent.resume subagent.close tool_search.load_tool_namespace widget.create widget.present widget.state browser.find browser.lookup_citation_url browser.open browser.search artifact.list_actions artifact.invoke_action avatar.create avatar.edit avatar.get avatar.set social.search tracking.set_status
List 2 — namespaces with additional deferred functions whose names are not visible without a load call (forbidden here), so they cannot be enumerated exactly: artifact (functions beyond list_actions and invoke_action) avatar (functions beyond create, edit, get, set) browser (functions beyond find, lookup_citation_url, open, search) chat (all deferred) cron (all deferred) device (all deferred) hooks (all deferred) idea (all deferred) map (all deferred) media (all deferred) social (functions beyond search) tracking (functions beyond set_status) ui (all deferred) user_goal (all deferred) workflow (all deferred) Assumption: function names were taken only from my present context (tool descriptions and schema listings); no namespace was loaded to enumerate hidden names, per the no-tool-call instruction. DONE