add previous skill result to semif context for successive requeues
This commit is contained in:
1 parent
f05e06e6f6
commit
4e3e3f767c
5 files changed
+163
-4
No files matched your search
@@ -132,7 +132,9 @@ skill.py loop: observe -> act -> observe -> assess; the body is a single
|
|||||||
summary is deterministic (no generation), built from
|
summary is deterministic (no generation), built from
|
||||||
category.skill + ok/failed + action_log — the body writes only the
|
category.skill + ok/failed + action_log — the body writes only the
|
||||||
result, the runner adds the `category.name:` ref; the assess state carries
|
result, the runner adds the `category.name:` ref; the assess state carries
|
||||||
the resolved inputs (secrets redacted); a `DETERMINISTIC_CATEGORIES`
|
the skill's declared action, the goal, and the resolved inputs
|
||||||
|
(secrets redacted), and the requeue state flags a retry that would
|
||||||
|
reproduce the identical observed result as a no-op; a `DETERMINISTIC_CATEGORIES`
|
||||||
run (housekeeping) skips assessment/repair — it is an internal
|
run (housekeeping) skips assessment/repair — it is an internal
|
||||||
mechanical action with a known result, not an external run;
|
mechanical action with a known result, not an external run;
|
||||||
a run paused for input is resumed by re-invoking act with the
|
a run paused for input is resumed by re-invoking act with the
|
||||||
|
|||||||
@@ -713,6 +713,10 @@ class Scheduler:
|
|||||||
requeued = False
|
requeued = False
|
||||||
if outcome.updated_request and request.reentries < self.max_reentries:
|
if outcome.updated_request and request.reentries < self.max_reentries:
|
||||||
child = _requeue(request, outcome.updated_request)
|
child = _requeue(request, outcome.updated_request)
|
||||||
|
# Remember what this attempt observed so the next assessment can
|
||||||
|
# tell a genuine retry (the result changed) from a guaranteed
|
||||||
|
# repeat against unchanged state.
|
||||||
|
child.meta["prev_result"] = outcome.action_log or outcome.new_state
|
||||||
self.queue.push(child)
|
self.queue.push(child)
|
||||||
self.trace.append("requeued", request.id, text=outcome.updated_request)
|
self.trace.append("requeued", request.id, text=outcome.updated_request)
|
||||||
if self.on_request_requeued is not None:
|
if self.on_request_requeued is not None:
|
||||||
|
|||||||
+22
-3
@@ -295,15 +295,19 @@ class SkillRunner:
|
|||||||
then offered to `assess:requeue`, which picks complete/retry. On retry
|
then offered to `assess:requeue`, which picks complete/retry. On retry
|
||||||
the original request text is re-dispatched (the scheduler bounds it by
|
the original request text is re-dispatched (the scheduler bounds it by
|
||||||
`max_reentries`). Both are real logged decision rows. The state carries
|
`max_reentries`). Both are real logged decision rows. The state carries
|
||||||
the resolved inputs so a wrong resolution is visible to the decision.
|
the skill's declared action, the goal, and the resolved inputs so the
|
||||||
The engine is always real: EngineUnavailable propagates to the
|
decision sees what the skill was meant to do and how its inputs
|
||||||
scheduler, which marks the app fatal.
|
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.
|
||||||
"""
|
"""
|
||||||
label = f"{skill.category}.{skill.name}"
|
label = f"{skill.category}.{skill.name}"
|
||||||
resolved = _resolved_inputs(skill, ctx.config)
|
resolved = _resolved_inputs(skill, ctx.config)
|
||||||
outcome = DecisionRequest(
|
outcome = DecisionRequest(
|
||||||
state=(
|
state=(
|
||||||
f"skill: {label}\n"
|
f"skill: {label}\n"
|
||||||
|
f"skill action: {skill.description}\n"
|
||||||
f"goal: {request.text}\n"
|
f"goal: {request.text}\n"
|
||||||
f"resolved inputs:\n{resolved}\n"
|
f"resolved inputs:\n{resolved}\n"
|
||||||
f"action log:\n{action.action_log}"
|
f"action log:\n{action.action_log}"
|
||||||
@@ -334,13 +338,28 @@ class SkillRunner:
|
|||||||
if success:
|
if success:
|
||||||
return True, None
|
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(
|
requeue = DecisionRequest(
|
||||||
state=(
|
state=(
|
||||||
f"skill: {label}\n"
|
f"skill: {label}\n"
|
||||||
|
f"skill action: {skill.description}\n"
|
||||||
f"goal: {request.text}\n"
|
f"goal: {request.text}\n"
|
||||||
f"resolved inputs:\n{resolved}\n"
|
f"resolved inputs:\n{resolved}\n"
|
||||||
f"action log:\n{action.action_log}\n"
|
f"action log:\n{action.action_log}\n"
|
||||||
"outcome: failed"
|
"outcome: failed"
|
||||||
|
f"{no_progress}"
|
||||||
),
|
),
|
||||||
question="Is the request complete, or should it run again?",
|
question="Is the request complete, or should it run again?",
|
||||||
options=[
|
options=[
|
||||||
|
|||||||
@@ -728,3 +728,41 @@ def test_empty_result_is_assessed_as_success(tmp_path):
|
|||||||
assert "assess:requeue" not in phases, (
|
assert "assess:requeue" not in phases, (
|
||||||
"an empty discovery must not be retried or repaired"
|
"an empty discovery must not be retried or repaired"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_result_is_assessed_as_success(tmp_path):
|
||||||
|
"""A correctly-read result is a successful run, not a failure.
|
||||||
|
|
||||||
|
The assessment must see the skill's declared action; with only the skill
|
||||||
|
label the real model marked a truthful read failed for ambiguous phrasings
|
||||||
|
(e.g. "What's my next simplex message?"), which then looped the retry ladder
|
||||||
|
and offered to repair a working skill. This exercises the real engine, since
|
||||||
|
only it produces the probabilities.
|
||||||
|
"""
|
||||||
|
config = load_config()
|
||||||
|
require_real(config)
|
||||||
|
engine = SemIfEngine(build_engine_config(config))
|
||||||
|
|
||||||
|
def act(ctx, request):
|
||||||
|
return ActionResult(
|
||||||
|
action_log="SimpleX message from pepper: hello",
|
||||||
|
new_state="SimpleX message from pepper: hello",
|
||||||
|
)
|
||||||
|
|
||||||
|
skill = Skill(
|
||||||
|
name="next_message",
|
||||||
|
category="simplex",
|
||||||
|
description="Read the next unread SimpleX message.",
|
||||||
|
act=act,
|
||||||
|
)
|
||||||
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
|
runner = SkillRunner(ActionContext(engine=engine, config={}), log)
|
||||||
|
outcome = runner.run(skill, Request("What's my next simplex message?"))
|
||||||
|
print(f"[{outcome.success}] {outcome.summary}")
|
||||||
|
|
||||||
|
assert outcome.success is True, outcome.summary
|
||||||
|
phases = [row["extra"]["phase"] for row in log.read()]
|
||||||
|
assert "assess:outcome" in phases
|
||||||
|
assert "assess:requeue" not in phases, (
|
||||||
|
"a truthful read must not be retried or repaired"
|
||||||
|
)
|
||||||
@@ -612,6 +612,80 @@ def test_canned_response_runs_without_assessment(tmp_path):
|
|||||||
assert log.read() == []
|
assert log.read() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_assessment_state_carries_skill_action(tmp_path):
|
||||||
|
"""The assessment decision must see what the skill was meant to do.
|
||||||
|
|
||||||
|
Regression: with only `skill: <label>` in the state, the decision model
|
||||||
|
misfired on a correctly-read result for an ambiguous phrasing, marked a
|
||||||
|
truthful read failed, and looped the retry ladder until a repair offer. The
|
||||||
|
skill's declared action now rides in both assessment states.
|
||||||
|
"""
|
||||||
|
from semif_agent.skill import SkillRunner
|
||||||
|
from semif_agent.skills import ActionContext
|
||||||
|
|
||||||
|
engine = ScriptedEngine(
|
||||||
|
choices={"Did the skill achieve": "failure"}, default="success"
|
||||||
|
)
|
||||||
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
|
|
||||||
|
def act(ctx, request):
|
||||||
|
return ActionResult(action_log="SimpleX message from pepper: hello", new_state="read")
|
||||||
|
|
||||||
|
skill = Skill(
|
||||||
|
name="next_message",
|
||||||
|
category="simplex",
|
||||||
|
description="Read the next unread SimpleX message.",
|
||||||
|
act=act,
|
||||||
|
)
|
||||||
|
runner = SkillRunner(ActionContext(engine=engine, config={}), log)
|
||||||
|
runner.run(skill, Request("What's my next simplex message?"))
|
||||||
|
|
||||||
|
outcome_state = engine.calls[0].state
|
||||||
|
assert "skill action: Read the next unread SimpleX message." in outcome_state
|
||||||
|
assert "goal: What's my next simplex message?" in outcome_state
|
||||||
|
requeue_state = engine.calls[1].state
|
||||||
|
assert "skill action: Read the next unread SimpleX message." in requeue_state
|
||||||
|
|
||||||
|
|
||||||
|
def test_requeue_state_flags_identical_repeat(tmp_path):
|
||||||
|
"""A retry that would reproduce the identical result is flagged as a no-op
|
||||||
|
so the requeue decision can choose `complete` instead of looping."""
|
||||||
|
from semif_agent.skill import SkillRunner
|
||||||
|
from semif_agent.skills import ActionContext
|
||||||
|
|
||||||
|
engine = ScriptedEngine(
|
||||||
|
choices={"Did the skill achieve": "failure"}, default="success"
|
||||||
|
)
|
||||||
|
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||||
|
skill = Skill(
|
||||||
|
name="next_message",
|
||||||
|
category="simplex",
|
||||||
|
description="Read the next unread SimpleX message.",
|
||||||
|
act=lambda ctx, request: ActionResult(
|
||||||
|
action_log="SimpleX message from pepper: hello", new_state="read"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
runner = SkillRunner(ActionContext(engine=engine, config={}), log)
|
||||||
|
|
||||||
|
# First attempt: no prior result, so no no-progress note.
|
||||||
|
runner.run(skill, Request("What's my next simplex message?"))
|
||||||
|
assert "identical result" not in engine.calls[1].state
|
||||||
|
|
||||||
|
# Same observed result as the previous attempt: flagged as a no-op retry.
|
||||||
|
engine.calls.clear()
|
||||||
|
repeat = Request("What's my next simplex message?")
|
||||||
|
repeat.meta["prev_result"] = "SimpleX message from pepper: hello"
|
||||||
|
runner.run(skill, repeat)
|
||||||
|
assert "identical result" in engine.calls[1].state
|
||||||
|
|
||||||
|
# A changed result is progress: not flagged.
|
||||||
|
engine.calls.clear()
|
||||||
|
progress = Request("What's my next simplex message?")
|
||||||
|
progress.meta["prev_result"] = "a different previous result"
|
||||||
|
runner.run(skill, progress)
|
||||||
|
assert "identical result" not in engine.calls[1].state
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_navigate_leaf_picks_among_existing_skills_only(tmp_path):
|
def test_navigate_leaf_picks_among_existing_skills_only(tmp_path):
|
||||||
"""Two-stage leaf: create_skill is NOT an option in the leaf softmax. The
|
"""Two-stage leaf: create_skill is NOT an option in the leaf softmax. The
|
||||||
@@ -2027,3 +2101,25 @@ def test_exhausted_reentry_offers_repair(tmp_path):
|
|||||||
scheduler._finish_run(skill, request, outcome)
|
scheduler._finish_run(skill, request, outcome)
|
||||||
assert not any(e["kind"] == "requeued" for e in scheduler.trace.read())
|
assert not any(e["kind"] == "requeued" for e in scheduler.trace.read())
|
||||||
assert any(e["kind"] == "repair_offered" for e in scheduler.trace.read())
|
assert any(e["kind"] == "repair_offered" for e in scheduler.trace.read())
|
||||||
|
|
||||||
|
|
||||||
|
def test_requeue_remembers_previous_result(tmp_path):
|
||||||
|
"""A requeued retry carries the observed result forward so the next
|
||||||
|
assessment can detect a guaranteed no-op repeat."""
|
||||||
|
scheduler = _scheduler(tmp_path)
|
||||||
|
_install_tracking_stub(scheduler)
|
||||||
|
skill = scheduler.tree["tracking"][0]
|
||||||
|
request = Request("track my package")
|
||||||
|
outcome = RunResult(
|
||||||
|
skill="tracking.check",
|
||||||
|
success=False,
|
||||||
|
summary="failed",
|
||||||
|
action_log="connection refused",
|
||||||
|
new_state="unchanged",
|
||||||
|
updated_request="track my package",
|
||||||
|
)
|
||||||
|
scheduler._finish_run(skill, request, outcome)
|
||||||
|
child = scheduler.queue.pop()
|
||||||
|
assert child is not None
|
||||||
|
assert child.meta["prev_result"] == "connection refused"
|
||||||
|
assert any(e["kind"] == "requeued" for e in scheduler.trace.read())
|
||||||
Reference in new issue
Block a user