官方更新 Google Developers Blog 正文 ok 913 words

借助 Google Developer Knowledge API 生态系统全面提升开发效率

英文标题:Supercharge your development with the Google Developer Knowledge API ecosystem

Google 正式以公开预览形式推出 Developer Knowledge API 及 MCP Server,为 Google Cloud、Firebase、Android 等产品提供权威、机器可读且持续更新的开发者文档访问能力。该生态包含 gcloud CLI、Agent skill、API Explorer 及多语言客户端库,可支持终端查询、AI Agent、IDE 和生产后端系统。API 提供语义与关键词搜索、文档分块、基于官方文档的问答及批量获取能力,旨在减少模型知识截止日期导致的幻觉并优化 Token 使用。对开发者而言,这意味着无需依赖脆弱的网页抓取,即可将最新 Google 技术文档直接接入编码助手、CI/CD 流程和企业知识机器人。
打开原文相关 8 · 机会 5
media11.7 KB media394.6 KB media53.3 KB media47.0 KB media424.3 KB media122.8 KB

中文

如果你在 Google Cloud 上构建 AI Agent 或开发者工具,就不必再依赖脆弱的网页抓取,也不必艰难应对 LLM 过时的训练知识截止日期。

借助 Google Developer Knowledge API 生态系统更快、更智能、更有把握地进行开发。该生态包括 gcloud CLI 界面、官方 Agent skill、API Explorer 和多语言客户端库。无论你是在命令行终端中操作、向 AI Agent 提示、以交互方式测试请求,还是编写生产软件,这些工具都能交付 Google 文档。


什么是 Developer Knowledge API?

Developer Knowledge API 是 Google 面向 Google Cloud、Firebase、Android 等产品开发者文档的官方、可编程权威信息源。它专为现代 AI Agent、IDE 扩展和自动化工作流设计,以提供最新 Markdown 格式文档的结构化 API,取代脆弱的网页抓取方式。

该 API 提供语义搜索和关键词搜索、智能文档分块以及基于依据的问答能力,可确保你的 Agent 和开发者工具保持准确并提高 Token 效率。

Developer Knowledge API 会被频繁建立索引,以确保可预测的检索、文档的新鲜度,以及上游更新到 Agent 可访问之间的最小延迟。

通过 Developer Knowledge API 的各类接口,开发者和 AI Agent 可以在终端、IDE 和后端代码库中发现、检索并整合基于 Google 官方文档的答案。

gcloud CLI

Developer Knowledge API gcloud CLI 界面将官方文档搜索、检索和基于依据的问答集成到你的命令行环境中。它预装在 Cloud Shell 中,并可在 Linux、macOS 和 Windows 上的标准 Google Cloud SDK 安装环境中运行,无需额外插件或配置。

主要能力和命令:

  • answer-query**:**在终端中获取有据可依的答案。
  • documents search-chunks**:搜索 Google 文档中的文档片段和分块。
  • documents describe**:获取指定文档的元数据和内容。

示例:

# 获取有据可依的答案
gcloud developer-knowledge answer-query --query="How do I create a BigQuery dataset?"

# 搜索文档分块
gcloud developer-knowledge documents search-chunks --query="Firestore transactions"

# 获取指定文档的元数据和内容
gcloud developer-knowledge documents describe "documents/docs.cloud.google.com/storage/docs/creating-buckets"

# 通过将错误追踪信息直接管道传输到 answer-query 命令来排查问题
gcloud developer-knowledge answer-query --query="$(cat error.txt)"

Shell

如需开始使用 gcloud CLI,请参阅 gcloud CLI 快速入门。

Agent skill

Developer Knowledge Agent skill 在 AI 编码助手与 Google 文档生态系统之间建立连接,使自主工具能够访问最新技术规范。

主要优势

  • **依据支撑与减少幻觉:**为 AI 编码助手和 Agent 工作流提供最新 Google 开发者文档访问能力,减少由过时 LLM 训练知识截止日期导致的幻觉。
  • **优化 Token 与上下文使用:**采用多步骤检索工作流——先使用 searchDocumentChunks 检查代码和文档分块,再通过 documents.get 获取完整 Markdown 页面;或者使用 answerQuery 直接提供有据可依的答案。
  • **广泛的工具兼容性:**通过标准 MCP 集成支持 Google Antigravity、Claude Code、Cursor、GitHub Copilot 和自定义 Agent 框架。该 skill 会指导你的助手使用 Developer Knowledge MCP server(或通过 curl 回退至 REST API)。

配置 Agent skill

在终端中运行以下 CLI 辅助命令以配置该 skill:

npx skills add google/skills --skill retrieving-developer-knowledge

Shell

该命令会在你的项目中安装 Developer Knowledge Agent skill。该 skill 会指导你的助手使用 Developer Knowledge MCP server(或使用 curl 回退至 REST API)。

如需在 IDE 中连接 MCP Server,或通过 Application Default Credentials 或 API key 配置身份验证,请参阅连接到 Developer Knowledge MCP server。

客户端库

客户端库 可让你将文档检索、搜索和基于依据的答案生成嵌入生产系统、自动化 CI/CD 管道和企业知识机器人中。

主要优势:

  • **编程访问:**提供对 AnswerQuery、SearchDocumentChunks、GetDocument 和 BatchGetDocuments 的编程访问。
  • **符合语言惯例的集成:**提供针对每种受支持语言生态系统定制的原生类型定义、构建器模式、错误处理和异步执行能力。
  • 批处理与效率:BatchGetDocuments 等方法支持在一次 API 调用中检索最多 20 份文档。
  • **企业级安全性和可靠性:**支持 Google Cloud Application Default Credentials、自动重试和结构化引文追踪。

支持的语言:

请按照快速入门配置环境、安装库,并开始检索开发者文档。

代码示例:

以下示例展示了 AI Agent 如何使用 Python 客户端库获取最新产品发布说明,确保其回答基于训练知识截止日期之后的数据:

from google.cloud import developer_knowledge_v1

def FetchMyProductReleaseNotes(my_product_name: str) -> str:
    """Fetches the latest release notes to bridge a model's knowledge cutoff."""
    # Initialize the Developer Knowledge API client
    my_api_client = developer_knowledge_v1.DeveloperKnowledgeClient()

    # Formulate a targeted query for the specific product's release notes
    my_search_query = f"{my_product_name} latest release notes"
    my_request = developer_knowledge_v1.SearchDocumentChunksRequest(
        query=my_search_query,
    )

    # Retrieve and return the relevant documentation chunks
    my_response = my_api_client.search_document_chunks(request=my_request)

    # Extract the chunk text
    my_release_notes = [my_chunk.text for my_chunk in my_response.chunks]
    return "\n".join(my_release_notes)

# Example usage:
# my_latest_notes = FetchMyProductReleaseNotes("Firestore")

Python

适用于各类任务的代码示例:

APIs Explorer

用于 Developer Knowledge API 的 Google APIs Explorer 提供集成在 Google 开发者网站中的交互式零代码界面,可用于试验和验证 API 请求及响应结构。

通过 APIs Explorer,你可以测试以下核心端点:

后续步骤

准备好将 Google 开发者文档集成到你的工作流和 AI 工具中了吗?以下是几种入门方式:

  • **如果你已经安装 gcloud CLI:**可以立即通过 gcloud CLI 界面 查询官方文档。
  • **如果你尚未安装 gcloud CLI:**可将 Agent skill 提供给你的 AI 编码助手或 Agent,以启用基于依据的检索。

English / 原文

If you build AI agents or developer tools on Google Cloud, stop relying on brittle web-scraping or wrestling with stale LLM training cutoffs.

Build faster, smarter, and with greater confidence using the Google Developer Knowledge API ecosystem, including our gcloud CLI surface, an official agent skill, API Explorer, and multi-language client libraries. Whether you are operating in a command-line terminal, prompting an AI agent, testing requests interactively, or writing production software, our tools deliver Google documentation.


What is the Developer Knowledge API?

The Developer Knowledge API is Google's official, programmatic source of truth for developer documentation about Google Cloud, Firebase, Android, and more. Designed specifically for modern AI agents, IDE extensions, and automated workflows, it replaces brittle web-scraping with a structured API that serves fresh, Markdown-formatted documentation.

By offering semantic and keyword search, intelligent document chunking, and grounded Q&A capabilities, the API ensures your agents and developer tools remain accurate and token-efficient.

The Developer Knowledge API is indexed frequently to ensure predictable retrieval, fresh documentation, and minimal lag between upstream updates and agent access.

With the Developer Knowledge API interfaces, developers and AI agents can discover, retrieve, and synthesize answers grounded in official Google documentation across terminals, IDEs, and backend codebases.

gcloud CLI

The Developer Knowledge API gcloud CLI surface integrates official documentation search, retrieval, and grounded Q&A into your command-line environment. It comes pre-installed in Cloud Shell and works across standard Google Cloud SDK installations on Linux, macOS, and Windows without requiring extra plugins or configuration.

Key capabilities and commands:

  • answer-query: Get grounded answers in your terminal.
  • documents search-chunks: Search document snippets and chunks across Google documentation.
  • documents describe: Retrieve metadata and content for a specific document.

Examples:

# Get grounded answers
gcloud developer-knowledge answer-query --query="How do I create a BigQuery dataset?"

# Search document chunks
gcloud developer-knowledge documents search-chunks --query="Firestore transactions"

# Retrieve metadata and content for a specific document
gcloud developer-knowledge documents describe "documents/docs.cloud.google.com/storage/docs/creating-buckets"

# Troubleshoot an error trace by piping it directly into the answer-query command
gcloud developer-knowledge answer-query --query="$(cat error.txt)"

Shell

To get started with the gcloud CLI, see the gcloud CLI Quickstart.

Agent skill

The Developer Knowledge agent skill establishes a link between AI coding assistants and Google's documentation ecosystem, enabling autonomous tools to access up-to-date technical specifications.

Key Benefits

  • Grounding & reduced hallucinations: Provides AI coding assistants and agentic workflows access to up-to-date Google developer documentation, reducing hallucinations from stale LLM training cutoffs.
  • Optimized token & context usage: Uses a multi-step retrieval workflow—inspecting code and documentation chunks using searchDocumentChunks first before fetching complete Markdown pages with documents.get, or delivering grounded answers using answerQuery.
  • Broad tooling compatibility: Uses the standard MCP integration across Google Antigravity, Claude Code, Cursor, GitHub Copilot, and custom agentic frameworks. The skill instructs your assistant how to use the Developer Knowledge MCP server (or fall back to the REST API via curl).

Configure the agent skill

Configure the skill by running the following CLI helper command in your terminal:

npx skills add google/skills --skill retrieving-developer-knowledge

Shell

This command installs the Developer Knowledge agent skill in your project. The skill instructs your assistant how to use the Developer Knowledge MCP server (or fall back to the REST API using curl).

To connect to the MCP server in your IDE, or to configure authentication with Application Default Credentials or an API key, see Connect to the Developer Knowledge MCP server.

Client libraries

The client libraries let you embed documentation retrieval, search, and grounded answer generation into production systems, automated CI/CD pipelines, and enterprise knowledge bots.

Key benefits:

  • Programmatic access: Provides programmatic access to AnswerQuery, SearchDocumentChunks, GetDocument, and BatchGetDocuments.
  • Idiomatic integration: Native type definitions, builder patterns, error handling, and asynchronous execution tailored to each supported language ecosystem.
  • Batching and efficiency: Methods like BatchGetDocuments enable retrieving up to 20 documents in a single API call.
  • Enterprise security and reliability: Support for Google Cloud Application Default Credentials, automatic retries, and structured citation tracking.

Supported languages:

Get started by following the Quickstart to set up your environment, install a library, and start retrieving developer documentation.

Code examples:

The following example demonstrates how an AI agent can use the Python client library to fetch the latest product release notes, ensuring its responses are grounded in data beyond its training cutoff:

from google.cloud import developer_knowledge_v1

def FetchMyProductReleaseNotes(my_product_name: str) -> str:
    """Fetches the latest release notes to bridge a model's knowledge cutoff."""
    # Initialize the Developer Knowledge API client
    my_api_client = developer_knowledge_v1.DeveloperKnowledgeClient()

    # Formulate a targeted query for the specific product's release notes
    my_search_query = f"{my_product_name} latest release notes"
    my_request = developer_knowledge_v1.SearchDocumentChunksRequest(
        query=my_search_query,
    )

    # Retrieve and return the relevant documentation chunks
    my_response = my_api_client.search_document_chunks(request=my_request)

    # Extract the chunk text
    my_release_notes = [my_chunk.text for my_chunk in my_response.chunks]
    return "\n".join(my_release_notes)

# Example usage:
# my_latest_notes = FetchMyProductReleaseNotes("Firestore")

Python

Code examples across various tasks:

APIs Explorer

The Google APIs Explorer for the Developer Knowledge API offers an interactive, zero-code interface integrated into Google's developer site, enabling experimentation and verification of API requests and response structures.

Through the APIs Explorer, you can test the following core endpoints:

Next steps

Ready to integrate Google developer documentation into your workflows and AI tools? Here are a few ways to get started:

  • If you already have the gcloud CLI: You can start querying official documentation right away using the gcloud CLI surface.
  • If you don't have the gcloud CLI: Give the agent skill to your AI coding assistant or agent to enable grounded retrieval.