teach codegen that skills are reusable modules with self-owned data (guardrail item 9)

This commit is contained in:
Denton Social committed 2026-09-24 23:45:52 -05:00
1 parent db7d431976
commit 90fda9f2a4
4 files changed
+65 -7

No files matched your search

+10 -1
View File
@@ -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 - Update `config.example.json` codegen block and the AGENTS.md codegen
section with every new key from items 2, 4, 5. 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`) (`codegen.py`, `SKILL.md`)
- The generated body is meant to be REUSED across requests, so the prompt - 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 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. internal/mock data model; ask the human only to disambiguate intent.
- Test: prompt/`SKILL.md` contains the reuse + self-mock-data directives; - Test: prompt/`SKILL.md` contains the reuse + self-mock-data directives;
a generated-body parse is unaffected. 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 ### Code principles
- **No mocking.** The decision engine is always real SemIf; the LLM is always a - **No mocking.** The decision engine is always real SemIf; the LLM is always a
+13 -6
View File
@@ -72,13 +72,20 @@ def act(ctx, request, prediction) -> ActionResult:
- **Never swallow the request.** If the skill cannot act, return an - **Never swallow the request.** If the skill cannot act, return an
`ActionResult` with a short `action_log` explaining why and set `new_state` `ActionResult` with a short `action_log` explaining why and set `new_state`
back to `request.text`. back to `request.text`.
- **Request input when data is missing.** If a required piece of data is not - **Reusable module with its own data model.** A skill body is executed across
in the request or in local files, do not fail silently: return an 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="<question>")`. `ActionResult(action_log="...", new_state=request.text, needs_input="<question>")`.
The run pauses and the human is asked. The answer arrives on The run pauses and the human answers on `request.user_input`; `act` is then
`request.user_input` and `act` is called again with the *same* prediction — called again with the *same* prediction — check `request.user_input` on the
check `request.user_input` on the resume pass to finish the run (or ask again resume pass to finish the run. This disambiguates intent only, never
if it is still insufficient). 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"]`), - **Write files under configured data dirs only** (e.g. `ctx.config["drafts"]`),
never anywhere else on disk. never anywhere else on disk.
- **Fail fast on budget.** Keep the work small; do not loop or retry in code. - **Fail fast on budget.** Keep the work small; do not loop or retry in code.
+6
View File
@@ -599,6 +599,9 @@ def build_skill_body_prompt(
f"Skill description: {draft.description}\n" f"Skill description: {draft.description}\n"
f"Existing skills in this category: {existing}\n" f"Existing skills in this category: {existing}\n"
f"Existing categories:\n{tree_summary(tree)}\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 " "Write the Python module body now. Reply with ONLY valid Python code "
"defining `predict` and `act`. No prose, no markdown fences, no JSON." "defining `predict` and `act`. No prose, no markdown fences, no JSON."
) )
@@ -680,6 +683,9 @@ def _retry_prompt(
f"Category: {category}\n" f"Category: {category}\n"
f"Skill name: {draft.name}\n" f"Skill name: {draft.name}\n"
f"Skill description: {draft.description}\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, " "Reply with ONLY valid Python defining `predict` and `act`. No prose, "
"no markdown fences, no JSON." "no markdown fences, no JSON."
) )
+36
View File
@@ -17,6 +17,7 @@ from semif_agent.codegen import (
CodegenClient, CodegenClient,
CodegenError, CodegenError,
DegenerationError, DegenerationError,
_retry_prompt,
build_skill_body_prompt, build_skill_body_prompt,
generate_skill_body, generate_skill_body,
parse_skill_body, parse_skill_body,
@@ -52,6 +53,15 @@ def test_read_skill_contract_loads_contract():
assert "data/skills" in text 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(): def test_build_skill_body_prompt_includes_contract_request_and_draft():
tree = build_tree(build_skills({"skills": {}})) tree = build_tree(build_skills({"skills": {}}))
draft = SkillDraft(name="probe", description="Probe the service.") 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 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( @pytest.mark.parametrize(
"raw", "raw",
[ [