From 50c83c61fd47cbc754cf6e9178a0a2622a41cff1 Mon Sep 17 00:00:00 2001 From: Denton Social Date: Wed, 30 Sep 2026 15:01:47 -0500 Subject: [PATCH] edit documentation for clarity, add table for per-query context composition --- AGENTS.md | 8 ++++-- README.md | 62 ++++++++++++++++++++++++++++++++++++++++ semif_agent/provider.py | 15 +++++----- semif_agent/scheduler.py | 10 +++---- 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index f60f50f..7bb7cbf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -695,9 +695,11 @@ CLI, unit tests (24) + box integration tests (2). exceeds even the relaxed cap before it settles on a body, which is why the sampler (below) is the real fix. - **Sampler params + escalation.** `codegen.temperature` (default 0.7), - `top_p` (0.85), `presence_penalty` (1.5), `frequency_penalty` (0.2) follow - the Qwen3.8 model card's instruct-mode anti-repetition guidance — a high - `presence_penalty`, not greedy temperature, is the loop cure. Those four are + `top_p` (0.85), `presence_penalty` (1.5), `frequency_penalty` (0.2) are the + Qwen3.8 model card's instruct-mode preset used as an anti-repetition sampler, + not to toggle reasoning — a high `presence_penalty`, not greedy temperature, + is the loop cure, and the model's thinking-mode preset + (`presence_penalty=0.0`) is exactly what it loops under. Those four are the only sampler knobs reachable via ollama's OpenAI-compat API; `repeat_penalty`/`min_p`/`top_k` are Modelfile-only, so the per-request `presence_penalty` (which overrides the Modelfile) is what actually stops the diff --git a/README.md b/README.md index eebd3d1..b7ba969 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ A successful release of this could be defined by a single question: "Can I use t - [The skill tree and navigation](#the-skill-tree-and-navigation) - [The skill run loop](#the-skill-run-loop) - [Authoring a new skill](#authoring-a-new-skill) + - [What each model sees](#what-each-model-sees) - [Data contracts and tiered config](#data-contracts-and-tiered-config) - [Repairing a failed run](#repairing-a-failed-run) - [Dream: the learning signal](#dream-the-learning-signal) @@ -189,6 +190,67 @@ A rejected/simulated body is traced (`fidelity_review`), badged `unverified`, and never blocks authoring. Codegen failures (including timeouts) surface as a graceful stub and are retryable with `restart `. +### What each model sees + +Two kinds of model calls exist, and they are injected with **different things**. + +A **SemIf decision** carries only three fields — `state`, `question`, and +`options` (each with an `id` + `description`) — and +`semif_phase1.llamacpp_backend.score` reads the option logits from that one +forward pass. There is no hidden system prompt and no growing conversation: +what you see in the table below is the entire input. Probabilities are +conditional on exactly the supplied options. + +A **generative call** (`llm` for titles/descriptions, `codegen` for bodies and +tests) is a built OpenAI-style `messages` list. Its context is assembled from +the request, the tree, the elicitation answers, the runtime **bridge catalog** +(`describe_bridges()`), and — for bodies and tests — the contract files +(`SKILL.md`, `TESTGEN.md`). + +#### SemIf decisions + +| Phase | File | State injected | Options | +| --- | --- | --- | --- | +| `interrupt:choice` | `scheduler.py:279` | request text + `[current process: ]` | `interrupt` / `defer` | +| `priority:score` | `scheduler.py:296` | request text (+ `[current process: …]` when busy) | critical / high / medium / low | +| `navigate:category` | `skills.py:682` | request text | every category name (+ `create_category`) | +| `navigate:leaf` | `skills.py:736` | request text + `[current process: ]` | every skill name + description (+ `create_skill`) | +| `navigate:response` | `skills.py:634` | request text + category | canned reply names + descriptions (catchall last) | +| `navigate:intent` | `skills.py:811` | `Requested action: ` + `Action of the existing skill: ` | `same` / `different` | +| `assess:outcome` | `skill.py:257` | skill label + goal + action log | `success` / `failure` | +| `assess:requeue` | `skill.py:279` | skill label + goal + action log + `outcome: failed` | `complete` / `retry` | +| `config:search` | `scheduler.py:1477` | skill + variable name + its semantic description | each candidate config key (+ `ask`) | +| `config:record` | `skill.py:112` | skill + `variable = value` | `record` / `ask_again` | +| `authoring:fidelity` | `scheduler.py:1311` | skill, request, description, `INTEGRATION` JSON, static findings, first 4000 chars of body | `accept` / `reconsider` | +| `repair:choice` | `scheduler.py:658` | skill, request, integration, truncated failure | `retry` / `repair_skill` / `ask_user` / `no_repair` | +| degeneration watchdog¹ | `cli.py:128` | `[codegen ]` + last 2000 chars of the stream | `continue` / `stop` | +| `codegen_regen`¹ | `cli.py:165` | `[testgen ]` + last 1200 chars of the test error | `regen_code` / `regen_test` / `regen_contract` | + +¹ Trace-only: logged to `runs.jsonl`, never to `decisions.jsonl`. + +#### Generative calls + +| Call | Client | System context | User context | File | +| --- | --- | --- | --- | --- | +| `generate_category` | `llm` | authoring instruction: propose one broad category, JSON-only | request text + full tree summary | `skills.py:896` | +| `generate_skill` | `llm` | authoring instruction: propose one specific skill, JSON-only | request + category + existing skill names | `skills.py:947` | +| `generate_skill_body` | `codegen` | full **SKILL.md** | request, category, name, description, existing skills + tree summary, elicitation answers, integration hint, **bridge catalog**, `BODY_DIRECTIVES` | `codegen.py:156` | +| body retry | `codegen` | full **SKILL.md** | rejection reason, request, category, name, description, elicitation answers, integration hint, **bridge catalog**, `BODY_DIRECTIVES` | `codegen.py:474` | +| `generate_elicitation` | `codegen` | elicitation instructions + example questions + anti-patterns + `max_questions` | request, category, name, description, existing skills + tree summary, **bridge catalog** | `codegen.py:580` | +| `generate_data_contract` | `codegen` | full **TESTGEN.md** | skill, request, full body code, **bridge catalog** + the contract ask | `codegen.py:833` | +| `generate_skill_tests` | `codegen` | full **TESTGEN.md** | skill, request, full body code, **bridge catalog**; continued with the accepted **contract JSON** as an assistant turn + the test-gen ask | `codegen.py:942` | +| `regenerate_skill_body` | `codegen` | full **SKILL.md** | correction header, request, description, **raw evidence bundle** (rendered verbatim), previous body, integration hint, **bridge catalog**, `BODY_DIRECTIVES` | `codegen.py:1046` | + +The **bridge catalog** is `describe_bridges()` (`bridges/registry.py:33`): each +known bridge's name, service, description, base-URL config var, auth header + +token var, documented config vars, and endpoints. It is the single runtime +source of bridge specifics — `SKILL.md` and `TESTGEN.md` carry only the generic +pattern — so a bridge can be added without touching either contract file. + +The **raw evidence bundle** handed to a corrective regen carries the request, +description, requirements, the observed failure fields (error, action log, new +state, summary) and the previous body, rendered as-is with no prose diagnosis. + ### Data contracts and tiered config Generated bodies own no data. At runtime the runner merges: diff --git a/semif_agent/provider.py b/semif_agent/provider.py index f04300e..e5707c2 100644 --- a/semif_agent/provider.py +++ b/semif_agent/provider.py @@ -80,13 +80,14 @@ class OpenAICompatClient: It lets a SemIf continue/stop decision cut off a generation that is looping instead of converging, before it fills the context window. - Sampler defaults follow the Qwen3.8 model card's instruct-mode guidance - (unsloth/Qwen3.8-27B-GGUF): the anti-repetition cure is a high - `presence_penalty`, not greedy temperature. `temperature`/`top_p`/ - `presence_penalty`/`frequency_penalty` are per-`chat` overridable; the - `generate_skill_body` escalation ladder bumps presence toward the card's - max (2.0) and lowers temperature on retries. `max_attempts` bounds that - ladder (default 3). + Sampler defaults are the Qwen3.8 card's instruct-mode preset + (unsloth/Qwen3.8-27B-GGUF) used as an anti-repetition sampler, not to + toggle reasoning: a high `presence_penalty` is the loop cure, while the + prototype thinking-mode preset (`presence_penalty=0.0`) is what this + codegen model loops under. `temperature`/`top_p`/`presence_penalty`/ + `frequency_penalty` are per-`chat` overridable; the `generate_skill_body` + escalation ladder bumps presence toward the card's max (2.0) and lowers + temperature on retries. `max_attempts` bounds that ladder (default 3). """ error_class = ProviderError diff --git a/semif_agent/scheduler.py b/semif_agent/scheduler.py index 541209f..953393f 100644 --- a/semif_agent/scheduler.py +++ b/semif_agent/scheduler.py @@ -275,7 +275,7 @@ class Scheduler: # ---- decision templates (all real SemIf, all logged) ---- - def _choice(self, request: Request, current: Process) -> bool: + def _interrupt_choice(self, request: Request, current: Process) -> bool: decision = DecisionRequest( state=compose_state(request, current=current.skill), question="Should this be allowed to interrupt the current process?", @@ -292,7 +292,7 @@ class Scheduler: ) return result.prob(CHOICE_INTERRUPT) >= self.tau - def _score(self, request: Request, current: str | None = None) -> tuple[float, str]: + def _priority_score(self, request: Request, current: str | None = None) -> tuple[float, str]: decision = DecisionRequest( state=compose_state(request, current=current), question="How urgent is this request?", @@ -335,7 +335,7 @@ class Scheduler: self.trace.append("submit", request.id, text=text, source=source) if self.current is None: - weight, label = self._score(request) + weight, label = self._priority_score(request) self.current = Process(request=request, skill="(scheduling)", weight=weight) try: outcome = self._dispatch(request, weight=weight) @@ -347,7 +347,7 @@ class Scheduler: self.trace.append("ran", request.id, skill=outcome.skill, summary=outcome.summary) return "running", f"[{label}] {outcome.summary}", request.id - interrupt = self._choice(request, self.current) + interrupt = self._interrupt_choice(request, self.current) if interrupt: if self.pending is not None: self.trace.append("pending_abandoned", self.pending.request.id) @@ -364,7 +364,7 @@ class Scheduler: self.trace.append("ran", request.id, skill=outcome.skill, summary=outcome.summary) return "preempted", f"interrupted {previous.skill}; {outcome.summary}", request.id - weight, label = self._score(request, current=self.current.skill) + weight, label = self._priority_score(request, current=self.current.skill) ok = self.queue.push(request, weight) if not ok: self.trace.append("rejected", request.id, reason="queue is full")