Files
semif-agent/semif_agent/trace.py
T
gabby ab0defca1e chain multi-step requests across known skills
Add the run-ledger chained-run path and make a compound request run its
known skills in order instead of authoring one monolithic skill.

- scheduler/skill: `assess:outcome` gains a `continue` verdict; a continued
  step is re-dispatched with a bounded run ledger (max_reentries + a
  monotonic-progress guard), and the ledger is rendered into the routing and
  assessment state.
- navigation leaf guard (`confirm_skill_fit`) becomes same/part/different and
  is ledger-aware, so the first step of a compound request runs instead of
  being rejected into `create_skill` (a real run picked calculator.calculate
  at 0.99 and was rejected into create_skill).
- results flow forward through `request.run_ledger` (`last_result` helper);
  `simplex.send_message` sends the prior step's result rather than asking the
  LLM bridge to recompute it. Documented in CODEGEN.md.
- `assess:outcome` stays the sole continuation authority: the guard only
  decides whether a skill contributes, never forces a continuation (a forced
  continue on `part` overrode a correct `done` on the final step and authored
  a spurious category).
- verbosity levels, structured SchedulerReply fields, and a send_message
  hermetic test for the chained-result path.
2026-10-10 07:25:17 +00:00

46 lines
1.7 KiB
Python

"""Run lifecycle tracing: the events around each request's trip through the
scheduler.
Decision rows live in `decisions.jsonl` (SemIf-compatible). Lifecycle events
(submit, dropped, queued, dequeued, assessed, continued, ...) live here in
`runs.jsonl`, keyed by `run_id` (the request id) so the dashboard can rebuild
each run's flow without touching the decision-log contract. Both files are
append-only; replays read them in order.
"""
from __future__ import annotations
import json
import time
from pathlib import Path
class TraceLog:
def __init__(self, path: str = "data/runs.jsonl"):
self.path = Path(path)
def append(self, kind: str, run_id: str, ts: float | None = None, **fields) -> None:
# `ts` lets a caller record the moment an event *happened* (e.g. the last
# speech frame of an utterance) rather than when the row was written.
row = {"kind": kind, "run_id": run_id, "ts": time.time() if ts is None else ts, **fields}
self.path.parent.mkdir(parents=True, exist_ok=True)
with self.path.open("a") as handle:
handle.write(json.dumps(row) + "\n")
def read(self) -> list[dict]:
if not self.path.is_file():
return []
rows = []
with self.path.open("r") as handle:
for line in handle:
line = line.strip()
if line:
rows.append(json.loads(line))
return rows
def runs(self) -> dict[str, list[dict]]:
"""Group events by run_id, preserving insertion order of first sighting."""
grouped: dict[str, list[dict]] = {}
for row in self.read():
grouped.setdefault(row.get("run_id", ""), []).append(row)
return grouped