Skip to content

Add jqschema shared workflow for analyzing large tool outputs#1942

Merged
pelikhan merged 5 commits into
mainfrom
copilot/add-json-schema-minify-script
Oct 18, 2025
Merged

Add jqschema shared workflow for analyzing large tool outputs#1942
pelikhan merged 5 commits into
mainfrom
copilot/add-json-schema-minify-script

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 18, 2025

Overview

This PR adds a shared agentic workflow component that provides AI agents with a jq-based JSON schema discovery utility. The tool helps agents discover the structure of complex JSON responses from GitHub search tools and other APIs without displaying verbose output.

Motivation

When AI agents use GitHub search tools like search_code, search_issues, or search_repositories, the API responses can be extremely large (thousands of results with nested objects). Agents need to understand the structure of these responses to extract relevant data, but displaying full responses is:

  • Token-inefficient (wasting 40k+ tokens per response)
  • Difficult to parse visually
  • Unnecessary when only the schema structure is needed

Solution

Created a shared workflow that:

  1. Provides a bash script (/tmp/gh-aw/jqschema.sh) that transforms JSON data into compact schemas
  2. Uses jq recursively to replace all values with their type names ("string", "number", "boolean", "null")
  3. Reduces arrays to just their first element's structure
  4. Outputs compact JSON for easy readability
  5. Includes bash tools for jq * and the script path, automatically available in importing workflows

Example Transformation

Input (GitHub repository search response):

{
  "total_count": 2500,
  "incomplete_results": false,
  "items": [
    {
      "name": "gh-aw",
      "stargazers_count": 100,
      "topics": ["github", "agentic"],
      "license": {"key": "mit", "name": "MIT License"}
    }
  ]
}

Output (compact schema):

{"incomplete_results":"boolean","items":[{"license":{"key":"string","name":"string"},"name":"string","stargazers_count":"number","topics":["string"]}],"total_count":"number"}

Usage

Workflows can import this shared component and agents will have access to the script and bash tools:

imports:
  - shared/jqschema.md

Agents can then use it to analyze tool outputs:

# Discover structure before fetching large datasets
gh api search/repositories -f q="language:go" -f per_page=1 | /tmp/gh-aw/jqschema.sh

# Or pipe any JSON through it
cat response.json | /tmp/gh-aw/jqschema.sh

Benefits

  • Token Efficiency: Agents can understand response structures with minimal token usage
  • Smart Querying: Agents can plan queries after understanding available fields
  • API Exploration: Helps agents discover capabilities of unfamiliar APIs
  • Debug Aid: Makes it easier to understand what data tools return
  • Tool Access: Bash tools for jq and the script are automatically available in importing workflows

Files Changed

  • .github/workflows/shared/jqschema.md - New shared workflow component with script, tools, and documentation
  • 🧪 .github/workflows/test-jqschema.md - Test workflow demonstrating usage
  • 📦 .github/workflows/test-jqschema.lock.yml - Compiled test workflow

Workflows Updated

The jqschema utility has been added to the following workflows for immediate use:

  • .github/workflows/changeset-generator.md - GitHub PR analyzer
  • .github/workflows/daily-news.md - Daily repository news summary
  • .github/workflows/scout.md - Research and investigation workflow
  • .github/workflows/cli-version-checker.md - CLI version monitoring

Testing

  • ✅ Manual script testing with complex JSON structures
  • ✅ GitHub API response format validation
  • ✅ Edge cases (empty arrays, null values, nested objects)
  • ✅ All updated workflows compile successfully
  • ✅ All unit tests pass
  • ✅ Build successful
  • ✅ Bash tools correctly configured in compiled workflows
Original prompt

Add a shared agentic workflow that adds a script to generate minified json schema from data.

  • add step in front matter that writes this script in /tmp/gh-aw/jq folder, chmod execution rights

#!/usr/bin/env bash

json-schema-minify.sh

jq -c '
def walk(f):
. as $in |
if type == "object" then
reduce keys[] as $k ({}; . + {($k): ($in[$k] | walk(f))})
elif type == "array" then
if length == 0 then [] else [.[0] | walk(f)] end
else
type
end;
walk(.)
'

  • update prompt with usage instruction

Generate a compact structural schema (keys + types) from JSON input.

Usage:

cat data.json | ./json-schema-minify.sh

curl -s https://api.example.com/data | ./json-schema-minify.sh

  • tell the agent to use this script to discover the schema of tools that return a large amount of data like GitHub search *

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot renamed shared workflow and script to jqschema

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot add shared workflow to github PR analyzer agentic workflows, daily news, scout, cli version checker

Copilot AI and others added 2 commits October 18, 2025 12:44
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add shared agentic workflow for generating minified JSON schema Add json-schema-minify shared workflow for analyzing large tool outputs Oct 18, 2025
Copilot AI requested a review from pelikhan October 18, 2025 12:52
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 18, 2025

@copilot add shared workflow to github PR analyzer agentic workflows, daily news, scout, cli version checker

Added jqschema import to changeset-generator (PR analyzer), daily-news, scout, and cli-version-checker. All workflows compile successfully. (commit: ${git rev-parse --short HEAD})

@copilot renamed shared workflow and script to jqschema

Done. Renamed shared workflow to jqschema.md and script to jqschema.sh. All references updated. (commit: ${git rev-parse --short HEAD})

Copilot AI changed the title Add json-schema-minify shared workflow for analyzing large tool outputs Add jqschema shared workflow for analyzing large tool outputs Oct 18, 2025
@@ -0,0 +1,109 @@
---
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot add tools section

tools:
bash:
- "jq *"
- "/tmp/gh-aw/jqschema.sh"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added tools section with bash: ["jq *", "/tmp/gh-aw/jqschema.sh"]. Tools are automatically merged into workflows that import jqschema.

Comment thread .github/workflows/shared/jqschema.md Outdated
steps:
- name: Set up jq utilities directory
run: |
mkdir -p /tmp/gh-aw/jq
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot remove line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed mkdir -p /tmp/gh-aw/jq line. Script now writes directly to /tmp/gh-aw/.

Comment thread .github/workflows/shared/jqschema.md Outdated
- name: Set up jq utilities directory
run: |
mkdir -p /tmp/gh-aw/jq
cat > /tmp/gh-aw/jq/jqschema.sh << 'EOF'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot use /tmp/gh-aw/ folder, no nested jq needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to /tmp/gh-aw/jqschema.sh (removed nested jq folder). All paths updated throughout documentation and workflows.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot import jqschema in the github copilot PR analyzer agentic workflows

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan October 18, 2025 13:17
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot import jqschema in the github copilot PR analyzer agentic workflows

@pelikhan pelikhan marked this pull request as ready for review October 18, 2025 13:19
@github-actions
Copy link
Copy Markdown
Contributor

Agentic Changeset Generator triggered by this pull request.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 18, 2025

@copilot import jqschema in the github copilot PR analyzer agentic workflows

Cannot add jqschema import to copilot-agent-analysis workflow - the workflow content (18KB) + jqschema docs (3.3KB) exceeds GitHub Actions' 21KB limit for WORKFLOW_MARKDOWN environment variable. The workflow would need to be shortened first.

@copilot import jqschema in the github copilot PR analyzer agentic workflows

Cannot add jqschema import to copilot-agent-analysis workflow - the workflow content (18KB) + jqschema docs (3.3KB) exceeds GitHub Actions' 21KB limit for WORKFLOW_MARKDOWN environment variable. The workflow would need to be shortened first.

@pelikhan pelikhan merged commit 90dfff2 into main Oct 18, 2025
13 of 14 checks passed
@pelikhan pelikhan deleted the copilot/add-json-schema-minify-script branch October 18, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants