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.
This commit is contained in:
1 parent
9ba14fdab0
commit
ab0defca1e
20 files changed
+1046
-324
No files matched your search
+95
-85
@@ -7,11 +7,13 @@ the human for anything unresolved), performs the real action, and returns an
|
||||
`ActionResult.decisions` and are logged by the runner with the run outcome.
|
||||
|
||||
Assessment is a SemIf decision, not generation: `assess:outcome` decides
|
||||
success/failure (P(success) >= tau) and, on failure, `assess:requeue` decides
|
||||
complete/retry. The run summary is deterministic — same inputs, same string —
|
||||
built from the category, skill, outcome flag, and action log. Every SemIf
|
||||
decision made during a run is logged as a training row; the assessment outcome
|
||||
is kept on the row so the dream pass can weigh failed runs.
|
||||
whether there is any additional work to do — `done` (request satisfied),
|
||||
`continue` (the step worked but more work is needed; the scheduler routes the
|
||||
next step), or `failed` (the step errored → the repair path). The run summary is
|
||||
deterministic — same inputs, same string — built from the category, skill,
|
||||
outcome flag, and action log. Every SemIf decision made during a run is logged as
|
||||
a training row; the assessment outcome is kept on the row so the dream pass can
|
||||
weigh failed runs.
|
||||
|
||||
A skill with a data contract may need variables collected from the human before
|
||||
it runs. Those are asked pre-act, runner-driven: `run` resolves the tiered
|
||||
@@ -35,6 +37,8 @@ from .skills import (
|
||||
ActionContext,
|
||||
Skill,
|
||||
SkillStore,
|
||||
bound_output,
|
||||
render_ledger,
|
||||
resolve_skill_config,
|
||||
unresolved_variables,
|
||||
)
|
||||
@@ -87,7 +91,12 @@ class RunResult:
|
||||
summary: str
|
||||
action_log: str
|
||||
new_state: str
|
||||
updated_request: str | None = None
|
||||
#: The three-way outcome for a chained run: "done" (request satisfied),
|
||||
#: "continue" (the step worked but more work is needed → the scheduler routes
|
||||
#: the next step), or "failed" (the step errored → the repair path). None
|
||||
#: only for a pause for input (needs_input/error), which never reaches the
|
||||
#: outcome branch.
|
||||
outcome: str | None = None
|
||||
decisions_logged: int = 0
|
||||
assessment_summary: str = ""
|
||||
error: str | None = None
|
||||
@@ -102,11 +111,25 @@ class SkillRunner:
|
||||
log: DecisionLog,
|
||||
store: SkillStore | None = None,
|
||||
tau: float = 0.6,
|
||||
done_tau: float = 0.5,
|
||||
fail_tau: float = 0.5,
|
||||
result_chars: int = 300,
|
||||
):
|
||||
self.ctx = ctx
|
||||
self.log = log
|
||||
self.store = store
|
||||
self.tau = tau
|
||||
#: Thresholds for the three-way `assess:outcome` decision. Precedence is
|
||||
#: failed > done > continue: a step is only declared "continue" when the
|
||||
#: model is genuinely unsure, so a confident success/failure is honored
|
||||
#: and the chain is not entered needlessly.
|
||||
self.done_tau = done_tau
|
||||
self.fail_tau = fail_tau
|
||||
#: The shared speakable budget: every skill's action_log/new_state is
|
||||
#: truncated to this many characters (the same bound the voice front end
|
||||
#: and the humanizer use), so a result fits one message / ~20s of speech
|
||||
#: and the run ledger stays bounded.
|
||||
self.result_chars = result_chars
|
||||
|
||||
# ---- contract resolution ----
|
||||
|
||||
@@ -288,111 +311,98 @@ class SkillRunner:
|
||||
|
||||
def _assess(
|
||||
self, skill: Skill, request: Request, ctx: ActionContext, action
|
||||
) -> tuple[bool, str | None]:
|
||||
"""SemIf assessment: did the run succeed, and should it run again?
|
||||
) -> str:
|
||||
"""SemIf assessment: is there any *additional work* to be done?
|
||||
|
||||
`assess:outcome` decides success (`P(success) >= tau`); a failure is
|
||||
then offered to `assess:requeue`, which picks complete/retry. On retry
|
||||
the original request text is re-dispatched (the scheduler bounds it by
|
||||
`max_reentries`). Both are real logged decision rows. The state carries
|
||||
the skill's declared action, the goal, and the resolved inputs so the
|
||||
decision sees what the skill was meant to do and how its inputs
|
||||
resolved; the requeue state additionally flags a retry that would
|
||||
reproduce the identical observed result as a no-op. The engine is always
|
||||
real: EngineUnavailable propagates to the scheduler, which marks the app
|
||||
fatal.
|
||||
A single three-way `assess:outcome` decision over the step's own action
|
||||
plus the run ledger so far:
|
||||
|
||||
- ``done`` — the request is satisfied (a definitive "nothing found"
|
||||
counts as done);
|
||||
- ``continue`` — the step worked, but the request is not yet satisfied;
|
||||
the scheduler routes the next step (bounded by ``max_reentries`` and
|
||||
the monotonic-progress guard);
|
||||
- ``failed`` — the step errored / did not work → the repair path.
|
||||
|
||||
The verdict uses thresholds, not argmax, with precedence
|
||||
``failed > done > continue`` (``fail_tau`` then ``done_tau``), so a
|
||||
confident success/failure is honored and ``continue`` — the over-trigger
|
||||
— only wins when the model is genuinely unsure. Real logged decision row
|
||||
(phase `assess:outcome`). The state carries the skill's declared action,
|
||||
the goal, the resolved inputs, the (bounded) action log, and the steps
|
||||
already taken. The engine is always real: EngineUnavailable propagates to
|
||||
the scheduler, which marks the app fatal.
|
||||
"""
|
||||
label = f"{skill.category}.{skill.name}"
|
||||
resolved = _resolved_inputs(skill, ctx.config)
|
||||
outcome = DecisionRequest(
|
||||
state=(
|
||||
f"skill: {label}\n"
|
||||
f"skill action: {skill.description}\n"
|
||||
f"goal: {request.text}\n"
|
||||
f"resolved inputs:\n{resolved}\n"
|
||||
f"action log:\n{action.action_log}"
|
||||
),
|
||||
question="Did the skill achieve the user's goal?",
|
||||
observed = bound_output(action.action_log, self.result_chars)
|
||||
if not observed:
|
||||
observed = bound_output(action.new_state, self.result_chars)
|
||||
state = (
|
||||
f"skill: {label}\n"
|
||||
f"skill action: {skill.description}\n"
|
||||
f"goal: {request.text}\n"
|
||||
f"resolved inputs:\n{resolved}\n"
|
||||
f"action log:\n{observed}"
|
||||
)
|
||||
ledger = render_ledger(request.run_ledger)
|
||||
if ledger:
|
||||
state += f"\nsteps already taken:\n{ledger}"
|
||||
decision = DecisionRequest(
|
||||
state=state,
|
||||
question="Is there any additional work to be done to satisfy the request?",
|
||||
options=[
|
||||
Option(
|
||||
"success",
|
||||
"Yes — the skill carried out the request and produced a "
|
||||
"truthful result. A definitive 'nothing found' or 'nothing "
|
||||
"to do' result (empty inbox, no unread messages, no "
|
||||
"matching event) counts as success.",
|
||||
"done",
|
||||
"No — the request is satisfied. A definitive 'nothing found' "
|
||||
"or 'nothing to do' result (empty inbox, no unread messages, "
|
||||
"no matching event) counts as done.",
|
||||
),
|
||||
Option(
|
||||
"failure",
|
||||
"No — the request was not carried out, or the result is an "
|
||||
"error, a refusal, or an unresolved action.",
|
||||
"continue",
|
||||
"Yes — this step worked, but the request is not yet satisfied; "
|
||||
"another skill should run next toward the same request.",
|
||||
),
|
||||
Option(
|
||||
"failed",
|
||||
"The step did not work: the result is an error, a refusal, or "
|
||||
"an unresolved action.",
|
||||
),
|
||||
],
|
||||
)
|
||||
result = self.ctx.engine.call(outcome)
|
||||
result = self.ctx.engine.call(decision)
|
||||
self.log.append(
|
||||
outcome,
|
||||
decision,
|
||||
result,
|
||||
extra={"phase": "assess:outcome", "run_id": request.id, "skill": label},
|
||||
)
|
||||
success = result.prob("success") >= self.tau
|
||||
if success:
|
||||
return True, None
|
||||
|
||||
# A retry that would reproduce the identical observed result is a
|
||||
# guaranteed no-op run (the request, config, and external state are
|
||||
# unchanged), so the requeue decision is told before it can pick
|
||||
# `retry` again — otherwise a deterministic failure loops through the
|
||||
# reentry ladder and ends in a repair offer for a working skill.
|
||||
observed = action.action_log or action.new_state
|
||||
prev = request.meta.get("prev_result")
|
||||
no_progress = ""
|
||||
if prev is not None and prev == observed:
|
||||
no_progress = (
|
||||
"\nAttempts so far produced the identical result; retrying "
|
||||
"would repeat the same run against unchanged state."
|
||||
)
|
||||
requeue = DecisionRequest(
|
||||
state=(
|
||||
f"skill: {label}\n"
|
||||
f"skill action: {skill.description}\n"
|
||||
f"goal: {request.text}\n"
|
||||
f"resolved inputs:\n{resolved}\n"
|
||||
f"action log:\n{action.action_log}\n"
|
||||
"outcome: failed"
|
||||
f"{no_progress}"
|
||||
),
|
||||
question="Is the request complete, or should it run again?",
|
||||
options=[
|
||||
Option("complete", "It is complete; do nothing further."),
|
||||
Option("retry", "Run the original request again."),
|
||||
],
|
||||
)
|
||||
requeue_result = self.ctx.engine.call(requeue)
|
||||
self.log.append(
|
||||
requeue,
|
||||
requeue_result,
|
||||
extra={"phase": "assess:requeue", "run_id": request.id, "skill": label},
|
||||
)
|
||||
updated = request.text if requeue_result.prob("retry") >= self.tau else None
|
||||
return False, updated
|
||||
probs = result.probs
|
||||
if probs.get("failed", 0.0) >= self.fail_tau:
|
||||
return "failed"
|
||||
if probs.get("done", 0.0) >= self.done_tau:
|
||||
return "done"
|
||||
return "continue"
|
||||
|
||||
def _finish(
|
||||
self, skill: Skill, request: Request, ctx: ActionContext, action
|
||||
) -> RunResult:
|
||||
observed = action.new_state
|
||||
action_log = bound_output(action.action_log, self.result_chars)
|
||||
observed = bound_output(action.new_state, self.result_chars)
|
||||
if skill.category in CANNED_CATEGORIES or skill.category in DETERMINISTIC_CATEGORIES:
|
||||
summary = deterministic_summary(
|
||||
skill.category, skill.name, True, action.action_log, observed
|
||||
skill.category, skill.name, True, action_log, observed
|
||||
)
|
||||
return RunResult(
|
||||
skill=skill.name,
|
||||
success=True,
|
||||
summary=summary,
|
||||
action_log=action.action_log,
|
||||
action_log=action_log,
|
||||
new_state=observed,
|
||||
assessment_summary=summary,
|
||||
outcome="done",
|
||||
)
|
||||
success, updated_request = self._assess(skill, request, ctx, action)
|
||||
verdict = self._assess(skill, request, ctx, action)
|
||||
success = verdict != "failed"
|
||||
|
||||
decisions = getattr(action, "decisions", [])
|
||||
for decision, result in decisions:
|
||||
@@ -408,15 +418,15 @@ class SkillRunner:
|
||||
)
|
||||
|
||||
summary = deterministic_summary(
|
||||
skill.category, skill.name, success, action.action_log, observed
|
||||
skill.category, skill.name, success, action_log, observed
|
||||
)
|
||||
return RunResult(
|
||||
skill=skill.name,
|
||||
success=success,
|
||||
summary=summary,
|
||||
action_log=action.action_log,
|
||||
action_log=action_log,
|
||||
new_state=observed,
|
||||
updated_request=updated_request,
|
||||
outcome=verdict,
|
||||
decisions_logged=len(decisions),
|
||||
assessment_summary=summary,
|
||||
)
|
||||
Reference in new issue
Block a user