Remove the predict phase; contract-driven resolution
Skills now have a single `act(ctx, request)` body phase. The free-string `Prediction.text` handoff, the `Prediction` type, and the predict phase are gone. - Resolution is pipeline-owned: the tiered config merge (global -> category -> skill) fills contract vars; the authoring-time SemIf search now searches the whole cascade; unresolved vars pause pre-act (`pre_act`, renamed from `pre_predict`) and are asked of the human one at a time. - The data contract is a module-level `CONTRACT` constant in the body, parsed by `parse_contract`; `contract.json` is a derived mirror. The separate `generate_data_contract` codegen call is removed. - Candidate selection stays in the body: a set of candidates (bridge endpoint, direct API, hard-coded list) gets a SemIf query, and the decisions ride back on `ActionResult.decisions` to be logged with the run outcome (phase `act`). - `assess:outcome`/`assess:requeue` state carries the resolved inputs (secrets redacted by name) so the decision sees the full query -> resolution -> action path. - Authoring validation enforces: compiles + `act`; `INTEGRATION` flat and valid; `CONTRACT` flat str->str; every CONTRACT key actually read from `ctx.config`. - Test-regen ladder narrowed to code/test (the contract rides in the code). SKILL.md/TESTGEN.md rewritten; seeds (calendar.next_event, simplex.next_message, simplex.connect_link) rewritten to act-only + CONTRACT; docs updated. BREAKING: persisted bodies in data/skills/ must be regenerated.
This commit is contained in:
1 parent
4a62e794a5
commit
567c280ee2
26 files changed
+679
-706
No files matched your search
@@ -17,7 +17,7 @@ import json
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from semif_agent.skills import ActionResult, Prediction
|
||||
from semif_agent.skills import ActionResult
|
||||
|
||||
INTEGRATION = {
|
||||
"service": "simplex",
|
||||
@@ -25,6 +25,11 @@ INTEGRATION = {
|
||||
"config_vars": ["simplex_bridge_url", "simplex_bridge_token"],
|
||||
}
|
||||
|
||||
CONTRACT = {
|
||||
"simplex_bridge_url": "Base URL of the standalone SimpleX forwarding bridge, e.g. http://127.0.0.1:5227 (no trailing slash needed).",
|
||||
"simplex_bridge_token": "Shared secret for the bridge, if one is configured; sent as the X-Semif-Token header. Leave blank when the bridge requires no auth.",
|
||||
}
|
||||
|
||||
TIMEOUT_SECONDS = 30
|
||||
|
||||
|
||||
@@ -58,20 +63,18 @@ def _get(ctx, path):
|
||||
raise BridgeError(f"GET {path}: {exc}") from exc
|
||||
|
||||
|
||||
def predict(ctx, request):
|
||||
def act(ctx, request):
|
||||
try:
|
||||
payload = _get(ctx, "/health")
|
||||
except BridgeError as exc:
|
||||
return Prediction(text=f"bridge error: {exc}")
|
||||
return ActionResult(
|
||||
action_log=f"simplex.connect_link: {exc}", new_state=request.text
|
||||
)
|
||||
if not payload.get("ok"):
|
||||
return Prediction(text="bridge error: simplex forwarding bridge is not healthy")
|
||||
return Prediction(text="ready: simplex forwarding bridge reachable")
|
||||
|
||||
|
||||
def act(ctx, request, prediction):
|
||||
text = prediction.text if prediction else ""
|
||||
if text.startswith("bridge error:"):
|
||||
return ActionResult(action_log=text, new_state=request.text)
|
||||
return ActionResult(
|
||||
action_log="simplex.connect_link: simplex forwarding bridge is not healthy",
|
||||
new_state=request.text,
|
||||
)
|
||||
try:
|
||||
payload = _get(ctx, "/address")
|
||||
except BridgeError as exc:
|
||||
|
||||
@@ -76,8 +76,7 @@ def test_reports_existing_link():
|
||||
try:
|
||||
ctx = ActionContext(engine=None, config=config(url))
|
||||
request = Request("give me your simplex link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "simplex:/contact#abc" in action.action_log, action.action_log
|
||||
assert "https://smp/short" in action.action_log, action.action_log
|
||||
assert "current" in action.action_log, action.action_log
|
||||
@@ -95,8 +94,7 @@ def test_reports_freshly_created_link():
|
||||
try:
|
||||
ctx = ActionContext(engine=None, config=config(url))
|
||||
request = Request("create a simplex invitation link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "simplex:/contact#new" in action.action_log, action.action_log
|
||||
assert "created" in action.action_log, action.action_log
|
||||
print(action.action_log)
|
||||
@@ -110,8 +108,7 @@ def test_no_provider_is_reported_honestly():
|
||||
try:
|
||||
ctx = ActionContext(engine=None, config=config(url))
|
||||
request = Request("give me your simplex link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "503" in action.action_log, action.action_log
|
||||
assert action.new_state == request.text, "a failed lookup must not fake a result"
|
||||
print(action.action_log)
|
||||
@@ -125,8 +122,7 @@ def test_empty_link_is_reported_honestly():
|
||||
try:
|
||||
ctx = ActionContext(engine=None, config=config(url))
|
||||
request = Request("give me your simplex link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "no SimpleX" in action.action_log, action.action_log
|
||||
assert action.new_state == request.text
|
||||
print(action.action_log)
|
||||
@@ -138,10 +134,8 @@ def test_empty_link_is_reported_honestly():
|
||||
def test_unreachable_bridge_fails_honestly():
|
||||
ctx = ActionContext(engine=None, config=config("http://127.0.0.1:1"))
|
||||
request = Request("give me your simplex link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
assert prediction.text.startswith("bridge error:"), prediction.text
|
||||
action = skill.act(ctx, request, prediction)
|
||||
assert action.action_log.startswith("bridge error:"), action.action_log
|
||||
action = skill.act(ctx, request)
|
||||
assert action.action_log.startswith("simplex.connect_link:"), action.action_log
|
||||
assert action.new_state == request.text
|
||||
print(action.action_log)
|
||||
|
||||
@@ -153,8 +147,7 @@ def test_auth_token_is_sent_when_configured():
|
||||
try:
|
||||
ctx = ActionContext(engine=None, config=config(url, token="sekret"))
|
||||
request = Request("give me your simplex link")
|
||||
prediction = skill.predict(ctx, request)
|
||||
action = skill.act(ctx, request, prediction)
|
||||
action = skill.act(ctx, request)
|
||||
assert "simplex:/contact#abc" in action.action_log, action.action_log
|
||||
assert set(handler.tokens) == {"sekret"}, handler.tokens
|
||||
print(action.action_log)
|
||||
|
||||
Reference in new issue
Block a user