feat(kpi): expand KPI runtime monitoring, prompt advisory envelopes, and missing field resiliency
This commit is contained in:
+19
-12
@@ -68,6 +68,7 @@ def _tool(op, args):
|
||||
def spawn_call(job_id, job_name, profile):
|
||||
count, _, hint = PROFILES[profile]
|
||||
task = "Subagent for job %s (%s): %s." % (job_id, job_name, hint)
|
||||
return _tool("swarm.spawn", {"count": count, "task": task[:900], "label": (job_name or "job")[:60]})
|
||||
|
||||
|
||||
def dm_call(to, target, message):
|
||||
@@ -76,9 +77,6 @@ def dm_call(to, target, message):
|
||||
separators=(", ", ": "))
|
||||
|
||||
|
||||
return _tool("swarm.spawn", {"count": count, "task": task[:900], "label": (job_name or "job")[:60]})
|
||||
|
||||
|
||||
def native_followup_call(job_id, job_name, profile, agent):
|
||||
"""Muse-native one-shot cron (cron.create runonce) - bridged to followup.create."""
|
||||
_, mins, _ = PROFILES[profile]
|
||||
@@ -99,7 +97,7 @@ def thread_url(target):
|
||||
return "https://box.muse-dev.online/%s/%s" % ("thread" if UUID_RE.fullmatch(t.lower()) else "sidechat", t)
|
||||
|
||||
|
||||
def wrap(job_name, job_id, agent, target, rendered):
|
||||
def wrap(job_name, job_id, agent, target, rendered, include_kpi: bool = True):
|
||||
"""Return the full DM body as a direct, authentic operator directive."""
|
||||
profile = pick_profile(job_name)
|
||||
spawn = spawn_call(job_id, job_name, profile)
|
||||
@@ -107,24 +105,33 @@ def wrap(job_name, job_id, agent, target, rendered):
|
||||
parts = job_id.split("-")
|
||||
wo_id = parts[-1] if len(parts) > 1 and len(parts[-1]) >= 8 else hashlib.sha256(job_id.encode()).hexdigest()[:8]
|
||||
session_name = f"work-{agent}-{wo_id}"
|
||||
tmux_new = _tool("tmux.new", {"session": session_name, "command": "bash"})
|
||||
tmux_send = _tool("tmux.send", {"session": session_name, "keys": "echo 'Starting task execution...'"})
|
||||
|
||||
advisory_section = ""
|
||||
if include_kpi:
|
||||
try:
|
||||
import kpi
|
||||
advisory = kpi.get_live_advisory_block(agent)
|
||||
if advisory:
|
||||
advisory_section = f"\n{advisory}\n"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
top = (
|
||||
f"Operator Directive [ref:{wo_id}]:\n"
|
||||
"Execute the task below using tool calls. Background tmux session is ready for command execution:\n"
|
||||
f" • {tmux_new}\n"
|
||||
f" • {tmux_send}\n"
|
||||
f"Host tmux worker session '{session_name}' is available on bl (/tmp/tmux-muse.sock).\n"
|
||||
f" • Subagent assistance: {spawn}\n"
|
||||
f" • Verification schedule: {follow}\n\n"
|
||||
f" • Verification schedule: {follow}\n"
|
||||
f"{advisory_section}\n"
|
||||
"--- Task ---\n"
|
||||
)
|
||||
|
||||
has_result = "[RESULT" in rendered
|
||||
bottom = (
|
||||
"\n--- End Task ---\n\n"
|
||||
f"Inspect tmux output: [TOOL tmux.capture {{\"session\": \"{session_name}\", \"lines\": 30}}]\n"
|
||||
f"Inspect tmux worker: box tmux capture {session_name} 30 (or attach via /tmp/tmux-muse.sock)\n"
|
||||
"Tools: cron.create, cron.runs, health.check, swarm.spawn, swarm.list, dm.send, box.exec, tools.list.\n"
|
||||
"Message a peer: [DM {\"to\": \"<agent>\", \"target\": \"<sidechat>\", \"message\": \"<text>\"}].\n"
|
||||
"Query box: [TOOL box.exec {\"action\": \"<fleet-status|dm-log|job-get|...>\"}] \u2014 [TOOL tools.list {}] lists every op.\n"
|
||||
"Query box: [TOOL box.exec {\"action\": \"<fleet-status|dm-log|job-get|...>\"}] — [TOOL tools.list {}] lists every op.\n"
|
||||
)
|
||||
if not has_result:
|
||||
bottom += f"When complete, report your verdict: [RESULT {job_id}] OK: <summary of actions>\n"
|
||||
|
||||
Reference in New Issue
Block a user