
Skill
context-engineering-hillclimb
improve ContextSet via hill-climbing iterations
Description
Guides the agent to perform hill-climbing iterations to improve a ContextSet based on Evalbench evaluation results.
SKILL.md
Load the
context-engineering-workflowskill first. It holds the shared context this phase depends on: workspace layout, state file conventions, phase order, and safety protocol. Do not proceed with this phase without reading it.
Phase: Optimization & Hill-Climbing
Goal
Analyze evaluation failures to perform a Gap Analysis and apply targeted context mutations (refinements) to iteratively improve translation accuracy.
Workflow
Follow these steps exactly in order:
1. Setup & Loop
- Validation:
- Check if
autoctx/experiments/directory andautoctx/state.mdexist. If missing, warn the user that the workspace might not be initialized (suggest running the Setup & Connection phase of this skill first). - Once an experiment is selected, verify it contains an
eval_reports/folder. If missing, suggest running the Evaluation workflow first.
- Check if
- Identify Experiment:
- Read the local
autoctx/state.mdto identify the active experiment. - If not found, ask the user to select an experiment folder from
autoctx/experiments/.
- Read the local
- Determine Loop Version:
- Scan the
autoctx/experiments/<experiment_name>/hillclimb/folder for files matchingimproved_context_v*.json. - Determine the loop version
vNby finding the maximumNand usingN+1. If the folder is empty, start atv1.
- Scan the
- Locate Base Context:
- For
v1:- Check
autoctx/state.mdto see if a specific base context path was recorded for this experiment (e.g., during the Evaluation setup for user-provided contexts). - If not found in
state.md, default to the baseline generated by Bootstrap in the experiment folder. - If still not found, ask the user for the absolute path to their base context file and record it as the Base Context in autoctx/state.md.
- Check
- For
vN(where N > 1), the base context isimproved_context_v(N-1).json. - Verify the base context file exists. If missing, STOP and ask the user for the correct path.
- For
2. Phase 1: Gap Analysis
- Validation:
- Determine the target evaluation run folder under
eval_reports/. If multiple folders exist, find the most recent one by modified time. Prefer the latest run by default, but list other available runs as well (peeking into theirsummary.csvorconfigs.csvto show timestamps/metrics for visual context). Ask the user to confirm the selection. - Verify that the selected
eval_reports/<job_id_folder>/contains expected files (e.g.,scores.csv,summary.csv). If missing or empty, STOP and inform the user.
- Determine the target evaluation run folder under
- Read Evaluation Results: Use the
read_evaluation_resultMCP tool passing the path toeval_reports/<job_id_folder>/. - Generate Gap Analysis Report (Batched):
- The tool returns a summary and a batch of failure cases (default limit 10).
- Iterate through the failure cases by calling the tool with increasing
offset(0, 10, 20, ...) until all failed queries are analyzed. - First Batch (offset=0): Initialize the report file with the
# Gap Analysis Report - vNheader and## Summarysection, followed by the analysis of the first batch under## Failed Queries Detail. - Subsequent Batches: Call the tool with the next offset, analyze the new failures, and append them to the
## Failed Queries Detailsection.
Use the following structure for the report:# Gap Analysis Report - vN ## Summary - **Total Queries**: 10 - **Passed**: 7 - **Failed**: 3 - **Pass Rate**: 70% ## Failed Queries Detail ### Query 1: "How many users registered in 2023?" - **Error Category**: `[FilterError]` - **Expected SQL**: `SELECT count(*) FROM users WHERE year = 2023` - **Actual SQL**: `SELECT count(*) FROM users` (Missing filter) - **Root Cause**: The LLM did not know about the `year` column or how to filter by year for this entity. - **Proposed Mutation**: Add a facet for "Users by Year". ### Query 2: "Show me top selling products" - **Error Category**: `[OrderingError]` - **Expected SQL**: `SELECT name FROM products ORDER BY sales DESC LIMIT 5` - **Actual SQL**: `SELECT name FROM products LIMIT 5` - **Root Cause**: Missing ordering instruction in context. - **Proposed Mutation**: Update the template for "Product Sales" to include ordering. ### Query 3: "Get users older than 30" - **Error Category**: `[GoldenDataError]` - **Expected SQL**: `SELECT * FROM users WHERE age >> 30` (Syntax error `>>` in golden SQL) - **Actual SQL**: `SELECT * FROM users WHERE age > 30` - **Root Cause**: Invalid syntax in golden dataset. - **Proposed Mutation**: None. Flag to user to fix the evaluation dataset. - Save Report: You MUST physically write the report file to
autoctx/experiments/<experiment_name>/hillclimb/gap_analysis_vN.md. If you are processing in batches, ensure you append to this file until all failed queries are documented. Do not merely output it in chat; it must exist on the file system. - Log in State Tracking:
- Update
autoctx/state.mdto record the mapping for LoopvN(Base Context <-> Eval Report <-> Gap Analysis).
- Update
- Human-in-the-Loop Review:
- Inform the user that the Gap Analysis report has been successfully written to disk.
- Ask the user if they want to review, make any corrections, or add manual feedback directly to the file before proceeding to Phase 2 (Context Mutation).
- Wait for user confirmation before starting Phase 2.
3. Phase 2: Context Mutation
Refer to context-generation-guide for how to edit a ContextSet.
- Validation: Verify that
gap_analysis_vN.mdexists and contains findings. Verify the base ContextSet file exists. If missing, STOP and inform the user. - Analyze Gap Report & Determine Fixing Strategy:
- Read
gap_analysis_vN.mdto identify what needs to be fixed. - Fixing Strategy Guidelines:
- Conciseness: Try to use less context to cover more scenarios. Avoid adding redundant or hyper-specific templates for every single edge case.
- Generalizability: Prefer solutions that generalize well (e.g., use a
facetfor a column definition rather than a specifictemplatefor every query using that column). - Supported Types: Support mutations for
template,facet, andvalue_searchtypes.
- Read
- Apply Mutations:
- Copy the Base Context: Copy the base ContextSet file to the new destination:
autoctx/experiments/<experiment_name>/hillclimb/improved_context_vN.json. - Generate New Items: For any new context items identified in the fixing strategy (for "add" operations):
- Invoke the
context-generation-guideskill to produce the final parameterized items. - Provide the identified candidates to that skill.
- That skill will handle phrase extraction, parameterization, and constructing the valid JSON structure.
- Invoke the
- Validate New Items:
- Templates: Run generated SQL examples via
<source>-execute-sql(use dummy values for placeholders) to verify syntax. - Others: Cross-check table/column references against the schema via
<source>-list-schemas.
- Templates: Run generated SQL examples via
- Apply Mutations: Call the
mutate_context_setMCP tool passing the new file path asfile_pathand mutations asmutations_jsonto mutate the context set.
- Copy the Base Context: Copy the base ContextSet file to the new destination:
- Log in State Tracking:
- Update
autoctx/state.mdto include the output path ofimproved_context_vN.jsonfor LoopvN.
- Update
4. Validation & Upload Advice
- Summarize Improvements: Tell the user what was changed (e.g., added 2 facets, updated 1 template).
- Upload Instructions:
- Read Database Details: Read
autoctx/tools.yaml(ordb_config.yaml) to fetch the specific project, location, and instance/cluster details for the active database. - Generate URL: Call the
generate_upload_urltool passing the extracted values to provide the direct console link to the user. - Present the local file path to
improved_context_vN.jsonand the generated console link together in a single clear message.
- Read Database Details: Read
- Instruct Next Step Evaluation:
- Instruct the user to run evaluation using the evaluating workflow on this new ContextSet to see if metrics improve. This will start Loop
N+1.
- Instruct the user to run evaluation using the evaluating workflow on this new ContextSet to see if metrics improve. This will start Loop
Output
Upon successful completion, the workspace must contain:
autoctx/experiments/<experiment_name>/hillclimb/gap_analysis_vN.mdautoctx/experiments/<experiment_name>/hillclimb/improved_context_vN.json- Updated
autoctx/state.mdsummarizing the run loop.
Logging State Example (autoctx/state.md)
When updating autoctx/state.md, please append or update the Hill-Climbing Run Log section:
# Context Authoring Experiment State Tracking
## Active Experiment: my-exp-1
## Hill-Climbing Run Log
### Loop: v1
- **Base Context**: `baseline_context.json`
- **Eval Report Path**: `autoctx/experiments/my-exp-1/eval_reports/<job_id_uuid>/` (containing `configs.csv`, `evals.csv`, etc.)
- **Gap Analysis**: `autoctx/experiments/my-exp-1/hillclimb/gap_analysis_v1.md`
- **Mutated Context**: `autoctx/experiments/my-exp-1/hillclimb/improved_context_v1.json`
!IMPORTANTTool Modification Rule: Always use the
mutate_context_settool for all ContextSet changes. Pass mutation payloads directly to the tool — it handles all file I/O internally. Do not read the target context set file beforehand.
More skills from the db-context-enrichment repository
View all 7 skillscontext-engineering-bootstrap
bootstrap initial ContextSet for database enrichment
Jul 18ContextData ModelingDatabaseGoogle Cloudcontext-engineering-dataset-generation
generate golden SQL evaluation datasets
Jul 18Data AnalysisEvalsGoogle CloudSQLcontext-engineering-evaluate
evaluate ContextSet against golden datasets
Jul 18Data AnalysisEvalsGoogle CloudSQLcontext-engineering-init
initialize context engineering and database connections
Jul 18ConfigurationDatabaseEngineeringGoogle Cloudcontext-engineering-workflow
optimize context sets for Gemini data agents
Jul 18Agent ContextData AnalysisGeminiGoogle Cloudcontext-generation-guide
generate context items for database enrichment
Jul 18Agent ContextDatabaseDocumentationGoogle Cloud
More from Google Cloud
View publisherkb-search
search and extract local knowledge base documents
knowledge-catalog
Jul 12DocumentationKnowledge BaseSearchknowledge_catalog_discovery_agent
search and rank Knowledge Catalog data entries
knowledge-catalog
Jul 12Data AnalysisGoogle CloudKnowledge ManagementSearchcontributing
contribute to Cloud Foundation Fabric
cloud-foundation-fabric
Jul 31AutomationEngineeringGitHubGoogle Cloud +1fabric-builder
generate Terraform code for Google Cloud
cloud-foundation-fabric
Jul 12Google CloudInfrastructure as CodeTerraformfast-0-org-setup-prereqs
prepare prerequisites for FAST 0-org-setup
cloud-foundation-fabric
Jul 12Google CloudOperationsagent-aware-cli
design agent-aware command-line interfaces
vertex-ai-creative-studio
Jul 12CLIEngineeringGoogle Cloud