Expand description
Helpers for the autonomous skill-review pipeline.
Skill review takes the conversation trace from a completed turn and
decides whether the agent’s approach is worth saving as a reusable
skill. The first step is converting the raw Vec<Message> into a
structured tool-trajectory the review LLM can reason about — without
drowning in tool I/O bytes.
The shape is deliberately small (one builder, one truncation knob) so that future steps in the pipeline (success heuristics, evolution decisions) can compose on top without entangling.
Module entry points:
build_tool_trajectory— render aVec<Message>to a step listassess_success— cheap heuristic that flags failed/aborted turns so the review LLM doesn’t waste budget packaging them as skills
Structs§
- Applied
Action - Outcome of applying a review action; logged by the caller.
- Skill
Review Job - Asynchronous queue for end-of-turn skill review requests. The agent
loop enqueues a
chat_idafter a successful turn; a dedicated worker task drains the queue and invokesrun_skill_reviewwithout blocking the request path. - Skill
Review Queue - Skill
Review Worker - Owning side of the skill-review queue. Created together with the
SkillReviewQueuehandle and consumed byspawn_skill_review_worker.
Enums§
- Learn
Outcome - Outcome of one review pass, rich enough for a user-facing reply
(the
/learncommand) while the autonomous path just logs it. - Review
Action - Decoded review verdict. Accepts both the new
{"action": "create"|"edit"|"patch"|"none", ...}shape and the legacy{"create": true|false, ...}shape so older self-hosted prompts and fine-tuned models keep working through the upgrade. - Success
Signal - Cheap, no-LLM verdict on whether a completed turn is “successful
enough” to mine for a reusable skill. We bias toward false positives
(review more) over false negatives (miss a good skill) — only the
clear failure shapes are flagged as
Unlikely. - Trajectory
Step - One step in the rendered trajectory.
Constants§
- DEFAULT_
TEXT_ PREVIEW_ CHARS - Cap per assistant/user text block. Long-form messages (essays, pasted-in code) get summarized; concise reasoning narrations pass through unchanged.
- DEFAULT_
TOOL_ INPUT_ PREVIEW_ CHARS - Cap per-tool-input JSON in the rendered trajectory. Generous enough to
preserve typical commands/queries, tight enough that one giant
bashpayload doesn’t blow up the review prompt. - DEFAULT_
TOOL_ RESULT_ PREVIEW_ CHARS - Cap per-tool-result body in the rendered trajectory. Tool results are often the bulk of token cost; the head usually carries the headline, so head-only truncation is fine for review purposes.
Functions§
- apply_
review_ action - Validate + apply a review action against the skills directory on disk.
Returns
Ok(Some(_))when a file was written,Ok(None)forNone/Malformed, orErr(_)when the action failed validation (already- existing name on create, missing target on edit/patch, immutable human-curated target, injection-scan failure, etc.). - archive_
inactive_ agent_ skills - Move stale agent-created skills out of the active discovery path.
Targets a skill iff
should_archive_skillreturns true for its (mtime, last activation) pair againstthreshold_days. - assess_
success - Inspect the trailing assistant text + the tool-result mix to decide whether the task looks completed. Designed to be safe to call even on short or pathological message lists.
- build_
skill_ review_ channel - Build the
(handle, worker)pair that goes intoAppStateand the scheduler boot, respectively. - build_
tool_ trajectory - Render the conversation as an ordered, structured tool trajectory
suitable for feeding to a review LLM. Image blocks are dropped (no
text signal) and oversized payloads are head-truncated using the
DEFAULT_*_PREVIEW_CHARScaps. The output is human-readable Markdown — the leading numbers make it easy for the LLM to reference specific steps in its rationale. - parse_
review_ action - run_
skill_ review - Run the full review pipeline for one chat. Safe to call repeatedly
for the same chat — the cap on
agent-createdskills and the duplicate-name check inside skill creation prevent runaway writes. - run_
skill_ review_ core - Full review pipeline for one chat.
forcedis the/learnpath: it bypasses the feature gate, the tool-call threshold, and the success heuristic — the user explicitly asked for distillation — but keeps the agent-created cap and every content-security check. - should_
archive_ skill - Pure decision rule for the auto-archive sweep — extracted so the
policy can be unit-tested without touching the filesystem clock.
Returns
trueiff the candidate skill should be archived. - spawn_
skill_ review_ worker - Run the worker loop on the current task. Drains all immediately- available jobs into a dedup set before processing, so a flurry of enqueues for the same chat collapses to one review.