AgentSkillsCN

wikipedia

利用 Wikipedia API 进行标题搜索、摘要提取、全文摘录、相关页面及媒体资源获取。

SKILL.md
--- frontmatter
name: wikipedia
description: Use Wikipedia APIs for title search, summaries, full text extracts, related pages and media.
always: false

Use this skill when the user asks for Wikipedia facts, summaries, related pages, or media links.

Workflow:

  1. Pick language (default en).
  2. Normalize titles:
    • trim spaces
    • replace spaces with _
    • URL encode when needed
  3. If the title is uncertain → search first.
  4. Use action_run_command with curl -s <url>.
  5. Retry once using search if a page endpoint fails.
  6. Return concise results with the final Wikipedia URL.

Supported endpoint patterns:

  • Search titles: https://{language}.wikipedia.org/w/rest.php/v1/search/title?q={query}&limit={limit}
  • Summary: https://{language}.wikipedia.org/api/rest_v1/page/summary/{title}
  • Full text extract (JSON): https://{language}.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&explaintext=1&redirects=1&titles={title}
  • Related pages: https://{language}.wikipedia.org/api/rest_v1/page/related/{title}
  • Media list: https://{language}.wikipedia.org/api/rest_v1/page/media-list/{title}
  • Random summary: https://{language}.wikipedia.org/api/rest_v1/page/random/summary

When to use each endpoint:

  • Search titles → when user gives a topic/name but title may be wrong or ambiguous.
  • Summary → default for “who is / what is”.
  • Full text extract → when user asks for full article or detailed info.
  • Related pages → when user asks for similar or connected topics.
  • Media list → when user asks for images/media.
  • Random summary → when user asks for a random Wikipedia article.

Input expectations:

  • Search requires query; optional limit (default 5).
  • Page endpoints require title.

Canonical article link format: https://{language}.wikipedia.org/wiki/{Title_With_Underscores}

Error handling:

  • If HTTP status is not 200:
    1. Run title search using the same input.
    2. Retry the page endpoint using the top result title.
    3. If still failing, return a short failure reason and show search results.