diff --git a/AGENTS.md b/AGENTS.md index 7306d28..5386258 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -422,7 +422,7 @@ WARN 100–200K, DUMB>200K), so limits are a total-context budget - Update `config.example.json` codegen block and the AGENTS.md codegen section with every new key from items 2, 4, 5. -- [ ] **9. Codegen prompt: code-for-reuse + self-generated mock data** +- [x] **9. Codegen prompt: code-for-reuse + self-generated mock data** (`codegen.py`, `SKILL.md`) - The generated body is meant to be REUSED across requests, so the prompt must tell the model to generate its own mock data (its own source of @@ -436,6 +436,15 @@ WARN 100–200K, DUMB>200K), so limits are a total-context budget internal/mock data model; ask the human only to disambiguate intent. - Test: prompt/`SKILL.md` contains the reuse + self-mock-data directives; a generated-body parse is unaffected. + - Implemented on the dev machine (2026-09-24): SKILL.md gained a hard rule + "Reusable module with its own data model" and the old "Request input when + data is missing" rule was reworded to "Request input for clarification + when requirements are unclear from the prompt" (intent only, never + operational data). Both codegen prompt builders (`build_skill_body_prompt` + and `_retry_prompt`) now add an explicit user-message line: the body is + reused across many requests; give the skill its own internal/mock data + model and ask only to clarify intent. Unit-tested (contract + both prompt + builders carry the directives; existing body-parse tests unaffected). ### Code principles - **No mocking.** The decision engine is always real SemIf; the LLM is always a diff --git a/SKILL.md b/SKILL.md index 38b6cbc..609ff36 100644 --- a/SKILL.md +++ b/SKILL.md @@ -72,13 +72,20 @@ def act(ctx, request, prediction) -> ActionResult: - **Never swallow the request.** If the skill cannot act, return an `ActionResult` with a short `action_log` explaining why and set `new_state` back to `request.text`. -- **Request input when data is missing.** If a required piece of data is not - in the request or in local files, do not fail silently: return an +- **Reusable module with its own data model.** A skill body is executed across + many requests — it is a reusable module, never a one-shot exchange. It must + not rely on the human to supply its working data at predict/act time. The + skill owns its source of truth: a self-contained internal/mock data model + (module-level fixtures or config-file-backed state). The REPL input path is + for clarifying questions only — never the primary data source. +- **Request input for clarification when requirements are unclear from the + prompt.** If the human's intent is ambiguous, do not guess: return an `ActionResult(action_log="...", new_state=request.text, needs_input="")`. - The run pauses and the human is asked. The answer arrives on - `request.user_input` and `act` is called again with the *same* prediction — - check `request.user_input` on the resume pass to finish the run (or ask again - if it is still insufficient). + The run pauses and the human answers on `request.user_input`; `act` is then + called again with the *same* prediction — check `request.user_input` on the + resume pass to finish the run. This disambiguates intent only, never + operational data — a skill asking for data it should own (tracking IDs, + coordinates, statuses) is missing its data model. - **Write files under configured data dirs only** (e.g. `ctx.config["drafts"]`), never anywhere else on disk. - **Fail fast on budget.** Keep the work small; do not loop or retry in code. diff --git a/semif_agent/codegen.py b/semif_agent/codegen.py index 7229b12..d3f906f 100644 --- a/semif_agent/codegen.py +++ b/semif_agent/codegen.py @@ -599,6 +599,9 @@ def build_skill_body_prompt( f"Skill description: {draft.description}\n" f"Existing skills in this category: {existing}\n" f"Existing categories:\n{tree_summary(tree)}\n" + "This body will be reused across many requests: give the skill its own " + "internal/mock data model and never ask the human for operational data — " + "ask only to clarify intent.\n" "Write the Python module body now. Reply with ONLY valid Python code " "defining `predict` and `act`. No prose, no markdown fences, no JSON." ) @@ -680,6 +683,9 @@ def _retry_prompt( f"Category: {category}\n" f"Skill name: {draft.name}\n" f"Skill description: {draft.description}\n" + "This body will be reused across many requests: give the skill its own " + "internal/mock data model and never ask the human for operational data — " + "ask only to clarify intent.\n" "Reply with ONLY valid Python defining `predict` and `act`. No prose, " "no markdown fences, no JSON." ) diff --git a/tests/test_codegen.py b/tests/test_codegen.py index f636f63..db2b318 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -17,6 +17,7 @@ from semif_agent.codegen import ( CodegenClient, CodegenError, DegenerationError, + _retry_prompt, build_skill_body_prompt, generate_skill_body, parse_skill_body, @@ -52,6 +53,15 @@ def test_read_skill_contract_loads_contract(): assert "data/skills" in text +def test_contract_directs_reusable_self_mocked_skills(): + """SKILL.md must tell the model that a body is a reusable module owning its + own source of truth, not a one-shot that leans on the human for data.""" + text = read_skill_contract() + assert "Reusable module with its own data model" in text + assert "internal/mock data model" in text + assert "for clarifying questions only" in text + + def test_build_skill_body_prompt_includes_contract_request_and_draft(): tree = build_tree(build_skills({"skills": {}})) draft = SkillDraft(name="probe", description="Probe the service.") @@ -66,6 +76,32 @@ def test_build_skill_body_prompt_includes_contract_request_and_draft(): assert "tracking.check" in joined +def test_build_skill_body_prompt_directs_reuse_and_self_mock_data(): + tree = build_tree(build_skills({"skills": {}})) + draft = SkillDraft(name="probe", description="Probe the service.") + messages = build_skill_body_prompt( + Request("check if the service is up"), "tracking", draft, tree, "THE CONTRACT" + ) + joined = messages[1]["content"] + assert "reused across many requests" in joined + assert "internal/mock data model" in joined + assert "ask only to clarify intent" in joined + + +def test_retry_prompt_directs_reuse_and_self_mock_data(): + messages = _retry_prompt( + Request("check if the service is up"), + "tracking", + SkillDraft(name="probe", description="Probe the service."), + "THE CONTRACT", + ValueError("skill body is empty"), + ) + joined = messages[1]["content"] + assert "reused across many requests" in joined + assert "internal/mock data model" in joined + assert "ask only to clarify intent" in joined + + @pytest.mark.parametrize( "raw", [