diff --git a/CODEGEN.md b/CODEGEN.md index ea59f2e..663d047 100644 --- a/CODEGEN.md +++ b/CODEGEN.md @@ -9,12 +9,12 @@ contract, `TESTGEN.md`. This file is about the runnable body only. ## What a skill is Semif-agent is an end-user application: an everyday person asks it to do a task, -and it does that task using a combination of user-provided data and a catalog of basic services known as bridges. A skill is the thing that performs one of those tasks: it is the leaf in the skill tree that the agent navigates to when it has resolved a request to a single, concrete action. Navigation is performed by an llm-based classification engine known as SemIf. +and it does that task using a combination of native python modules, user-provided data and a catalog of basic services known as bridges. A skill is the thing that performs one of those tasks: it is the leaf in the skill tree that the agent navigates to when it has resolved a request to a single, concrete action. Navigation is performed by an llm-based decision engine known as SemIf. A skill is three things: -1. **A manifest** — the registry entry that makes it navigable and describes - what it does. +1. **A registry entry** — its navigable `name` + `description`, recorded in + `data/categories.json` and mirrored in the running tree. 2. **A code body** — a runnable Python module implementing a single `act` phase against a real service. 3. **A declaration** — the `INTEGRATION` constant (which real system the body @@ -50,7 +50,10 @@ It performs one forward pass and reads the probabilities of the declared answer tokens directly. It returns a probability for each option — no sentence, no JSON, no decoding loop, nothing to parse. In effect it is a semantic `if`: software asks a yes/no/which question in natural language and gets back a typed, -thresholdable number. The `state` may also be a nonempty JSON object or array. +thresholdable number. In this agent the `state` is always a string +(`request.text`, or the query plus a list of candidates); the broader SemIf +project also accepts a nonempty JSON object or array as state, but a body here +must pass a string. The whole point is that the **question and options arrive with the request**. Routing, selection, and assessment are not baked into the model or the prompt; @@ -66,7 +69,7 @@ code. ### SemIf's feature set -SemIf () is a broader project than +SemIf () is a broader project than the one call this agent makes. Its full feature set: - **Runtime-defined decisions** — state, criterion, and option descriptions are @@ -161,33 +164,48 @@ Rules: the skill's confidence threshold, otherwise fall back to the configured default (see `calendar.create_event` and `simplex.next_message`). - **Use the LLM bridge for text, not for routing or assessment.** Generated text - goes through the LLM bridge (`llm_bridge_url`, `llm_bridge_token`) — a generic - `POST /chat` — never by speaking a model's protocol directly. Keep the model - extractive and bounded (see how `calendar.create_event` asks only for a title - and description), and report a real failure when the bridge is down rather than - guessing the text. + goes through the LLM bridge — a generic `POST /chat` whose base URL, token, + and endpoint shapes are in the bridge catalog injected below — never by + speaking a model's protocol directly. Keep the model extractive and bounded + (see how `calendar.create_event` asks only for a title and description), and + report a real failure when the bridge is down rather than guessing the text. - **Never blur the boundaries.** SemIf never generates; an LLM never routes, selects, or assesses; deterministic code never invents a value it cannot observe. A request input is resolved by SemIf, not by substring matching by hand; a title is generated by the LLM, not assembled by string concatenation when it should be written; a date is parsed by code, not asked of a model. -## Manifest schema +## The registry entry -Registered in `data/categories.json` (and mirrored in the running tree). Fields: +The body writer does **not** author a manifest. The `llm` provider authors the +leaf's `name` and `description`, and the scheduler records them in +`data/categories.json` (mirrored in the running tree). You are told the chosen +`name` and `description` in the prompt; use them, and never invent or rename the +skill. -| Field | Meaning | -| -------------------- | -------------------------------------------------------------------- | -| `name` | `category.skill` dotted snake_case id. Lowercase letters, digits, `_` and `.` only (`[a-z0-9_]+(?:\.[a-z0-9_]+)*`). Single purpose. | -| `category` | The top-level category bucket the skill lives under. | -| `description` | One to two sentences: what the skill does, for navigation. | -| `allowed_inputs` | What the skill accepts / needs as input context. | -| `actions` | The concrete actions the skill takes. | -| `cost_budget` | Relative budget for one run; a run that exceeds it fails fast. | -| `decision_log_ref` | Reference to the decision rows this skill logged during a run. | +The registry is a map of category -> bucket: -Only `name` and `description` are required for a stub; the rest fill in as the -skill is exercised. +```json +{ + "": { + "description": "", + "skills": [ + { + "name": "", + "description": "", + "request_text": "", + "requirements": {"": ""} + } + ] + } +} +``` + +- A leaf `name` is a single snake_case token (`[a-z0-9_]+(?:\.[a-z0-9_]+)*`), + not dotted with the category; the category is the key it lives under, and the + runner joins them as `category.name` only when it builds the run summary. +- `request_text` and `requirements` are recorded by the scheduler so a stub can + be re-driven later; the body never sets them. ## Code body contract @@ -261,8 +279,12 @@ def act(ctx, request) -> ActionResult: """Perform the real action and return the result + new state.""" ``` -- `ctx` is an `ActionContext` with `ctx.engine` (the real SemIf engine) and - `ctx.config` (the resolved values for this skill, including its own config). +- `ctx` is an `ActionContext` with `ctx.engine` (the real SemIf engine), + `ctx.config` (the resolved values for this skill, including its own config), + and `ctx.timers` (the in-process timer/alarm service — use it to schedule a + notification, as the `time.set_timer` and `time.set_alarm` seeds do). + `ctx.admin` exists for the built-in housekeeping meta skills only; an ordinary + body must never touch it. - `request` is the `Request` being handled. - `ActionResult(action_log: str, new_state: str, needs_input: str | None = None, decisions: list = [])` is imported from `semif_agent.skills`; return that exact @@ -363,8 +385,10 @@ INTEGRATION = { (`http|caldav|imap|smtp|pop|subprocess|file|compute`). `compute` is only for skills that perform no external action at all (pure analysis/formatting); an action skill must not use it. -- `config_vars` — the `ctx.config` keys the body reads for this integration. - Empty list allowed for `compute`. +- `config_vars` — the `ctx.config` keys the body reads for this integration. In + the committed seeds this is exactly the body's `CONTRACT` key set; an empty + list is allowed for `compute`. Declaring a variable the body never reads is a + mismatch the fidelity check flags. The auto-run test is a hermetic mechanics check and never exercises the live service, so this declaration is how the agent knows what the skill was built to @@ -488,10 +512,14 @@ Rules: pause the human's answer arrives on `request.user_input` and `act` is invoked again from the beginning — re-derive the query and config, consume `request.user_input`, and do not re-ask a question you already have an answer - for. + for. `request.meta` is a scratch dict carried on the same request across the + pause, so a body can cache a computed value or an already-collected answer + there and reuse it on the resume pass instead of recomputing or re-asking — + see how `calendar.create_event` caches the extracted title/description and the + answers it collected. - **Fail fast on budget.** Keep the work small; do not loop or retry in code. -- **Names match the manifest.** The module is imported as its manifest name; - the function is `act` exactly. +- **The function is `act` exactly.** The module is imported under its registered + leaf name; the entry point is a module-level `act(ctx, request)`. ## Bridge services @@ -562,11 +590,12 @@ Rules: A generated skill is accepted only if: -1. It compiles (`compile(..., "exec")` succeeds), imports every name it uses - (`ActionResult` from `semif_agent.skills`; `DecisionRequest`/`Option` from - `semif_agent.decisions` only when it actually builds a sub-decision; each - stdlib module it calls — no `NameError` at run time), and defines `act`. -2. Its `name` matches the manifest regex and its `category` is given. +1. It parses as Python (`ast.parse` succeeds), defines a module-level `act` + function, and imports every name it uses (`ActionResult` from + `semif_agent.skills`; `DecisionRequest`/`Option` from `semif_agent.decisions` + only when it actually builds a sub-decision; each stdlib module it calls — no + `NameError` at run time). +2. Its `name` matches the leaf-name regex and its `category` is given. 3. Its body imports nothing outside the stdlib and the agent package. 4. It uses `ctx.engine` (never mocks) and returns proper `ActionResult` types. 5. It is single-purpose and does not duplicate an existing category leaf. @@ -590,3 +619,11 @@ A generated skill is accepted only if: 13. If it is a messaging skill, it uses a bridge service over HTTP (never a service's native protocol), resolves recipients with a SemIf sub-decision, and sends only on explicit user intent. + +Items 1 and 7 are hard checks in the parser (`parse_skill_body`) and reject the +body outright. The rest are not statically rejected: a missing or inconsistent +`INTEGRATION` (#11) is inferred and the body is accepted badged `unverified`, a +third-party import (#3) only fails when the module is actually imported, and +import-time work (#12) only shows up when it runs. The fidelity gate rewrites a +body once for these, then accepts it — so treat every item as required, not +optional. diff --git a/README.md b/README.md index 600ca61..de7bcab 100644 --- a/README.md +++ b/README.md @@ -744,8 +744,8 @@ rows. A skill is one specific, single-purpose action reachable by category → skill navigation. It is three things: -1. a **manifest** (navigable description — `name`, `category`, `description`, - plus optional `allowed_inputs`, `actions`, `cost_budget`, `decision_log_ref`); +1. a **registry entry** (navigable description — `name` + `description`, + authored by the small `llm` provider and recorded in `data/categories.json`); 2. a **code body** (a single `act`); 3. an **`INTEGRATION` declaration** (service / transport / config_vars) and a flat **`CONTRACT`** (the operational values the runner must provide). diff --git a/TESTGEN.md b/TESTGEN.md index 6bf3a9b..95db1d2 100644 --- a/TESTGEN.md +++ b/TESTGEN.md @@ -3,8 +3,8 @@ This file is the authoritative spec for the **testing** side of a skill. It is fed verbatim (alongside the finished `skill.py`) to the model that produces the test artifact. The runnable body contract lives in `CODEGEN.md`; this file is -deliberately separate so the body writer never embeds test data and the test -writer never worries about body semantics. +deliberately separate so the body writer never embeds test data and the test is +generated from the finished body rather than the other way around. A finished skill leaf is a folder `data/skills///` containing (among others) two artifacts: @@ -33,8 +33,9 @@ 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 -`CODEGEN.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. +`CODEGEN.md`); `contract.json` is a persisted mirror of it, and the same +contract object is handed to you as context. You do not author or change the +contract. This contract exists for exactly two consumers: @@ -99,10 +100,14 @@ A stdlib-only Python script that: The test artifact is accepted only if: -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 +1. `skill.test.py` parses as Python — the only static check — and runs to exit 0 + when executed from the skill folder; on failure the captured output drives a + regeneration. +2. It imports only the stdlib and the agent package, embeds its fixtures inline + (no external files), and is hermetic (no external network, no real services). + These are required of every test but are **not** statically verified, so do + not rely on a checker to catch a violation. +3. The test stays compatible with the body's `CONTRACT` (the same variable names the body reads from `ctx.config`). Produce one artifact: `skill.test.py` (derived from `skill.py` plus its diff --git a/tests/test_codegen.py b/tests/test_codegen.py index 841420b..d33d81b 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -146,6 +146,24 @@ def test_contract_directs_request_arguments_and_output(): assert "No work at import time" in text +def test_skill_contract_documents_runtime_surface(): + """CODEGEN.md must document the ActionContext surface a body can rely on + (ctx.timers for scheduling) and the request.meta resume cache — both are + used by the authoritative seed set, so a body writer needs them.""" + text = read_skill_contract() + assert "ctx.timers" in text + assert "request.meta" in text + + +def test_skill_contract_has_no_stale_manifest_fields(): + """The old manifest schema (allowed_inputs/actions/cost_budget/ + decision_log_ref, a dotted leaf name) described fields the registry never + had; keep it out of the body contract.""" + text = read_skill_contract() + for stale in ("allowed_inputs", "decision_log_ref", "cost_budget", "Manifest schema"): + assert stale not in text + + def test_body_directives_require_query_arguments_and_output(): """The prompt directives (used by the first, retry, and regen prompts) must echo the query->arguments and real-output requirements, not just CODEGEN.md."""