Skip to content

improve(core): require recurrence evidence before extracting skills#25147

Merged
SandyTao520 merged 6 commits intomainfrom
st/feat/skill-extraction
Apr 15, 2026
Merged

improve(core): require recurrence evidence before extracting skills#25147
SandyTao520 merged 6 commits intomainfrom
st/feat/skill-extraction

Conversation

@SandyTao520
Copy link
Copy Markdown
Contributor

Summary

Tighten the skill extraction agent's signal gate so it requires evidence of recurrence and durability before writing a skill. Previously, sessions with similar summaries (e.g., two one-off incidents about login debugging) could trigger skill creation. Now the agent defaults to "no skill" and must prove future reuse before proceeding.

Details

Prompt changes (skill-extraction-agent.ts):

  • Add two new gate questions: "Is there strong evidence this will recur?" and "Is this broader than a single incident?"
  • Default to NO SKILL — the agent must justify creation, not justify skipping.
  • Explicitly reject one-off incidents, single-session preferences, and output-style preferences.
  • Raise the bar on confidence tiers: medium confidence now means "usually do NOT create."
  • Warn the agent that session-summary similarity alone is never sufficient evidence.
  • Require naming the future trigger, evidence sessions, recurrence signal, and validation signal before writing.

Unit test (skill-extraction-agent.test.ts):

  • Verifies new prompt guardrails are present (default-to-no-skill, incident rejection, summary-vs-evidence warnings).

Behavioral eval (skill_extraction.eval.ts):

  • ignores one-off incidents: seeds two incident-response sessions with similar summaries and asserts zero skills are created.
  • extracts a repeated project-specific workflow: seeds two sessions describing the same settings-doc regeneration workflow and asserts the extracted skill contains the correct commands and sections.

Related Issues

Closes #18007

How to Validate

  1. Run the unit test:
    npm test -w @google/gemini-cli-core -- src/agents/skill-extraction-agent.test.ts
  2. Run the behavioral evals (requires API key):
    npm run test -w evals -- skill_extraction.eval.ts
  3. Review the prompt diff to confirm the new gate questions and rejection categories are present.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@SandyTao520 SandyTao520 requested review from a team as code owners April 10, 2026 20:52
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the precision of the skill extraction agent by raising the bar for what constitutes a reusable skill. By requiring evidence of recurrence and durability, the agent is now less likely to create skills from one-off incidents or user-specific preferences, ensuring that only high-value, repeatable workflows are captured.

Highlights

  • Stricter Skill Extraction Criteria: Updated the skill extraction agent's prompt to require explicit evidence of recurrence and durability, defaulting to 'no skill' unless justified.
  • New Guardrails: Added specific rejection categories for one-off incidents, single-session preferences, and output-style preferences to prevent unnecessary skill creation.
  • Enhanced Validation: Introduced new behavioral evaluations to verify that the agent correctly ignores one-off incidents while successfully extracting repeated project-specific workflows.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

Size Change: +2.42 kB (+0.01%)

Total Size: 33.6 MB

Filename Size Change
./bundle/chunk-3C5HMBV5.js 0 B -3.8 kB (removed) 🏆
./bundle/chunk-GWNCRQFK.js 0 B -3.42 MB (removed) 🏆
./bundle/chunk-RYLKYKIA.js 0 B -14.5 MB (removed) 🏆
./bundle/core-PQZMUSEF.js 0 B -46.6 kB (removed) 🏆
./bundle/devtoolsService-FR3DNE3S.js 0 B -28.4 kB (removed) 🏆
./bundle/gemini-WOWVBYIX.js 0 B -553 kB (removed) 🏆
./bundle/interactiveCli-6J5254PO.js 0 B -1.29 MB (removed) 🏆
./bundle/oauth2-provider-46MXKLRP.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-72E4X26G.js 14.5 MB +14.5 MB (new file) 🆕
./bundle/chunk-V4H5YYIL.js 3.8 kB +3.8 kB (new file) 🆕
./bundle/chunk-WHPGIKXF.js 3.42 MB +3.42 MB (new file) 🆕
./bundle/core-TQMVEXLQ.js 46.6 kB +46.6 kB (new file) 🆕
./bundle/devtoolsService-HO4JYN7I.js 28.4 kB +28.4 kB (new file) 🆕
./bundle/gemini-2646R5JZ.js 553 kB +553 kB (new file) 🆕
./bundle/interactiveCli-UEYEGSVA.js 1.29 MB +1.29 MB (new file) 🆕
./bundle/oauth2-provider-6BBV3A7J.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/bundled/third_party/index.js 8 MB 0 B
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-5PS3AYFU.js 1.18 kB 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-PC3Y4R7E.js 1.97 MB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-MF3K2DAE.js 0 B -932 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/events-XB7DADIJ.js 418 B 0 B
./bundle/gemini.js 4.97 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-R4AKKXHF.js 980 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 222 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 229 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 13.4 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-NMOP5TMJ.js 932 B +932 B (new file) 🆕

compressed-size-action

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new evaluation suite and unit tests for the skill extraction system, while refining the agent's system prompt to prioritize durable, recurring workflows over one-off incidents. Feedback focuses on aligning the test code with repository style guides, specifically regarding the proper management of environment variables using vi.stubEnv and avoiding global state modifications like process.chdir.

Comment thread evals/skill_extraction.eval.ts
Comment thread evals/skill_extraction.eval.ts Outdated
Comment thread evals/skill_extraction.eval.ts Outdated
Comment on lines +171 to +174
const previousCwd = process.cwd();
let config: Awaited<ReturnType<typeof loadCliConfig>> | undefined;

process.chdir(projectRoot);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Modifying the process working directory with process.chdir() is a risky practice in tests as it affects the global state of the process and can cause flakiness in concurrent test runs. Since loadSettings and loadCliConfig both accept a projectRoot or cwd parameter, this global change is redundant and should be avoided.

    let config: Awaited<ReturnType<typeof loadCliConfig>> | undefined;

    try {
      resetSettingsCacheForTesting();

@gemini-cli gemini-cli Bot added the area/unknown Triage automation assigns this label to issues that it is unable to classify label Apr 10, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

59 tests passed successfully on gemini-3-flash-preview.


This is an automated guidance message triggered by steering logic signatures.

@SandyTao520
Copy link
Copy Markdown
Contributor Author

Re: process.chdir feedback — Intentionally keeping process.chdir here. startMemoryService and its transitive callchain (e.g. skill extraction, memory consolidation) rely on process.cwd() internally, so removing the chdir would break the eval. The current code restores the original cwd in a finally block, which is safe.

The other two comments (use vi.stubEnv instead of direct process.env mutation) are addressed in 42a4dcb.

Comment thread evals/skill_extraction.eval.ts Outdated
Comment thread evals/skill_extraction.eval.ts Outdated
Comment thread evals/skill_extraction.eval.ts Outdated
Comment thread evals/skill_extraction.eval.ts
Copy link
Copy Markdown
Member

@gundermanc gundermanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good! Main suggestions are that we:

  • Use componentEval() test type instead so we can eliminate a lot of the E2E related boilerplate and indirection.
  • Consider following up with more cases over time.
  • Ensure we have telemetry and/or logging that can help us detect and produce more evals for cases that don't work well.

'1. "Is this something a competent agent would NOT already know?" If no, STOP.',
'2. "Does an existing skill (listed below) already cover this?" If yes, STOP.',
'3. "Can I write a concrete, step-by-step procedure?" If no, STOP.',
'4. "Is there strong evidence this will recur for future agents in this repo/workflow?" If no, STOP.',
Copy link
Copy Markdown
Member

@gundermanc gundermanc Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point I think it'd help to be able to furnish the agent with quantitative data, like a sqlite DB or index of past sessions vs. making it count.

'- reuse proven workflows and verification checklists',
'- avoid known failure modes and landmines',
'- anticipate user preferences without being reminded',
'- capture durable workflow constraints that future agents are likely to encounter again',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 General thought on the system prompt -- this seems very long and very mechanical. Is it LLM generated? I find the LLM generates very structured, sometimes redundant prompts, though it's pretty good at reflecting on pre-written prompts.

I think you might be able to accomplish the same outcome with 1/4th the text and make it a bit easier to reason about. Ideally we have enough evals that we can sort of experiment and see which lines are required.

I'd suggest in a separate PR trying to ask the model to condense this, then tweaking the follow up by hand. If we have enough evals it should be possible to test how the behavior changes.

Replaces the evalTest approach (full CLI subprocess + loadCliConfig) with
componentEvalTest (in-process makeFakeConfig + direct startMemoryService).

Key changes:
- ComponentRig now creates an isolated homeDir and stubs GEMINI_CLI_HOME
  after auth to isolate storage paths (sessions, skills, extraction state).
- ComponentRig.cleanup() calls config.dispose() and vi.unstubAllEnvs().
- Skill extraction evals pass approvalMode: YOLO to auto-approve tool
  calls (write_file/read_file) in non-interactive mode.
- Removes ~100 lines of boilerplate (withRigStorage, waitForExtractionState,
  loadCliConfig, loadSettings, process.chdir).
Comment thread evals/skill_extraction.eval.ts Outdated
Copy link
Copy Markdown
Member

@gundermanc gundermanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestion. There seems to be a compile error.

@SandyTao520 SandyTao520 enabled auto-merge April 15, 2026 18:37
@SandyTao520 SandyTao520 added this pull request to the merge queue Apr 15, 2026
Merged via the queue into main with commit 485f3d9 Apr 15, 2026
29 checks passed
@SandyTao520 SandyTao520 deleted the st/feat/skill-extraction branch April 15, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/unknown Triage automation assigns this label to issues that it is unable to classify

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the world a better place

2 participants