feat: default serpapi tools to markdown output, add md/json format setting - #6
Open
galetahub wants to merge 1 commit into
Open
feat: default serpapi tools to markdown output, add md/json format setting#6galetahub wants to merge 1 commit into
galetahub wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the SerpApi OpenClaw plugin to default specialized serpapi_* tools to SerpApi’s markdown output (output=md) to reduce token usage, while preserving a JSON escape hatch via config and per-call overrides.
Changes:
- Add
webSearch.formatconfig (mddefault /json) plus per-tooloutputoverride parsing. - Update SerpApi client + result shaping to support markdown responses (including cache isolation and API-key redaction) and return
{ markdown: ... }by default for specialized tools. - Add
limitResultTable()to truncate markdown result tables for tools that acceptcount.
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/config.ts | Adds SerpApiOutputFormat and resolves default format (md/json) from plugin config. |
| src/markdown.ts | New helper to truncate markdown tables under a named heading. |
| src/serpapi-client.ts | Adds md/json output selection, md-aware caching, and API key redaction in returned text/errors. |
| src/utils.ts | Adds readOutputArg() and serpApiResult() to standardize md/json tool outputs and apply markdown truncation + wrapping. |
| src/serpapi-search-provider.ts | Forces web_search provider to always request structured JSON (output: "json"). |
| src/tools/amazon.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/amazon-product.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/autocomplete.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/bing.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/duckduckgo.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/ebay.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/ebay-product.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/events.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/facebook-profile.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/finance.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/flights.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/hotels.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/immersive-product.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/instagram-profile.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/jobs.ts | Adds output override + truncates markdown results table to count. |
| src/tools/lens.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/maps.ts | Adds output override + truncates markdown results table to count. |
| src/tools/maps-reviews.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/news.ts | Adds output override + truncates markdown results table to count. |
| src/tools/scholar.ts | Adds output override + truncates markdown results table to count. |
| src/tools/shopping.ts | Adds output override + truncates markdown results table to count. |
| src/tools/trends.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/tripadvisor.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/walmart.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/walmart-product.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/weather.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/yahoo.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/youtube.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/youtube-video.ts | Adds output override support and routes responses through serpApiResult(). |
| src/tools/youtube-transcript.ts | Adds output override support and routes responses through serpApiResult(). |
| skills/serpapi/SKILL.md | Documents the new default markdown behavior and override options. |
| README.md | Documents the response format setting and breaking change. |
| openclaw.plugin.json | Adds schema + UI hints for webSearch.format. |
| package.json | Bumps version to 0.2.0. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+32
to
+34
| function isTableSeparator(line: string): boolean { | ||
| return /^\|?[\s:|-]+\|[\s:|-]*$/.test(line.trim()) && line.includes("-"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SerpApi now supports markdown output via the
output=mdparameter — an LLM-optimized rendering that consumes significantly fewer tokens than raw JSON.This PR makes markdown the default response format for all 30 specialized
serpapi_*tools, with two escape hatches:plugins.entries.serpapi.config.webSearch.format—"md"(default) or"json"outputargument ("md"/"json")Changes
src/config.ts—resolveSerpApiFormat()reads theformatsetting. Defaults to"md", case-insensitive; invalid values throw instead of silently falling back.src/markdown.ts(new) —limitResultTable(), a line-based port of hermes-plugin'smarkdown.py: truncates the results table under a named heading (e.g."News Results") to the requestedcountrows while leaving front-matter, pagination, and other sections untouched.src/serpapi-client.ts—callSerpApireturnsRecord<string, unknown> | string: sendsoutput=mdand returns raw text for markdown; JSON path unchanged. Response text is redacted of the API key. Markdown payloads are wrapped under__serpapi_markdownfor the record-based shared cache; the cache key includes the format, so md/json entries can't poison each other.src/utils.ts—serpApiResult(): markdown responses are wrapped withwrapWebContent(the SDK's untrusted-content security markers) and returned under a singlemarkdownfield; JSON keeps the previous structured shape.outputoverride; the five tools withcount(news, jobs, maps, scholar, shopping) truncate the markdown results table tocountrows.web_searchprovider — hardcoded tooutput: "json". Its contract (results[],count/maxResults) is structured, so markdown does not apply — same as hermes-plugin's provider.openclaw.plugin.json—configSchema(enum: ["md", "json"],default: "md") anduiHintsfor the new setting.0.2.0.Breaking change
serpapi_*tools now return{ markdown: "..." }by default instead of the structured fields. Setformat: "json"(or passoutput: "json"per call) to restore the previous behavior.