Skip to content

REST API Reference

REST API 参考

This page provides a reference for the REST API provided by ADK web server. For details on using the ADK REST API in practice, see Use the API Server.

本页面提供了 ADK Web 服务器提供的 REST API 参考。有关实际使用 ADK REST API 的详细信息,请参阅使用 API 服务器

Tip

You can view an updated API reference on a running ADK web server by browsing to the /docs location, for example at: http://localhost:8000/docs

提示

您可以通过浏览正在运行的 ADK Web 服务器上的 /docs 位置查看更新的 API 参考文档,例如:http://localhost:8000/docs

Endpoints

端点

/run

This endpoint executes an agent run. It takes a JSON payload with the details of the run and returns a list of events generated during the run.

此端点执行智能体运行。它接受包含运行详细信息的 JSON 负载,并返回运行期间生成的事件列表。

Request Body

请求正文

The request body should be a JSON object with the following fields:

请求正文应是一个包含以下字段的 JSON 对象:

  • app_name (string, required): The name of the agent to run.
  • app_name (字符串,必填): 要运行的智能体的名称。
  • user_id (string, required): The ID of the user.
  • user_id (字符串,必填): 用户的 ID。
  • session_id (string, required): The ID of the session.
  • session_id (字符串,必填): 会话的 ID。
  • new_message (Content, required): The new message to send to the agent. See the Content section for more details.
  • new_message (Content,必填): 要发送给智能体的新消息。有关更多详细信息,请参阅 Content 部分。
  • streaming (boolean, optional): Whether to use streaming. Defaults to false.
  • streaming (布尔值,可选): 是否使用流式传输。默认为 false
  • state_delta (object, optional): A delta of the state to apply before the run.
  • state_delta (对象,可选): 在运行之前应用的状态增量。

Response Body

响应正文

The response body is a JSON array of Event objects.

响应正文是 Event 对象的 JSON 数组。

/run_sse

This endpoint executes an agent run using Server-Sent Events (SSE) for streaming responses. It takes the same JSON payload as the /run endpoint.

此端点使用服务器发送事件 (SSE) 执行智能体运行以进行流式响应。它接受与 /run 端点相同的 JSON 负载。

Request Body

请求正文

The request body is the same as for the /run endpoint.

请求正文与 /run 端点相同。

Response Body

响应正文

The response is a stream of Server-Sent Events. Each event is a JSON object representing an Event.

响应是服务器发送事件流。每个事件是代表 Event 的 JSON 对象。

Objects

对象

Content object

The Content object represents the content of a message. It has the following structure:

Content 对象表示消息的内容。它具有以下结构:

{
  "parts": [
    {
      "text": "..."
    }
  ],
  "role": "..."
}
  • parts: A list of parts. Each part can be either text or a function call.
  • parts: 部分的列表。每个部分可以是文本或函数调用。
  • role: The role of the author of the message (e.g., "user", "model").
  • role: 消息作者的角色(例如,"user"、"model")。

Event object

The Event object represents an event that occurred during an agent run. It has a complex structure with many optional fields. The most important fields are:

Event 对象表示智能体运行期间发生的事件。它具有许多可选字段的复杂结构。最重要的字段是:

  • id: The ID of the event.
  • id: 事件的 ID。
  • timestamp: The timestamp of the event.
  • timestamp: 事件的时间戳。
  • author: The author of the event.
  • author: 事件的作者。
  • content: The content of the event.
  • content: 事件的内容。