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:
gabby committed 2026-10-01 10:21:31 +00:00
1 parent 4a62e794a5
commit 567c280ee2
26 files changed
+679 -706

No files matched your search

+21 -22
View File
@@ -7,12 +7,11 @@ deliberately separate so the body writer never embeds test data and the test
writer never worries about body semantics.
A finished skill leaf is a folder
`data/skills/<category>/<name>/` containing (among others) two artifacts
produced here:
`data/skills/<category>/<name>/` containing (among others) two artifacts:
| File | Meaning |
| ----------------- | ------------------------------------------------------------------ |
| `contract.json` | The skill's data contract: what the runner must provide. |
| `contract.json` | A mirror of the body's `CONTRACT` constant: what the runner must provide. Derived from `skill.py`, not authored here. |
| `skill.test.py` | A hermetic mechanics test, runnable as `python skill.test.py`. |
## What the test is for (and is not)
@@ -33,6 +32,10 @@ A **single JSON object**. Each key is the name of a variable the skill needs;
each value is a plain-language, semantic description of the expected values for
that variable (what it is, what good values look like).
The body declares this itself as a module-level `CONTRACT` constant (see
`SKILL.md`); `contract.json` is a persisted mirror of it, provided to the test
writer as context. The test writer does not author or change the contract.
This contract exists for exactly two consumers:
1. **User input** — the config step asks the human for these variables when
@@ -54,10 +57,10 @@ Rules:
`ctx.config`.
- Each value is a non-empty string describing the expected values in plain
language (e.g. `"The email address the message is sent from."`).
- Derive the keys by reading the finished `skill.py`: every `ctx.config[...]`
access that carries operational data is a contract key. Do not invent keys
the body does not use.
- Do not include keys for purely internal/derived values.
- The keys are exactly the body's `CONTRACT` constant; every declared key is
read from `ctx.config`. Do not invent keys the body does not use.
- Optional values with safe defaults are read with `ctx.config.get(...)` and
are not contract keys.
## skill.test.py
@@ -83,10 +86,9 @@ A stdlib-only Python script that:
- For non-HTTP transports (IMAP, SMTP, subprocess, ...), exercise config
resolution, argument construction, and error paths (missing or misconfigured
values) without performing the real I/O.
- Exercises the skill's `predict` and `act` against those fixtures — call them
directly with a real-ish `ActionContext` (a fake `engine` is acceptable
**in the test only**; the test is the exception to the no-mocking rule for
the decision engine).
- Exercises the skill's `act` against those fixtures — call it directly with a
real-ish `ActionContext` (a fake `engine` is acceptable **in the test only**;
the test is the exception to the no-mocking rule for the decision engine).
- Exits 0 on success and non-zero on failure (use `assert`/`sys.exit(1)` with a
message). No third-party imports.
- Covers at least the happy path (through the loopback server where the body
@@ -97,16 +99,14 @@ A stdlib-only Python script that:
The test artifact is accepted only if:
1. `contract.json` is a single flat object of snake_case keys to semantic
descriptions, and every `ctx.config[...]` operational access in `skill.py`
has a matching key.
2. `skill.test.py` parses as Python, imports only the stdlib and the agent
1. `skill.test.py` parses as Python, imports only the stdlib and the agent
package, embeds its fixtures inline (no external files), is hermetic, and
runs to exit 0 when executed from the skill folder.
2. The test stays compatible with the body's `CONTRACT` (the same variable
names the body reads from `ctx.config`).
Produce the two artifacts in this order: first `contract.json` (derived from
`skill.py`), then `skill.test.py` (derived from the same `skill.py` plus the
contract, with fixture data embedded inline).
Produce one artifact: `skill.test.py` (derived from `skill.py` plus its
`CONTRACT`, with fixture data embedded inline).
## Worked example
@@ -119,7 +119,8 @@ machine:
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from semif_agent.skills import ActionContext, DecisionResult, Request
from semif_agent.decisions import DecisionResult, Request
from semif_agent.skills import ActionContext
class Handler(BaseHTTPRequestHandler):
@@ -155,9 +156,7 @@ def main():
ctx = ActionContext(engine=FakeEngine(), config={"service_url": url})
req = Request("check the service")
skill = __import__("skill")
pred = skill.predict(ctx, req)
assert pred.text, "predict must produce a forecast"
result = skill.act(ctx, req, pred)
result = skill.act(ctx, req)
assert result.action_log, "act must log what it did"
assert Handler.seen == ["/health"], f"body must really call the service: {Handler.seen}"
print(result.action_log)