From 5f210abebe492cce658f79bfe4f46cb0d7b1194d Mon Sep 17 00:00:00 2001 From: hanfengfu Date: Fri, 27 Nov 2026 09:57:48 +0800 Subject: [PATCH 1/2] docs: expose Tunnel and OAuth MCP guides in site navigation --- README.en.md | 16 ++++++---------- README.md | 16 ++++++---------- README.zh-CN.md | 16 ++++++---------- docs-site/content/docs/framework/index.en.mdx | 9 +++++++++ docs-site/content/docs/framework/index.mdx | 9 +++++++++ docs-site/content/docs/framework/meta.en.json | 10 +++++++++- docs-site/content/docs/framework/meta.json | 10 +++++++++- tests/test_public_release_positioning.py | 14 ++++++++++++++ 8 files changed, 68 insertions(+), 32 deletions(-) diff --git a/README.en.md b/README.en.md index e168563a1..c84bc3069 100644 --- a/README.en.md +++ b/README.en.md @@ -104,16 +104,12 @@ Agent Kernel centralizes trusted control, Harness owns composition and lifecycle ## Docs And Examples -- Documentation: -- Quick Start: -- Why KsADK: -- Architecture: -- Ecosystem Positioning: -- Observability: -- Cloud Deployment: -- Hosted UI and Event Replay: -- Environment Variables: -- Samples: +[Documentation home](https://kingsoftcloud.github.io/ksadk-python/) — browse the full guides and references. + +- **Getting started**: [Quick start](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/quickstart/) · [Why KsADK](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/why-ksadk/) · [Architecture](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/architecture/) · [Ecosystem positioning](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/comparison/) +- **Core capabilities**: [Tool tunnel](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/tool-tunnel/) · [OAuth / API key MCP](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/channel-connector/) +- **Deployment and operations**: [Cloud deployment](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/cloud-deployment/) · [Observability](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/observability-tracing/) · [Hosted UI and event replay](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/hosted-ui-events/) · [Environment variables](https://kingsoftcloud.github.io/ksadk-python/en/docs/references/environment-variables/) · [0.8.8 upgrade guide](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/upgrade-0-8-8/) +- **Examples**: [Sample repository](https://github.com/kingsoftcloud/ksadk-samples) ## Related Projects diff --git a/README.md b/README.md index 4155a2e1c..6e2c3db94 100644 --- a/README.md +++ b/README.md @@ -104,16 +104,12 @@ Agent Kernel 收口可信控制,Harness 管理装配与生命周期,可插 ## 文档与样例 -- 文档: -- 快速开始: -- 为什么需要 KsADK: -- 架构: -- 生态定位对比: -- 可观测: -- 云端部署: -- Hosted UI 与事件回放: -- 环境变量: -- 样例仓库: +[文档首页](https://kingsoftcloud.github.io/ksadk-python/):完整使用手册与参考文档。 + +- **入门**:[快速开始](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/quickstart/) · [为什么需要 KsADK](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/why-ksadk/) · [架构](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/architecture/) · [生态定位对比](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/comparison/) +- **核心能力**:[Tunnel 工具隧道](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/tool-tunnel/) · [OAuth / API Key MCP](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/channel-connector/) +- **部署与运维**:[云端部署](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/cloud-deployment/) · [可观测](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/observability-tracing/) · [Hosted UI 与事件回放](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/hosted-ui-events/) · [环境变量](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/environment-variables/) · [0.8.8 升级指南](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/upgrade-0-8-8/) +- **样例**:[样例仓库](https://github.com/kingsoftcloud/ksadk-samples) ## 相关项目 diff --git a/README.zh-CN.md b/README.zh-CN.md index cc26cb1aa..91a4553e3 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -101,16 +101,12 @@ Agent Kernel 收口可信控制,Harness 管理装配与生命周期,可插 ## 文档与样例 -- 文档: -- 快速开始: -- 为什么需要 KsADK: -- 架构: -- 生态定位对比: -- 可观测: -- 云端部署: -- Hosted UI 与事件回放: -- 环境变量: -- 样例仓库: +[文档首页](https://kingsoftcloud.github.io/ksadk-python/):完整使用手册与参考文档。 + +- **入门**:[快速开始](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/quickstart/) · [为什么需要 KsADK](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/why-ksadk/) · [架构](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/architecture/) · [生态定位对比](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/comparison/) +- **核心能力**:[Tunnel 工具隧道](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/tool-tunnel/) · [OAuth / API Key MCP](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/channel-connector/) +- **部署与运维**:[云端部署](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/cloud-deployment/) · [可观测](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/observability-tracing/) · [Hosted UI 与事件回放](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/hosted-ui-events/) · [环境变量](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/environment-variables/) · [0.8.8 升级指南](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/upgrade-0-8-8/) +- **样例**:[样例仓库](https://github.com/kingsoftcloud/ksadk-samples) ## 相关项目 diff --git a/docs-site/content/docs/framework/index.en.mdx b/docs-site/content/docs/framework/index.en.mdx index 62b820f61..3ba36b6ef 100644 --- a/docs-site/content/docs/framework/index.en.mdx +++ b/docs-site/content/docs/framework/index.en.mdx @@ -42,11 +42,20 @@ pip install -U "ksadk[all]" ## Events, interoperability, and delivery + + + +## Upgrade and migration + + + + + ## Find the exact contract diff --git a/docs-site/content/docs/framework/index.mdx b/docs-site/content/docs/framework/index.mdx index 21f147912..072ba008a 100644 --- a/docs-site/content/docs/framework/index.mdx +++ b/docs-site/content/docs/framework/index.mdx @@ -41,11 +41,20 @@ pip install -U "ksadk[all]" ## 事件、互操作与交付 + + + +## 升级与迁移 + + + + + ## 查找精确契约 diff --git a/docs-site/content/docs/framework/meta.en.json b/docs-site/content/docs/framework/meta.en.json index 2ba863816..a8760b27a 100644 --- a/docs-site/content/docs/framework/meta.en.json +++ b/docs-site/content/docs/framework/meta.en.json @@ -28,7 +28,11 @@ "guides/attachments-multimodal", "guides/workspace-files", "---[Network]Events and Interoperability---", + "guides/agui-a2ui", + "guides/mcp-oauth", + "guides/tool-tunnel", "guides/hosted-ui-events", + "guides/channel-connector", "guides/a2a-runtime", "---[Cloud]Build and Deploy---", "guides/managed-runtime", @@ -37,6 +41,10 @@ "guides/runtime-products", "---[Wrench]Operations and Maintenance---", "guides/observability-tracing", - "guides/web-ui-source" + "guides/web-ui-source", + "guides/integration-0-8-7", + "guides/upgrade-0-8-8", + "guides/upgrade-0-8-7", + "guides/upgrade-0-8-6" ] } diff --git a/docs-site/content/docs/framework/meta.json b/docs-site/content/docs/framework/meta.json index 611dc352a..9653459b2 100644 --- a/docs-site/content/docs/framework/meta.json +++ b/docs-site/content/docs/framework/meta.json @@ -28,7 +28,11 @@ "guides/attachments-multimodal", "guides/workspace-files", "---[Network]统一事件与互操作---", + "guides/agui-a2ui", + "guides/mcp-oauth", + "guides/tool-tunnel", "guides/hosted-ui-events", + "guides/channel-connector", "guides/a2a-runtime", "---[Cloud]构建与部署---", "guides/managed-runtime", @@ -37,6 +41,10 @@ "guides/runtime-products", "---[Wrench]运维与维护---", "guides/observability-tracing", - "guides/web-ui-source" + "guides/web-ui-source", + "guides/integration-0-8-7", + "guides/upgrade-0-8-8", + "guides/upgrade-0-8-7", + "guides/upgrade-0-8-6" ] } diff --git a/tests/test_public_release_positioning.py b/tests/test_public_release_positioning.py index bf2622347..c3cc4f357 100644 --- a/tests/test_public_release_positioning.py +++ b/tests/test_public_release_positioning.py @@ -277,6 +277,20 @@ def navigation_identity(entry: str) -> str: assert "fallbackLanguage: null" in i18n_config +def test_framework_sidebar_includes_every_listed_capability_guide(): + # The framework root flattens guide entries; the child menu alone does not + # expose a page in the rendered sidebar. + for metadata in ("meta.json", "meta.en.json"): + root = DOCS_CONTENT_ROOT / "framework" + sidebar = json.loads((root / metadata).read_text())["pages"] + guides = json.loads((root / "guides" / metadata).read_text())["pages"] + missing = [ + page for page in guides + if not page.startswith("---") and f"guides/{page}" not in sidebar + ] + assert not missing, f"{metadata}: guides hidden from framework sidebar: {missing}" + + def test_docs_navigation_exposes_the_083_user_journeys(): chinese = _read("docs-site/content/docs/framework/meta.json") english = _read("docs-site/content/docs/framework/meta.en.json") From 111423af41e2ecd5c91388e85a00cad79e1bfa8b Mon Sep 17 00:00:00 2001 From: hanfengfu Date: Fri, 27 Nov 2026 11:07:20 +0800 Subject: [PATCH 2/2] docs: publish verified Agent Web API reference in Pages --- README.en.md | 1 + README.md | 1 + README.zh-CN.md | 1 + .../docs/references/agent-web-api.en.mdx | 885 +++++++++++++++++ .../content/docs/references/agent-web-api.mdx | 891 ++++++++++++++++++ .../content/docs/references/index.en.mdx | 1 + docs-site/content/docs/references/index.mdx | 1 + .../content/docs/references/meta.en.json | 1 + docs-site/content/docs/references/meta.json | 1 + .../docs/references/remote-runtime-api.en.mdx | 2 + .../docs/references/remote-runtime-api.mdx | 2 + tests/test_public_release_positioning.py | 38 + 12 files changed, 1825 insertions(+) create mode 100644 docs-site/content/docs/references/agent-web-api.en.mdx create mode 100644 docs-site/content/docs/references/agent-web-api.mdx diff --git a/README.en.md b/README.en.md index c84bc3069..c6e3cc676 100644 --- a/README.en.md +++ b/README.en.md @@ -109,6 +109,7 @@ Agent Kernel centralizes trusted control, Harness owns composition and lifecycle - **Getting started**: [Quick start](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/quickstart/) · [Why KsADK](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/why-ksadk/) · [Architecture](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/architecture/) · [Ecosystem positioning](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/getting-started/comparison/) - **Core capabilities**: [Tool tunnel](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/tool-tunnel/) · [OAuth / API key MCP](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/channel-connector/) - **Deployment and operations**: [Cloud deployment](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/cloud-deployment/) · [Observability](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/observability-tracing/) · [Hosted UI and event replay](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/hosted-ui-events/) · [Environment variables](https://kingsoftcloud.github.io/ksadk-python/en/docs/references/environment-variables/) · [0.8.8 upgrade guide](https://kingsoftcloud.github.io/ksadk-python/en/docs/framework/guides/upgrade-0-8-8/) +- **API reference**: [Agent Web API](https://kingsoftcloud.github.io/ksadk-python/en/docs/references/agent-web-api/) - **Examples**: [Sample repository](https://github.com/kingsoftcloud/ksadk-samples) ## Related Projects diff --git a/README.md b/README.md index 6e2c3db94..5f62c0f61 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ Agent Kernel 收口可信控制,Harness 管理装配与生命周期,可插 - **入门**:[快速开始](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/quickstart/) · [为什么需要 KsADK](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/why-ksadk/) · [架构](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/architecture/) · [生态定位对比](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/comparison/) - **核心能力**:[Tunnel 工具隧道](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/tool-tunnel/) · [OAuth / API Key MCP](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/channel-connector/) - **部署与运维**:[云端部署](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/cloud-deployment/) · [可观测](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/observability-tracing/) · [Hosted UI 与事件回放](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/hosted-ui-events/) · [环境变量](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/environment-variables/) · [0.8.8 升级指南](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/upgrade-0-8-8/) +- **接口参考**:[Agent Web API](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/agent-web-api/) - **样例**:[样例仓库](https://github.com/kingsoftcloud/ksadk-samples) ## 相关项目 diff --git a/README.zh-CN.md b/README.zh-CN.md index 91a4553e3..5379abf69 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -106,6 +106,7 @@ Agent Kernel 收口可信控制,Harness 管理装配与生命周期,可插 - **入门**:[快速开始](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/quickstart/) · [为什么需要 KsADK](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/why-ksadk/) · [架构](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/architecture/) · [生态定位对比](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/getting-started/comparison/) - **核心能力**:[Tunnel 工具隧道](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/tool-tunnel/) · [OAuth / API Key MCP](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/mcp-oauth/) · [AG-UI / A2UI](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/agui-a2ui/) · [A2A](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/a2a-runtime/) · [Channel Connector](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/channel-connector/) - **部署与运维**:[云端部署](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/cloud-deployment/) · [可观测](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/observability-tracing/) · [Hosted UI 与事件回放](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/hosted-ui-events/) · [环境变量](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/environment-variables/) · [0.8.8 升级指南](https://kingsoftcloud.github.io/ksadk-python/cn/docs/framework/guides/upgrade-0-8-8/) +- **接口参考**:[Agent Web API](https://kingsoftcloud.github.io/ksadk-python/cn/docs/references/agent-web-api/) - **样例**:[样例仓库](https://github.com/kingsoftcloud/ksadk-samples) ## 相关项目 diff --git a/docs-site/content/docs/references/agent-web-api.en.mdx b/docs-site/content/docs/references/agent-web-api.en.mdx new file mode 100644 index 000000000..ca0cc5843 --- /dev/null +++ b/docs-site/content/docs/references/agent-web-api.en.mdx @@ -0,0 +1,885 @@ +--- +title: "Agent Web API" +description: "Sessions, runs, history, interactions, files, feedback, and MCP OAuth for Agent chat interfaces" +--- + +## Overview + +Use this reference to build an Agent chat interface: initialize capabilities, manage sessions, read history, run conversations, resume execution, handle interactions, access files, submit feedback, and complete MCP OAuth authorization. Optional file-preview and native-terminal endpoints are documented separately. + +Paths are relative to the Agent access URL supplied by the service. Read the capabilities first and use only features declared by the current deployment. + +## Requests and authentication + +| Item | Convention | +| --- | --- | +| Base URL | Use the access URL provided by the Agent service | +| Authentication | Automation clients supply Authorization: Bearer API_KEY as required by the service; browser clients may use an established access session | +| JSON | Content-Type: application/json | +| Streaming | Accept: text/event-stream and Stream=true where required | +| Upload | multipart/form-data; the HTTP client generates the boundary | +| Field names | JSON and query parameter names are case-sensitive | + +AgentId, UserId, and SessionId locate resources but do not grant authorization. Request, session, invocation, run, checkpoint, and model-response IDs have distinct meanings and are not interchangeable. + +## Responses and errors + +Ordinary JSON Actions use this success envelope: + +```json +{"Code":0,"Message":"Success","RequestId":"req-example","Action":"CreateSession","Data":{"Session":{"SessionId":"session-example","AgentId":"agent-example","UserId":"user-example"}}} +``` + +Data depends on the operation. MCP OAuth success responses do not guarantee RequestId or Action. Downloads return raw bytes; SSE is an incremental event stream rather than one JSON response. + +| Result | Client handling | +| --- | --- | +| HTTP 400 / 422 | Check fields, types, bounds, and field combinations | +| HTTP 401 / 403 | Re-establish a valid access session or correct permissions; do not blindly replay operations | +| HTTP 404 | Check identifiers, ownership, and whether the feature is enabled | +| HTTP 409 | Refresh revision or history state; changing an idempotency key is not a safe automatic retry | +| HTTP 429 | Handle rate or queue limits using the service retry guidance | +| HTTP 503 / 504 | Retry eligible reads; establish the outcome of a write before repeating it | +| HTTP 200 with Code other than 0 | Treat as a business failure and inspect Message, ReasonCode, or detail | + +Errors may use Message, ReasonCode, detail, or error. An expired browser access session can also produce an HTML 401/403 response; do not treat it as normal API JSON. + +## Endpoint directory + +| Method and path | Purpose | +| --- | --- | +| `POST /agentengine/api/v1/GetAgentUiBootstrap` | Get UI capabilities | +| `POST /agentengine/api/v1/ListAgentModels` | List models | +| `POST /agentengine/api/v1/CreateSession` | Create a session | +| `POST /agentengine/api/v1/ListSessions` | List sessions | +| `POST /agentengine/api/v1/GetSession` | Get a session | +| `POST /agentengine/api/v1/DeleteSession` | Delete a session | +| `POST /agentengine/api/v1/ListSessionMessages` | Read chat history | +| `POST /agentengine/api/v1/ListSessionEvents` | Read session events | +| `POST /agentengine/api/v1/RunAgent` | Run an Agent | +| `GET /agentengine/api/v1/SubscribeRunEvents` | Subscribe to run events | +| `POST /agentengine/api/v1/CancelRun` | Cancel a run | +| `POST /agentengine/api/v1/ListSessionCheckpoints` | List checkpoints | +| `POST /agentengine/api/v1/GetCheckpointResumePreview` | Preview checkpoint recovery | +| `POST /agentengine/api/v1/ResumeRun` | Resume a run | +| `POST /agentengine/api/v1/ListToolReceipts` | List tool receipts | +| `POST /agentengine/api/v1/SubmitInteraction` | Submit an interaction | +| `POST /agentengine/api/v1/UploadFile` | Upload an attachment | +| `GET /agentengine/api/v1/AttachmentContent` | Download an attachment | +| `POST /agentengine/api/v1/ListWorkspaceFiles` | List workspace files | +| `POST /agentengine/api/v1/AddWorkspaceFile` | Upload a workspace file | +| `POST /agentengine/api/v1/DeleteWorkspaceFile` | Delete a workspace file | +| `GET /agentengine/api/v1/GetWorkspaceFileContent` | Download a workspace file | +| `GET /agentengine/api/v1/ExportWorkspaceZip` | Export a workspace directory | +| `POST /agentengine/api/v1/GetResponseFeedback` | Get response feedback | +| `POST /agentengine/api/v1/UpsertResponseFeedback` | Save response feedback | +| `POST /agentengine/api/v1/DeleteResponseFeedback` | Delete response feedback | +| `POST /agentengine/api/v1/GetMcpAuthorizationWait` | Get authorization state | +| `POST /agentengine/api/v1/OpenMcpAuthorization` | Open authorization | +| `POST /agentengine/api/v1/RetryMcpAuthorization` | Retry authorization | +| `POST /agentengine/api/v1/RetryMcpConnection` | Retry MCP connection | +| `POST /agentengine/api/v1/CancelMcpAuthorizationWait` | Cancel authorization wait | +| `POST /agentengine/agui` | AG-UI conversation | + +Identifiers in the examples are placeholders; replace them with values returned by your service. + +## Initialization + +### Get UI capabilities + +`POST /agentengine/api/v1/GetAgentUiBootstrap` + +Initialize the client with Agent identity, available chat transports, history, recovery, file, OAuth, and terminal capabilities. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | + +Example request: + +```json +{"AgentId":"agent-example"} +``` + +**Response:** Data.Agent contains Agent metadata; Capabilities contains feature declarations; HostedChat contains available transports; ApiFormats lists output formats; WorkspaceFiles describes file capabilities; SessionBackend describes session storage. + +Use Capabilities to decide which controls to display. Obtain the AG-UI Endpoint from HostedChat.Transports. + +### List models + +`POST /agentengine/api/v1/ListAgentModels` + +Read the available model catalog and current selection. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `Name` | body | `string / null` | No | `null` | Compatibility field; the current model catalog is determined by the Agent runtime configuration. | + +Example request: + +```json +{"AgentId":"agent-example"} +``` + +**Response:** Data.Models is the model array; Current is the current model; Source identifies the catalog origin. + +## Sessions and history + +### Create a session + +`POST /agentengine/api/v1/CreateSession` + +Create a session. An explicitly supplied existing SessionId is handled according to the service session policy. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `"user"` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | + +Example request: + +```json +{"AgentId":"agent-example"} +``` + +**Response:** Data.Session is a Session object. + +### List sessions + +`POST /agentengine/api/v1/ListSessions` + +Read sessions for an Agent using page-based pagination. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `Page` | body | `integer` | No | `1` | Page number, starting at 1. minimum 1. | +| `PageSize` | body | `integer` | No | `20` | Number of sessions per page. minimum 1; maximum 1000. | + +Example request: + +```json +{"AgentId":"agent-example","Page":1,"PageSize":20} +``` + +**Response:** Data contains Sessions, Total, Page, and PageSize; it may also include DataSource, Degraded, and SessionContractVersion. + +Keep AgentId, UserId, and PageSize consistent across pages. Omitting UserId does not grant cross-user access. + +### Get a session + +`POST /agentengine/api/v1/GetSession` + +Read session metadata and its current or most recent run information. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**Response:** Data.Session is a Session object. + +### Delete a session + +`POST /agentengine/api/v1/DeleteSession` + +Delete a session and associated records, cancelling its outstanding detached streams. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**Response:** Data.Deleted is true on successful deletion. + +### Read chat history + +`POST /agentengine/api/v1/ListSessionMessages` + +Read projected chat messages, with backward pagination and incremental queries. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `AfterSeqId` | body | `integer / null` | No | `null` | Read events or messages after this sequence number. minimum 0. | +| `BeforeSeqId` | body | `integer / null` | No | `null` | Read events or messages before this sequence number. minimum 1. | +| `Limit` | body | `integer` | No | `50` | Maximum number of returned items. minimum 1; maximum 200. | +| `IncludeReasoning` | body | `boolean` | No | `false` | Include reasoning content that the service permits returning. | +| `IncludeToolEvents` | body | `boolean` | No | `false` | Include tool execution events. | +| `IncludeAttachments` | body | `boolean` | No | `true` | Include attachment metadata. | +| `HistoryEpoch` | body | `string / null` | No | `null` | History epoch returned by the preceding response. | +| `CursorSource` | body | `string / null` | No | `null` | Cursor source returned by the preceding response. allowed runtime, control. | +| `SnapshotSeqId` | body | `integer / null` | No | `null` | History snapshot sequence returned by the preceding response. minimum 0. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","Limit":50,"IncludeReasoning":false} +``` + +**Response:** Data contains SessionId, Messages, LatestSeqId, HasMore, NextCursor, and history context such as HistoryEpoch, SnapshotSeqId, and CursorSource. + +Reuse the returned CursorSource, HistoryEpoch, and SnapshotSeqId. When the service requires a history reload, discard the old cursor before querying again. + +### Read session events + +`POST /agentengine/api/v1/ListSessionEvents` + +Read events for progress recovery, tool results, and the event timeline. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `CheckpointIds` | body | `array` | No | `[]` | Filter by checkpoint identifiers. | +| `EventTypes` | body | `array` | No | `[]` | Filter by event type; an empty array disables this filter. | +| `Offset` | body | `integer / null` | No | `null` | Result offset, starting at 0. minimum 0. | +| `Limit` | body | `integer` | No | `200` | Maximum number of returned items. minimum 1; maximum 2000. | +| `AfterSeqId` | body | `integer / null` | No | `null` | Read events or messages after this sequence number. minimum 0. | +| `BeforeSeqId` | body | `integer / null` | No | `null` | Read events or messages before this sequence number. minimum 1. | +| `EventOrder` | body | `string / null` | No | `null` | Event ordering. | +| `CursorSource` | body | `string / null` | No | `null` | Cursor source returned by the preceding response. allowed runtime, control. | +| `HistoryEpoch` | body | `string / null` | No | `null` | History epoch returned by the preceding response. | +| `SnapshotSeqId` | body | `integer / null` | No | `null` | History snapshot sequence returned by the preceding response. minimum 0. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","AfterSeqId":0,"Limit":200} +``` + +**Response:** Data contains Events, Total, Offset, Limit, and optional HasMore and history context. + +Events can represent tool activity, status changes, or interactions; do not append every raw event as a chat message. + +## Conversations and runs + +### Run an Agent + +`POST /agentengine/api/v1/RunAgent` + +Execute a conversation turn synchronously, as SSE, or in a supported background mode. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `Messages` | body | `array` | No | `[]` | Message array containing role and content. | +| `UserId` | body | `string / null` | No | `"user"` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `AccountId` | body | `string / null` | No | `null` | Account correlation identifier; not an authentication credential. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | +| `InvocationId` | body | `string / null` | No | `null` | Invocation identifier used for event subscription and cancellation. | +| `ApiFormat` | body | `string` | No | `"responses"` | Output format: responses or chat_completions. | +| `Stream` | body | `boolean` | No | `false` | Request SSE output. | +| `Background` | body | `boolean` | No | `false` | Request background execution when supported. | +| `Model` | body | `string / null` | No | `null` | Model identifier selected from the model catalog. | +| `ModelMetadata` | body | `object / null` | No | `null` | Model capability metadata. | +| `ModelOptions` | body | `object / null` | No | `null` | Inference options supported by the selected model. | +| `Metadata` | body | `object / null` | No | `null` | Additional request metadata; it does not grant identity or permissions. | +| `ResponsesInput` | body | `JSON value / null` | No | `null` | Responses-style input, including multimodal or continuation input. | +| `PreviousResponseId` | body | `string / null` | No | `null` | Identifier of the preceding Responses response. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","InvocationId":"inv-example","Messages":[{"role":"user","content":"Hello"}],"ApiFormat":"responses","Stream":true} +``` + +**Response:** A synchronous foreground call wraps a Responses or Chat Completions result in Data. Streaming branches return SSE. See execution modes below. + +For ordinary foreground streaming set Stream=true. Use Background=true only when the service declares support. Messages and ResponsesInput follow the selected input protocol; continuation input may also require PreviousResponseId. Disconnecting HTTP does not itself cancel a run; use CancelRun to stop it. + +| Execution mode | Response | +| --- | --- | +| Synchronous foreground | JSON Action; Data contains a model response | +| Streaming foreground | SSE, including possible failure or interaction-wait events | +| Background returning a handle | JSON Action; Data contains SessionId, InvocationId, Status, Background, SubscribeUrl | +| Kernel-admitted streaming or background | SSE using Responses event projection; a JSON handle is not guaranteed | + +### Subscribe to run events + +`GET /agentengine/api/v1/SubscribeRunEvents` + +Subscribe to incremental events for one session and invocation after reconnecting or starting a background run. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | query | `string` | Yes | `—` | Session identifier. | +| `InvocationId` | query | `string` | Yes | `—` | Invocation identifier used for event subscription and cancellation. | +| `AfterSeqId` | query | `integer` | No | `0` | Read events or messages after this sequence number. | +| `AgentId` | query | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | query | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | + +Example request: + +```http +GET /agentengine/api/v1/SubscribeRunEvents?SessionId=session-example&InvocationId=inv-example&AfterSeqId=0 +Authorization: Bearer +``` + +**Response:** text/event-stream. Each data frame contains a SessionEvent; data: [DONE] terminates the subscription. SSE comments beginning with a colon are heartbeats. + +### Cancel a run + +`POST /agentengine/api/v1/CancelRun` + +Request cancellation by InvocationId. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | +| `InvocationId` | body | `string` | Yes | `—` | Invocation identifier used for event subscription and cancellation. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","InvocationId":"inv-example"} +``` + +**Response:** Data.Cancelled indicates cancellation was requested or accepted; Found indicates whether a run was located; Status and RuntimeCancelStatus describe the cancellation state. Cancelled=true does not guarantee the task has already stopped. + +Use the actual InvocationId. Requests carrying a trusted business identity must also provide AgentId and SessionId; other requests should provide both to scope cancellation. A response ID or CheckpointId cannot replace InvocationId. + +## Recovery and interactions + +### List checkpoints + +`POST /agentengine/api/v1/ListSessionCheckpoints` + +Read checkpoints for an Agent or selected sessions, filtered by recovery conditions. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `SessionId` | body | `array / string / null` | No | `null` | Session identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `CheckpointId` | body | `array / string / null` | No | `null` | Checkpoint identifier returned by the checkpoint listing. | +| `RunId` | body | `string / null` | No | `null` | Run identifier. | +| `OnlyResumable` | body | `boolean` | No | `false` | Return only resumable checkpoints. | +| `Framework` | body | `string / null` | No | `null` | Filter by framework. | +| `ResumeStatus` | body | `array` | No | `[]` | Filter by resume status. | +| `ResumeTypes` | body | `array` | No | `[]` | Filter by resume type. | +| `Offset` | body | `integer / null` | No | `null` | Result offset, starting at 0. minimum 0. | +| `Limit` | body | `integer` | No | `100` | Maximum number of returned items. minimum 1; maximum 1000. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","OnlyResumable":true} +``` + +**Response:** Data contains Checkpoints, Total, ResumableTotal, and HasResumableCheckpoint. + +### Preview checkpoint recovery + +`POST /agentengine/api/v1/GetCheckpointResumePreview` + +Check whether a checkpoint can be resumed and inspect blocking reasons before submitting recovery. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `RunId` | body | `string` | Yes | `—` | Run identifier. | +| `CheckpointId` | body | `string` | Yes | `—` | Checkpoint identifier returned by the checkpoint listing. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","CheckpointId":"checkpoint-example"} +``` + +**Response:** Data.Preview contains the recovery preview and admission result. + +### Resume a run + +`POST /agentengine/api/v1/ResumeRun` + +Resume execution from the specified session checkpoint. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `RunId` | body | `string` | Yes | `—` | Run identifier. | +| `CheckpointId` | body | `string` | Yes | `—` | Checkpoint identifier returned by the checkpoint listing. | +| `ResumeAttemptId` | body | `string / null` | No | `null` | Identifier for one resume attempt; reuse it when retrying the same attempt. | +| `InvocationId` | body | `string / null` | No | `null` | Invocation identifier used for event subscription and cancellation. | +| `Stream` | body | `boolean` | No | `false` | Request SSE output. | +| `Background` | body | `boolean` | No | `false` | Request background execution when supported. | +| `Model` | body | `string / null` | No | `null` | Model identifier selected from the model catalog. | +| `ModelMetadata` | body | `object / null` | No | `null` | Model capability metadata. | +| `ModelOptions` | body | `object / null` | No | `null` | Inference options supported by the selected model. | +| `Metadata` | body | `object / null` | No | `null` | Additional request metadata; it does not grant identity or permissions. | +| `ResumeInstructionEnabled` | body | `boolean` | No | `false` | Enable an additional resume instruction. | +| `ResumeInstruction` | body | `string / null` | No | `null` | Instruction accompanying the resume request. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","CheckpointId":"checkpoint-example","ResumeAttemptId":"resume-example","Stream":true} +``` + +**Response:** Synchronous execution returns a JSON Action result; normal streaming recovery returns SSE. Background recovery returns a handle containing SessionId, RunId, CheckpointId, ResumeAttemptId, InvocationId, Status, Background, and SubscribeUrl. An already-processed retry can return Status=already_processed and AlreadyProcessed=true. A terminal checkpoint can return Status=noop and Reason. These branches can return JSON even when Stream=true; inspect Content-Type. + +Call GetCheckpointResumePreview first. Use a new ResumeAttemptId for a distinct recovery attempt and keep it unchanged for retries of that same attempt. + +### List tool receipts + +`POST /agentengine/api/v1/ListToolReceipts` + +Read tool receipts associated with a run or checkpoint. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `RunId` | body | `string / null` | No | `null` | Run identifier. | +| `CheckpointId` | body | `string / null` | No | `null` | Checkpoint identifier returned by the checkpoint listing. | +| `Offset` | body | `integer` | No | `0` | Result offset, starting at 0. minimum 0. | +| `Limit` | body | `integer` | No | `200` | Maximum number of returned items. minimum 1; maximum 500. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**Response:** Data contains ToolReceipts, Total, Offset, and Limit. An uncertain receipt does not make replaying a side-effecting operation safe. + +### Submit an interaction + +`POST /agentengine/api/v1/SubmitInteraction` + +Submit an approval, rejection, structured answer, or cancellation decision. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `UserId` | body | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `RunId` | body | `string` | Yes | `—` | Run identifier. | +| `InteractionId` | body | `string` | Yes | `—` | Identifier of the pending interaction. | +| `ExpectedRevision` | body | `integer` | Yes | `—` | Current interaction or authorization-wait revision. minimum 1. | +| `InteractionAction` | body | `string` | Yes | `—` | Decision: approve, reject, submit, or cancel. allowed approve, reject, submit, cancel. | +| `Response` | body | `JSON value` | No | `null` | Any valid JSON value; structured submission must explicitly include this field. | +| `IdempotencyKey` | body | `string` | Yes | `—` | Idempotency key; keep it unchanged when retrying the same submission. minLength 1; maxLength 256. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","InteractionId":"interaction-example","ExpectedRevision":1,"InteractionAction":"approve","Response":null,"IdempotencyKey":"interaction-example-approve"} +``` + +**Response:** Data is a command receipt with schema_version, command_id, status, and conditionally message_id, run_id, accepted_seq, or error. + +This compatibility endpoint requires an active local Kernel; hosted deployments use their authorized interaction ingress. InteractionAction accepts approve, reject, submit, or cancel. Action is also accepted as a compatibility decision field. submit must explicitly include Response, including when its value is null. Use the current ExpectedRevision and preserve IdempotencyKey on retries. An accepted receipt can return HTTP 202 and a duplicate HTTP 200; accepted/duplicate means admitted, not fully executed. + +## Attachments and workspace + +### Upload an attachment + +`POST /agentengine/api/v1/UploadFile` + +Upload an image or document to obtain a reference usable in a later message. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `file` | form | `binary` | Yes | `—` | File content to upload. | + +Example request: + +```bash +curl --fail-with-body "$BASE_URL/agentengine/api/v1/UploadFile" -H "Authorization: Bearer $API_KEY" -F "file=@./example.txt" +``` + +**Response:** Data.FileData contains fileUri, displayName, mimeType, and sizeBytes. + +### Download an attachment + +`GET /agentengine/api/v1/AttachmentContent` + +Read content referenced by an uploaded file URI. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `FileUri` | query | `string` | Yes | `—` | File reference returned by UploadFile. | +| `SessionId` | query | `string / null` | No | `null` | Session identifier. | +| `AgentId` | query | `string / null` | No | `null` | Target Agent identifier. | +| `UserId` | query | `string / null` | No | `null` | Logical user identifier; authorization is still enforced by the authenticated identity. | + +Example request: + +```http +GET /agentengine/api/v1/AttachmentContent?FileUri=file-example +Authorization: Bearer +``` + +**Response:** Raw file bytes. Render or save according to Content-Type; do not parse an Action envelope. + +Use the exact fileUri returned by UploadFile, not an arbitrary file path or external URL. Isolated attachments may require AgentId or SessionId to locate their access scope. + +### List workspace files + +`POST /agentengine/api/v1/ListWorkspaceFiles` + +Read entries in a workspace directory. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `Path` | body | `string` | No | `"."` | Path relative to the workspace root. | +| `Recursive` | body | `boolean` | No | `false` | Include entries in subdirectories. | + +Example request: + +```json +{"AgentId":"agent-example","Path":".","Recursive":false} +``` + +**Response:** Data includes directory information and an Entries array. Entries contain Name, Path, Type, SizeBytes, MimeType, and ModifiedAt. + +### Upload a workspace file + +`POST /agentengine/api/v1/AddWorkspaceFile` + +Write a file to a relative workspace path. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `file` | form | `binary` | Yes | `—` | File content to upload. | +| `AgentId` | form | `string / null` | No | `null` | Target Agent identifier. | +| `Path` | form | `string` | Yes | `—` | Path relative to the workspace root. | + +Example request: + +```bash +curl --fail-with-body "$BASE_URL/agentengine/api/v1/AddWorkspaceFile" -H "Authorization: Bearer $API_KEY" -F "file=@./example.txt" -F "Path=notes/example.txt" +``` + +**Response:** Data.Entry contains Path, Name, Type, SizeBytes, MimeType, and ModifiedAt. + +Use multipart/form-data and let the HTTP client generate the boundary. Path is the destination relative path; file carries the content. + +### Delete a workspace file + +`POST /agentengine/api/v1/DeleteWorkspaceFile` + +Delete a file at a relative workspace path. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `Path` | body | `string` | Yes | `—` | Path relative to the workspace root. | + +Example request: + +```json +{"AgentId":"agent-example","Path":"notes/example.txt"} +``` + +**Response:** Data.Deleted is true on success. + +### Download a workspace file + +`GET /agentengine/api/v1/GetWorkspaceFileContent` + +Read raw workspace file content for document, image, or text previews. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `FilePath` | query | `string` | Yes | `—` | Relative workspace path of the requested file. | +| `AgentId` | query | `string / null` | No | `null` | Target Agent identifier. | + +Example request: + +```http +GET /agentengine/api/v1/GetWorkspaceFileContent?FilePath=notes%2Fexample.txt +Authorization: Bearer +``` + +**Response:** Raw file bytes. Use Content-Type and the returned Content-Disposition to render or save the response. + +FilePath is relative to the workspace; absolute paths and traversal outside the workspace are not allowed. + +### Export a workspace directory + +`GET /agentengine/api/v1/ExportWorkspaceZip` + +Export a workspace directory as a ZIP archive. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | query | `string / null` | No | `null` | Target Agent identifier. | +| `Path` | query | `string` | No | `"."` | Path relative to the workspace root. | + +Example request: + +```http +GET /agentengine/api/v1/ExportWorkspaceZip?Path=. +Authorization: Bearer +``` + +**Response:** ZIP bytes returned as an attachment. + +## Feedback + +### Get response feedback + +`POST /agentengine/api/v1/GetResponseFeedback` + +Read feedback for an assistant response. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `ResponseId` | body | `string` | Yes | `—` | Identifier of the assistant response receiving feedback. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example"} +``` + +**Response:** Data.Feedback contains the feedback object or null when none exists. + +### Save response feedback + +`POST /agentengine/api/v1/UpsertResponseFeedback` + +Create or update an up/down rating and feedback text. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `ResponseId` | body | `string` | Yes | `—` | Identifier of the assistant response receiving feedback. | +| `Rating` | body | `string` | Yes | `—` | Feedback rating: up or down. | +| `Comment` | body | `string / null` | No | `""` | Feedback text. | +| `EventId` | body | `string / null` | No | `null` | Related event identifier. | +| `TraceId` | body | `string / null` | No | `null` | Related trace identifier. | +| `RootSpanId` | body | `string / null` | No | `null` | Related root-span identifier. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example","Rating":"up","Comment":"Helpful answer"} +``` + +**Response:** Data.Feedback contains the saved feedback object. + +Rating accepts only up or down. ResponseId must identify an actual assistant response in the session. + +### Delete response feedback + +`POST /agentengine/api/v1/DeleteResponseFeedback` + +Remove feedback for an assistant response. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | Yes | `—` | Target Agent identifier. | +| `SessionId` | body | `string` | Yes | `—` | Session identifier. | +| `ResponseId` | body | `string` | Yes | `—` | Identifier of the assistant response receiving feedback. | + +Example request: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example"} +``` + +**Response:** Data.Deleted indicates whether an existing feedback record was removed. + +## MCP OAuth + +Use these operations only when the service advertises MCP authorization. Local and hosted authorization state is not interchangeable. The service manages credentials; do not send secrets or access tokens as chat messages. + +| Method and path | Purpose | +| --- | --- | +| `POST /agentengine/api/v1/GetMcpAuthorizationWait` | Read the current authorization wait and its permitted actions. | +| `POST /agentengine/api/v1/OpenMcpAuthorization` | Obtain the browser authorization URL for a pending MCP connection. | +| `POST /agentengine/api/v1/RetryMcpAuthorization` | Restart authorization after a failed or denied attempt when allowed. | +| `POST /agentengine/api/v1/RetryMcpConnection` | Retry the connection while valid credentials are still available. | +| `POST /agentengine/api/v1/CancelMcpAuthorizationWait` | Cancel the wait and prevent a late callback from continuing that wait. | + +All five operations accept these fields: + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `WaitId` | body | `string` | Yes | `—` | Current MCP authorization-wait identifier. minLength 1; maxLength 64. | +| `ExpectedRevision` | body | `integer / null` | No | `null` | Current interaction or authorization-wait revision. minimum 1. | +| `AgentId` | body | `string / null` | No | `null` | Target Agent identifier. | +| `SessionId` | body | `string / null` | No | `null` | Session identifier. | +| `IdempotencyKey` | body | `string / null` | No | `null` | Optional compatibility field. This group checks state using ExpectedRevision and does not promise deduplication by this field. | + +Query example: + +```json +{"WaitId":"wait-example","AgentId":"agent-example","SessionId":"session-example"} +``` + +For open, retry, or cancel, pass the revision obtained from the current state: + +```json +{"WaitId":"wait-example","ExpectedRevision":1,"AgentId":"agent-example","SessionId":"session-example"} +``` + +| Data field | Type | Meaning | +| --- | --- | --- | +| wait_id / run_id / config_id | string | Wait, run, and connection identifiers | +| revision | integer | Current revision for subsequent operations | +| status | string | Current authorization/connection state | +| display_name | string | MCP service display name | +| scopes | string[] | Requested authorization scopes | +| allowed_actions | string[] | Actions currently permitted | +| requires_resume | boolean | Whether continuation is associated with the wait | +| deadline | number | Wait deadline in Unix seconds | +| error | string / null | Failure reason | +| authorization_url | string, optional | Browser URL returned by OpenMcpAuthorization | + +allowed_actions values query, open, retry_authorization, retry_connection, and cancel correspond to the five operations above. Perform only currently permitted actions. Refresh state after the browser completes actual authorization. A cancelled wait must not be completed by a late callback. A state conflict can return HTTP 409 with ReasonCode; refresh before deciding the next action. + +## AG-UI conversation + +`POST /agentengine/agui` is the default endpoint; prefer the AG-UI Endpoint declared in HostedChat.Transports. + +Send standard AG-UI input to receive text, tools, state, and structured interactions. A2UI cards are carried by messages/events and do not require a separate A2UI HTTP API. + +| Parameter | Location | Type | Required | Default | Description | +| --- | --- | --- | --- | --- | --- | +| `threadId` | body | `string` | Yes | `—` | AG-UI conversation identifier. | +| `runId` | body | `string` | Yes | `—` | AG-UI run identifier. | +| `protocolVersion` | body | `string / null` | No | `null` | AG-UI protocol version. | +| `parentRunId` | body | `string / null` | No | `null` | Parent run identifier. | +| `state` | body | `JSON value / null` | No | `null` | Initial or current graph state. | +| `messages` | body | `array` | Yes | `—` | AG-UI message array. | +| `tools` | body | `array / null` | No | `null` | Client tool declarations. | +| `context` | body | `array / null` | No | `null` | Context entries. | +| `forwardedProps` | body | `JSON value / null` | No | `null` | Additional Agent properties. | +| `resume` | body | `array / null` | No | `null` | Responses for pending interactions. | + +**Response:** text/event-stream. Process the AG-UI start, text, tool, state, interaction, completion, and error events. + +messages contains AG-UI messages; tools contains tool declarations; context contains context entries; forwardedProps carries additional properties. threadId associates the session and runId identifies the AG-UI run. Do not substitute IDs from another transport. If AG-UI is unavailable, choose an allowed transport from the capability response. + +## Shared response objects + +### Session + +| Field | Meaning | +| --- | --- | +| SessionId / AgentId / UserId | Session and ownership identifiers | +| Title / TitleSource / Summary | Title, title source, and summary | +| FirstPrompt / LastPrompt | First and latest user-input previews | +| ActiveInvocationId / ActiveRunStatus | Current or most recent invocation and run state | +| ActiveRunMode / ActiveRunTrigger | Execution mode and trigger | +| CreatedAt / UpdatedAt / Version | Creation/update time in Unix seconds and integer version | +| State | Publicly permitted session state | +| Continuity | Runtime continuity information | + +### Message + +| Field | Meaning | +| --- | --- | +| MessageId / Role / Content | Message identifier, role, and content | +| Timestamp / SeqId / InvocationId | Time, sequence, and invocation | +| Reasoning / Blocks | Permitted reasoning and ordered content blocks | +| ToolEvents | Tool execution and approval state | +| Attachments | References, names, media types, sizes, and access URLs | + +### SessionEvent + +| Field | Meaning | +| --- | --- | +| EventId / SessionId | Event and session identifiers | +| Author / EventType | Producer and event type | +| Content | Event-type-specific payload | +| Timestamp / SeqId | Time and sequence | +| InvocationId | Associated invocation when available | + +### Feedback + +| Field | Meaning | +| --- | --- | +| AgentId / SessionId / ResponseId | Feedback target | +| Rating / Comment | up/down rating and text | +| EventId / TraceId / RootSpanId | Related event and trace | +| CreatedAt / UpdatedAt | Creation and update timestamps | + +## SSE conventions + +Use an incremental HTTP reader and split frames on blank lines. One network chunk is not one JSON object. Lines beginning with a colon are comments/heartbeats. SubscribeRunEvents data frames contain events and [DONE] ends that subscription. Non-Kernel RunAgent streams follow ApiFormat; Kernel streams use named Responses events such as response.completed, response.failed, and response.canceled. An interaction can produce response.incomplete and close the foreground stream; connection closure is not necessarily success. Parse AG-UI streams according to AG-UI. + +Reconnect using the same SessionId, InvocationId, and the last confirmed AfterSeqId. Do not replay user input to simulate continuation. HTTP 200 alone does not mean the streamed run succeeded. + +## Optional file previews and local native terminals + +Use these endpoints only when enabled. Native terminals are not a generic remote shell for every hosted user. + +### File preview resource + +`GET /_ksadk/workspace/v1/files/{file_path}` + +file_path is relative to the workspace and may contain multiple segments. URL-encode segments separately. Render returned bytes using Content-Type; HTML previews can resolve their relative assets through the same workspace path. + +### Create or reuse a terminal session + +`POST /_ksadk/terminal/sessions` + +| Parameter | Type | Required | Default | Meaning | +| --- | --- | --- | --- | --- | +| session_id | string | No | empty | Associated chat session | +| mode | string | No | tui | Terminal mode supported by the runtime | +| cols / rows | integer | No | 80 / 24 | Terminal dimensions | +| force_new | boolean | No | false | Force a new terminal session | +| cwd | string | No | unspecified | Working directory subject to runtime restrictions | + +```json +{"session_id":"session-example","mode":"tui","cols":80,"rows":24,"force_new":false} +``` + +Returns `{"session":{...}}`. Use terminal_session_id from that object for attachment and closure. + +### List terminal sessions + +`GET /_ksadk/terminal/sessions` + +Optional query fields session_id and mode filter the result. Returns `{"sessions":[...]}`. + +### Close a terminal session + +`DELETE /_ksadk/terminal/sessions/{terminal_session_id}` + +Returns deleted and terminal_session_id. A missing session can return HTTP 404. + +### Attach terminal WebSocket + +`WS /_ksadk/terminal/ws?terminal_session_id=` + +Use WSS for a remote secure connection and negotiate Sec-WebSocket-Protocol: ks-terminal.v1. The terminal identifier comes from session creation. Stop on a capability or identity denial; do not attempt to bypass authorization. diff --git a/docs-site/content/docs/references/agent-web-api.mdx b/docs-site/content/docs/references/agent-web-api.mdx new file mode 100644 index 000000000..be2f7d283 --- /dev/null +++ b/docs-site/content/docs/references/agent-web-api.mdx @@ -0,0 +1,891 @@ +--- +title: "Agent Web API" +description: "Agent 聊天界面的会话、运行、历史、交互、文件、反馈和 MCP OAuth 接口参考" +--- + +## 概述 + +本手册用于为 Agent 构建聊天界面,涵盖界面初始化、会话、消息历史、对话运行、恢复与交互、附件、工作区、反馈和 MCP OAuth 授权。文件预览与本地原生终端作为按需启用的扩展单独说明。 + +所有路径均相对于服务提供的 Agent 访问地址。调用前先获取界面能力,只使用当前服务声明支持的功能。 + +## 请求与认证 + +| 项目 | 约定 | +| --- | --- | +| 访问地址 | 使用 Agent 服务提供的访问地址,不自行拼接平台内部域名 | +| API 认证 | 自动化客户端按访问服务要求携带 `Authorization: Bearer `;浏览器可使用已建立的访问会话 | +| JSON 请求 | `Content-Type: application/json` | +| 流式请求 | `Accept: text/event-stream`,并按接口要求设置 `Stream=true` | +| 上传文件 | `multipart/form-data`,由 HTTP 客户端生成 boundary | +| 字段命名 | JSON 与 Query 字段名区分大小写 | + +AgentId、UserId、SessionId 等用于定位资源,不代替身份认证和授权。请求 ID、会话 ID、InvocationId、RunId、CheckpointId 和模型响应 ID 的用途不同,不能互相替换。 + +## 响应与错误 + +普通 JSON Action 成功响应采用以下结构: + +```json +{ "Code": 0, "Message": "Success", "RequestId": "req-example", "Action": "CreateSession", "Data": { "Session": { "SessionId": "session-example", "AgentId": "agent-example", "UserId": "user-example" } } } +``` + +`Data` 的内容由具体接口定义。MCP OAuth 成功响应不保证带有 RequestId 和 Action。文件下载返回原始字节;SSE 不使用整包 JSON 响应。 + +| 错误情况 | 客户端处理 | +| --- | --- | +| HTTP 400 / 422 | 检查参数、类型、范围和字段组合 | +| HTTP 401 / 403 | 重新建立合法访问会话或检查权限;不要自动重试业务操作 | +| HTTP 404 | 检查资源标识、会话归属和当前功能是否启用 | +| HTTP 429 | 请求或队列受限;按服务返回的重试提示处理 | +| HTTP 409 | 刷新交互版本、授权状态或历史上下文;不能直接更换幂等键重复提交 | +| HTTP 503 / 504 | 后端暂不可用或查询超时;根据错误原因重试读取,确认写操作结果后再决定是否重发 | +| HTTP 200 且 Code 非 0 | 业务失败;读取 Message、ReasonCode 或 detail | + +非成功响应可能使用 `Message`、`ReasonCode`、`detail` 或 `error` 返回错误信息。浏览器访问会话失效时也可能收到 HTML 401/403 页面;不能把它当作正常 API JSON。 + +## 接口目录 + +| 类别 | 方法与路径 | 用途 | +| --- | --- | --- | +| 初始化 | `POST /agentengine/api/v1/GetAgentUiBootstrap` | 获取界面能力 | +| 初始化 | `POST /agentengine/api/v1/ListAgentModels` | 获取模型目录 | +| 会话与历史 | `POST /agentengine/api/v1/CreateSession` | 创建会话 | +| 会话与历史 | `POST /agentengine/api/v1/ListSessions` | 查询会话列表 | +| 会话与历史 | `POST /agentengine/api/v1/GetSession` | 获取会话 | +| 会话与历史 | `POST /agentengine/api/v1/DeleteSession` | 删除会话 | +| 会话与历史 | `POST /agentengine/api/v1/ListSessionMessages` | 读取聊天历史 | +| 会话与历史 | `POST /agentengine/api/v1/ListSessionEvents` | 读取会话事件 | +| 对话与运行 | `POST /agentengine/api/v1/RunAgent` | 执行对话 | +| 对话与运行 | `GET /agentengine/api/v1/SubscribeRunEvents` | 续订运行事件 | +| 对话与运行 | `POST /agentengine/api/v1/CancelRun` | 取消运行 | +| 恢复与交互 | `POST /agentengine/api/v1/ListSessionCheckpoints` | 查询恢复点 | +| 恢复与交互 | `POST /agentengine/api/v1/GetCheckpointResumePreview` | 预览恢复操作 | +| 恢复与交互 | `POST /agentengine/api/v1/ResumeRun` | 恢复运行 | +| 恢复与交互 | `POST /agentengine/api/v1/ListToolReceipts` | 查询工具回执 | +| 恢复与交互 | `POST /agentengine/api/v1/SubmitInteraction` | 提交交互结果 | +| 附件与工作区 | `POST /agentengine/api/v1/UploadFile` | 上传附件 | +| 附件与工作区 | `GET /agentengine/api/v1/AttachmentContent` | 下载附件 | +| 附件与工作区 | `POST /agentengine/api/v1/ListWorkspaceFiles` | 列出工作区文件 | +| 附件与工作区 | `POST /agentengine/api/v1/AddWorkspaceFile` | 上传工作区文件 | +| 附件与工作区 | `POST /agentengine/api/v1/DeleteWorkspaceFile` | 删除工作区文件 | +| 附件与工作区 | `GET /agentengine/api/v1/GetWorkspaceFileContent` | 下载工作区文件 | +| 附件与工作区 | `GET /agentengine/api/v1/ExportWorkspaceZip` | 导出工作区 | +| 消息反馈 | `POST /agentengine/api/v1/GetResponseFeedback` | 读取消息反馈 | +| 消息反馈 | `POST /agentengine/api/v1/UpsertResponseFeedback` | 保存消息反馈 | +| 消息反馈 | `POST /agentengine/api/v1/DeleteResponseFeedback` | 删除消息反馈 | +| MCP OAuth | `POST /agentengine/api/v1/GetMcpAuthorizationWait` | 读取授权状态 | +| MCP OAuth | `POST /agentengine/api/v1/OpenMcpAuthorization` | 打开授权 | +| MCP OAuth | `POST /agentengine/api/v1/RetryMcpAuthorization` | 重试授权 | +| MCP OAuth | `POST /agentengine/api/v1/RetryMcpConnection` | 重试连接 | +| MCP OAuth | `POST /agentengine/api/v1/CancelMcpAuthorizationWait` | 取消授权等待 | +| AG-UI | `POST /agentengine/agui`(默认地址) | 标准 AG-UI 对话与结构化交互 | + +请求示例中的 agent-example、session-example 等均为占位标识。实际调用时使用服务返回的值。 + +## 初始化 + +### 获取界面能力 + +`POST /agentengine/api/v1/GetAgentUiBootstrap` + +获取 Agent 信息、可用聊天传输、文件、历史和恢复能力。客户端初始化时调用。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | + +请求示例: + +```json +{"AgentId":"agent-example"} +``` + +**返回**:Agent 为 Agent 基本信息;Capabilities 为能力声明;HostedChat 为可用聊天传输;ApiFormats 为支持的输出格式;WorkspaceFiles 为文件能力;SessionBackend 为会话后端信息。 + +先根据 Capabilities 判断是否展示交互、恢复、文件、OAuth 和终端功能。AG-UI 的实际地址从 HostedChat.Transports 中获取。 + +### 获取模型目录 + +`POST /agentengine/api/v1/ListAgentModels` + +获取当前 Agent 可选择的模型及当前模型。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `Name` | body | `string / null` | 否 | `null` | 兼容字段;当前模型列表由 Agent 的运行配置决定。 | + +请求示例: + +```json +{"AgentId":"agent-example"} +``` + +**返回**:Models 为模型数组;Current 为当前模型;Source 为模型目录来源。 + +## 会话与历史 + +### 创建会话 + +`POST /agentengine/api/v1/CreateSession` + +创建会话;指定已有 SessionId 时按服务端会话策略处理。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `"user"` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | + +请求示例: + +```json +{"AgentId":"agent-example"} +``` + +**返回**:Session:会话对象,结构见公共返回对象。 + +### 查询会话列表 + +`POST /agentengine/api/v1/ListSessions` + +分页读取指定 Agent 的会话列表。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `Page` | body | `integer` | 否 | `1` | 页码,从 1 开始。 最小 1。 | +| `PageSize` | body | `integer` | 否 | `20` | 每页条数。 最小 1;最大 1000。 | + +请求示例: + +```json +{"AgentId":"agent-example","Page":1,"PageSize":20} +``` + +**返回**:Sessions:会话数组;Total:会话总数;Page:当前页;PageSize:每页条数。可附带 DataSource、Degraded、SessionContractVersion。 + +同一翻页序列使用一致的 AgentId、UserId 和 PageSize。不要把分页查询中省略 UserId 等同于获得跨用户访问权限。 + +### 获取会话 + +`POST /agentengine/api/v1/GetSession` + +读取指定会话的元数据和当前运行信息。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**返回**:Session:会话对象。 + +### 删除会话 + +`POST /agentengine/api/v1/DeleteSession` + +删除会话及关联记录,并取消该会话仍在进行的后台流。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**返回**:Deleted:删除成功时为 true。 + +### 读取聊天历史 + +`POST /agentengine/api/v1/ListSessionMessages` + +读取适合聊天界面展示的消息投影,支持向前翻页和增量读取。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `AfterSeqId` | body | `integer / null` | 否 | `null` | 只读取该序号之后的事件或消息。 最小 0。 | +| `BeforeSeqId` | body | `integer / null` | 否 | `null` | 只读取该序号之前的事件或消息。 最小 1。 | +| `Limit` | body | `integer` | 否 | `50` | 最多返回条数。 最小 1;最大 200。 | +| `IncludeReasoning` | body | `boolean` | 否 | `false` | 是否包含可返回的推理内容。 | +| `IncludeToolEvents` | body | `boolean` | 否 | `false` | 是否包含工具执行事件。 | +| `IncludeAttachments` | body | `boolean` | 否 | `true` | 是否包含附件信息。 | +| `HistoryEpoch` | body | `string / null` | 否 | `null` | 使用服务端上次返回的历史版本标识。 | +| `CursorSource` | body | `string / null` | 否 | `null` | 使用服务端上次返回的游标来源。 取值 runtime, control。 | +| `SnapshotSeqId` | body | `integer / null` | 否 | `null` | 使用服务端上次返回的历史快照序号。 最小 0。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","Limit":50,"IncludeReasoning":false} +``` + +**返回**:SessionId:会话标识;Messages:消息数组;LatestSeqId:最新事件序号;HasMore:是否还有更早记录;NextCursor:下一页提示;HistoryEpoch、SnapshotSeqId、CursorSource:后续查询应保留的历史上下文。 + +CursorSource、HistoryEpoch、SnapshotSeqId 应沿用上次响应,不自行生成。服务端要求重载历史时,清空旧游标后重新读取。 + +### 读取会话事件 + +`POST /agentengine/api/v1/ListSessionEvents` + +读取会话事件,用于恢复进度、工具结果和原始时间线。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `CheckpointIds` | body | `array` | 否 | `[]` | 按 checkpoint 标识过滤。 | +| `EventTypes` | body | `array` | 否 | `[]` | 按事件类型过滤;空数组表示不按类型过滤。 | +| `Offset` | body | `integer / null` | 否 | `null` | 结果偏移量,从 0 开始。 最小 0。 | +| `Limit` | body | `integer` | 否 | `200` | 最多返回条数。 最小 1;最大 2000。 | +| `AfterSeqId` | body | `integer / null` | 否 | `null` | 只读取该序号之后的事件或消息。 最小 0。 | +| `BeforeSeqId` | body | `integer / null` | 否 | `null` | 只读取该序号之前的事件或消息。 最小 1。 | +| `EventOrder` | body | `string / null` | 否 | `null` | 事件排列顺序。 | +| `CursorSource` | body | `string / null` | 否 | `null` | 使用服务端上次返回的游标来源。 取值 runtime, control。 | +| `HistoryEpoch` | body | `string / null` | 否 | `null` | 使用服务端上次返回的历史版本标识。 | +| `SnapshotSeqId` | body | `integer / null` | 否 | `null` | 使用服务端上次返回的历史快照序号。 最小 0。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","AfterSeqId":0,"Limit":200} +``` + +**返回**:Events:事件数组;Total、Offset、Limit:查询结果信息;HasMore:是否还有记录;可能附带历史版本与快照信息。 + +与聊天消息不同,事件可能包含工具、状态和交互变化;不应把原始事件直接拼接成聊天消息。 + +## 对话与运行 + +### 执行对话 + +`POST /agentengine/api/v1/RunAgent` + +执行一轮 Agent 对话,支持同步、SSE 和能力允许时的后台模式。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `Messages` | body | `array` | 否 | `[]` | 消息数组;每项包含 role 与 content。 | +| `UserId` | body | `string / null` | 否 | `"user"` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `AccountId` | body | `string / null` | 否 | `null` | 账号关联标识;不替代服务端认证。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | +| `InvocationId` | body | `string / null` | 否 | `null` | 本次调用标识,用于续订、取消和事件关联。 | +| `ApiFormat` | body | `string` | 否 | `"responses"` | 输出协议:responses 或 chat_completions。 | +| `Stream` | body | `boolean` | 否 | `false` | 是否返回 SSE 流。 | +| `Background` | body | `boolean` | 否 | `false` | 是否请求后台执行;使用前确认运行能力。 | +| `Model` | body | `string / null` | 否 | `null` | 本次选择的模型标识;从模型目录获取。 | +| `ModelMetadata` | body | `object / null` | 否 | `null` | 模型能力信息。 | +| `ModelOptions` | body | `object / null` | 否 | `null` | 模型推理选项;支持项取决于所用模型。 | +| `Metadata` | body | `object / null` | 否 | `null` | 请求附加元数据;不用于伪造身份或服务端权限。 | +| `ResponsesInput` | body | `JSON value / null` | 否 | `null` | Responses 格式输入;用于文本、多模态或恢复输入。 | +| `PreviousResponseId` | body | `string / null` | 否 | `null` | 上一轮 Responses 响应标识。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","InvocationId":"inv-example","Messages":[{"role":"user","content":"你好"}],"ApiFormat":"responses","Stream":true} +``` + +**返回**:同步前台执行时,Data 为 ApiFormat 对应的 Responses 或 Chat Completions 对象。返回 SSE 时按事件流解析。后台模式的返回见下表。 + +| 执行方式 | 返回内容 | +| --- | --- | +| 前台同步 | JSON Action 外壳,Data 为模型响应 | +| 前台流式 | SSE;运行失败或交互等待可能在流中报告 | +| 后台,返回运行句柄时 | JSON Action;Data 包含 SessionId、InvocationId、Status、Background、SubscribeUrl | +| Kernel 受理的流式或后台请求 | SSE,采用 Responses 事件投影;不承诺返回 JSON 句柄 | + +普通前台流式请求设置 Stream=true。Background=true 只在服务明确允许后台执行时使用,返回形式可能与前台 SSE 不同;续订时使用 SubscribeRunEvents。Messages 与 ResponsesInput 按所选输入协议提供,恢复输入还可能需要 PreviousResponseId。断开 HTTP 连接不等价于取消任务;需要停止执行时调用 CancelRun。 + +### 续订运行事件 + +`GET /agentengine/api/v1/SubscribeRunEvents` + +在断线重连或后台运行时,订阅指定 invocation 的增量事件。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `SessionId` | query | `string` | 是 | `—` | 会话标识。 | +| `InvocationId` | query | `string` | 是 | `—` | 本次调用标识,用于续订、取消和事件关联。 | +| `AfterSeqId` | query | `integer` | 否 | `0` | 只读取该序号之后的事件或消息。 | +| `AgentId` | query | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | query | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | + +请求示例: + +```http +GET /agentengine/api/v1/SubscribeRunEvents?SessionId=session-example&InvocationId=inv-example&AfterSeqId=0 +Authorization: Bearer +``` + +**返回**:text/event-stream;每个 data 帧为会话事件对象,终止标志为 data: [DONE]。心跳是以冒号开头的 SSE 注释帧。 + +### 取消运行 + +`POST /agentengine/api/v1/CancelRun` + +按 InvocationId 请求停止当前运行。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | +| `InvocationId` | body | `string` | 是 | `—` | 本次调用标识,用于续订、取消和事件关联。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","InvocationId":"inv-example"} +``` + +**返回**:Cancelled 表示取消已请求或被运行时接受;Found 表示是否定位到运行;Status 为当前取消状态;RuntimeCancelStatus 为运行时取消结果。`Cancelled=true` 不保证后台任务在此时已经结束,应继续观察运行事件。 + +InvocationId 必须来自实际运行。在带可信业务身份的请求中必须提供 AgentId、SessionId;其他请求也建议同时提供以限定取消范围。取消接口不能使用 Responses id 或 CheckpointId 代替 InvocationId。 + +## 恢复与交互 + +### 查询恢复点 + +`POST /agentengine/api/v1/ListSessionCheckpoints` + +查询 Agent 或指定会话的 checkpoint,并按恢复条件筛选。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `SessionId` | body | `array / string / null` | 否 | `null` | 会话标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `CheckpointId` | body | `array / string / null` | 否 | `null` | checkpoint 标识;从会话 checkpoint 列表获取。 | +| `RunId` | body | `string / null` | 否 | `null` | 运行标识。 | +| `OnlyResumable` | body | `boolean` | 否 | `false` | 是否仅返回可恢复的 checkpoint。 | +| `Framework` | body | `string / null` | 否 | `null` | 按框架过滤。 | +| `ResumeStatus` | body | `array` | 否 | `[]` | 按恢复状态过滤。 | +| `ResumeTypes` | body | `array` | 否 | `[]` | 按恢复类型过滤。 | +| `Offset` | body | `integer / null` | 否 | `null` | 结果偏移量,从 0 开始。 最小 0。 | +| `Limit` | body | `integer` | 否 | `100` | 最多返回条数。 最小 1;最大 1000。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","OnlyResumable":true} +``` + +**返回**:Checkpoints:恢复点数组;Total:结果计数;ResumableTotal:可恢复计数;HasResumableCheckpoint:是否存在可恢复记录。 + +### 预览恢复操作 + +`POST /agentengine/api/v1/GetCheckpointResumePreview` + +在提交恢复前检查目标 checkpoint 的可恢复性和阻断原因。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `RunId` | body | `string` | 是 | `—` | 运行标识。 | +| `CheckpointId` | body | `string` | 是 | `—` | checkpoint 标识;从会话 checkpoint 列表获取。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","CheckpointId":"checkpoint-example"} +``` + +**返回**:Preview:目标恢复点的预览与准入结果。 + +### 恢复运行 + +`POST /agentengine/api/v1/ResumeRun` + +从指定会话的 checkpoint 恢复执行。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `RunId` | body | `string` | 是 | `—` | 运行标识。 | +| `CheckpointId` | body | `string` | 是 | `—` | checkpoint 标识;从会话 checkpoint 列表获取。 | +| `ResumeAttemptId` | body | `string / null` | 否 | `null` | 恢复尝试标识,用于区分恢复请求。 | +| `InvocationId` | body | `string / null` | 否 | `null` | 本次调用标识,用于续订、取消和事件关联。 | +| `Stream` | body | `boolean` | 否 | `false` | 是否返回 SSE 流。 | +| `Background` | body | `boolean` | 否 | `false` | 是否请求后台执行;使用前确认运行能力。 | +| `Model` | body | `string / null` | 否 | `null` | 本次选择的模型标识;从模型目录获取。 | +| `ModelMetadata` | body | `object / null` | 否 | `null` | 模型能力信息。 | +| `ModelOptions` | body | `object / null` | 否 | `null` | 模型推理选项;支持项取决于所用模型。 | +| `Metadata` | body | `object / null` | 否 | `null` | 请求附加元数据;不用于伪造身份或服务端权限。 | +| `ResumeInstructionEnabled` | body | `boolean` | 否 | `false` | 是否启用恢复附加指令。 | +| `ResumeInstruction` | body | `string / null` | 否 | `null` | 恢复时附加的指令。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","CheckpointId":"checkpoint-example","ResumeAttemptId":"resume-example","Stream":true} +``` + +**返回**:同步恢复时返回 JSON Action;正常流式恢复返回 SSE;后台恢复返回 JSON 句柄,Data 包含 SessionId、RunId、CheckpointId、ResumeAttemptId、InvocationId、Status、Background、SubscribeUrl。重复的已处理恢复尝试可返回 Status=already_processed、AlreadyProcessed=true;终态 checkpoint 的空操作可返回 Status=noop 及 Reason。这两种情况即使 Stream=true 也可能返回 JSON,客户端应检查 Content-Type。 + +先调用 GetCheckpointResumePreview。每次独立的恢复尝试使用新的 ResumeAttemptId,同一次尝试重试则保持标识不变。 + +### 查询工具回执 + +`POST /agentengine/api/v1/ListToolReceipts` + +读取运行或 checkpoint 关联的工具执行回执。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `RunId` | body | `string / null` | 否 | `null` | 运行标识。 | +| `CheckpointId` | body | `string / null` | 否 | `null` | checkpoint 标识;从会话 checkpoint 列表获取。 | +| `Offset` | body | `integer` | 否 | `0` | 结果偏移量,从 0 开始。 最小 0。 | +| `Limit` | body | `integer` | 否 | `200` | 最多返回条数。 最小 1;最大 500。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example"} +``` + +**返回**:ToolReceipts:回执数组;Total、Offset、Limit:分页信息。回执不确定时不能据此自动重放有副作用的工具。 + +### 提交交互结果 + +`POST /agentengine/api/v1/SubmitInteraction` + +提交审批、拒绝、结构化输入或取消决定。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `UserId` | body | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `RunId` | body | `string` | 是 | `—` | 运行标识。 | +| `InteractionId` | body | `string` | 是 | `—` | 待处理交互标识。 | +| `ExpectedRevision` | body | `integer` | 是 | `—` | 期望的交互或授权等待版本;从当前状态获取。 最小 1。 | +| `InteractionAction` | body | `string` | 是 | `—` | 交互决定;取值 approve、reject、submit 或 cancel。 | +| `Response` | body | `JSON value` | 否 | `null` | 交互响应,支持任意合法 JSON 值;结构化提交必须显式携带本字段。 | +| `IdempotencyKey` | body | `string` | 是 | `—` | 幂等键;同一次提交重试时保持不变。 最短 1;最长 256。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","RunId":"run-example","InteractionId":"interaction-example","ExpectedRevision":1,"InteractionAction":"approve","Response":null,"IdempotencyKey":"interaction-example-approve"} +``` + +**返回**:Data 为命令回执,包含 schema_version、command_id、status 及条件返回的 message_id、run_id、accepted_seq 或 error。 + +此兼容入口要求活动的本地 Kernel。托管服务通过相应授权入口完成同类操作,不能自行伪造许可。InteractionAction 的四个值为 approve、reject、submit、cancel;兼容请求也接受 Action 作为决定字段。submit 时必须显式包含 Response,Response=null 也是合法的 JSON 值,不能与省略字段混同。ExpectedRevision 必须取当前交互版本;同一次决定重试时保持 IdempotencyKey 不变。受理回执可以使用 HTTP 202,重复命令可以使用 HTTP 200;accepted/duplicate 只表示命令受理,不代表交互已经执行完成。 + +## 附件与工作区 + +### 上传附件 + +`POST /agentengine/api/v1/UploadFile` + +上传图片或文档,取得可放入后续消息的文件引用。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `file` | form | `binary` | 是 | `—` | 上传文件。 | + +请求示例: + +```bash +curl --fail-with-body "$BASE_URL/agentengine/api/v1/UploadFile" -H "Authorization: Bearer $API_KEY" -F "file=@./example.txt" +``` + +**返回**:FileData.fileUri:文件引用;displayName:显示名;mimeType:媒体类型;sizeBytes:文件大小。 + +### 下载附件 + +`GET /agentengine/api/v1/AttachmentContent` + +读取上传接口返回的文件引用。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `FileUri` | query | `string` | 是 | `—` | 上传接口返回的 fileUri。 | +| `SessionId` | query | `string / null` | 否 | `null` | 会话标识。 | +| `AgentId` | query | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `UserId` | query | `string / null` | 否 | `null` | 逻辑用户标识;访问范围仍受认证身份约束。 | + +请求示例: + +```http +GET /agentengine/api/v1/AttachmentContent?FileUri=file-example +Authorization: Bearer +``` + +**返回**:文件原始字节。按 Content-Type 渲染或保存,不按 JSON Action 外壳解析。 + +FileUri 来自 UploadFile,不是任意本地文件路径或外部 URL。受身份隔离的附件可能还需要 AgentId 或 SessionId 以定位其访问范围。 + +### 列出工作区文件 + +`POST /agentengine/api/v1/ListWorkspaceFiles` + +列出工作区指定目录的文件和子目录。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `Path` | body | `string` | 否 | `"."` | 工作区内的相对路径。 | +| `Recursive` | body | `boolean` | 否 | `false` | 是否递归列出子目录。 | + +请求示例: + +```json +{"AgentId":"agent-example","Path":".","Recursive":false} +``` + +**返回**:目录信息和 Entries 条目数组;条目包含 Name、Path、Type、SizeBytes、MimeType、ModifiedAt。 + +### 上传工作区文件 + +`POST /agentengine/api/v1/AddWorkspaceFile` + +将文件写入工作区指定相对路径。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `file` | form | `binary` | 是 | `—` | 上传文件。 | +| `AgentId` | form | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `Path` | form | `string` | 是 | `—` | 工作区内的相对路径。 | + +请求示例: + +```bash +curl --fail-with-body "$BASE_URL/agentengine/api/v1/AddWorkspaceFile" -H "Authorization: Bearer $API_KEY" -F "file=@./example.txt" -F "Path=notes/example.txt" +``` + +**返回**:Entry:上传后的文件条目,包含 Path、Name、Type、SizeBytes、MimeType、ModifiedAt。 + +使用 multipart/form-data,客户端自动设置 boundary;Path 是目标文件相对路径,file 是文件内容。 + +### 删除工作区文件 + +`POST /agentengine/api/v1/DeleteWorkspaceFile` + +删除工作区中的指定文件。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `Path` | body | `string` | 是 | `—` | 工作区内的相对路径。 | + +请求示例: + +```json +{"AgentId":"agent-example","Path":"notes/example.txt"} +``` + +**返回**:Deleted:删除成功时为 true。 + +### 下载工作区文件 + +`GET /agentengine/api/v1/GetWorkspaceFileContent` + +读取工作区文件的原始内容,可用于图片、文档和文本预览。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `FilePath` | query | `string` | 是 | `—` | 工作区内待下载文件的相对路径。 | +| `AgentId` | query | `string / null` | 否 | `null` | 目标 Agent 标识。 | + +请求示例: + +```http +GET /agentengine/api/v1/GetWorkspaceFileContent?FilePath=notes%2Fexample.txt +Authorization: Bearer +``` + +**返回**:文件原始字节。Content-Type 表示文件类型;按返回的 Content-Disposition 决定显示或下载。 + +FilePath 是工作区相对路径,不允许使用绝对路径或越过工作区边界。 + +### 导出工作区 + +`GET /agentengine/api/v1/ExportWorkspaceZip` + +将指定工作区目录导出为 ZIP 文件。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | query | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `Path` | query | `string` | 否 | `"."` | 工作区内的相对路径。 | + +请求示例: + +```http +GET /agentengine/api/v1/ExportWorkspaceZip?Path=. +Authorization: Bearer +``` + +**返回**:ZIP 二进制文件,按附件响应保存。 + +## 消息反馈 + +### 读取消息反馈 + +`POST /agentengine/api/v1/GetResponseFeedback` + +读取当前用户对指定响应的反馈。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `ResponseId` | body | `string` | 是 | `—` | 被反馈的模型响应标识。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example"} +``` + +**返回**:Feedback:反馈对象;未反馈时为 null。 + +### 保存消息反馈 + +`POST /agentengine/api/v1/UpsertResponseFeedback` + +创建或更新当前用户对指定响应的赞/踩及说明。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `ResponseId` | body | `string` | 是 | `—` | 被反馈的模型响应标识。 | +| `Rating` | body | `string` | 是 | `—` | 反馈值:up 或 down。 | +| `Comment` | body | `string / null` | 否 | `""` | 反馈说明。 | +| `EventId` | body | `string / null` | 否 | `null` | 关联事件标识。 | +| `TraceId` | body | `string / null` | 否 | `null` | 关联 trace 标识。 | +| `RootSpanId` | body | `string / null` | 否 | `null` | 关联根 span 标识。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example","Rating":"up","Comment":"回答有帮助"} +``` + +**返回**:Feedback:保存后的反馈对象。 + +Rating 只接受 up 或 down。ResponseId 应对应当前会话的实际助手响应。 + +### 删除消息反馈 + +`POST /agentengine/api/v1/DeleteResponseFeedback` + +撤销指定响应的反馈。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `AgentId` | body | `string` | 是 | `—` | 目标 Agent 标识。 | +| `SessionId` | body | `string` | 是 | `—` | 会话标识。 | +| `ResponseId` | body | `string` | 是 | `—` | 被反馈的模型响应标识。 | + +请求示例: + +```json +{"AgentId":"agent-example","SessionId":"session-example","ResponseId":"response-example"} +``` + +**返回**:Deleted:是否删除了已有反馈。 + +## MCP OAuth + +仅在服务声明支持 MCP 授权时使用。本地项目与托管访问的授权状态不能混用;授权流程由服务端管理,不在聊天消息中传递令牌或秘密。 + +| 方法与路径 | 用途 | +| --- | --- | +| `POST /agentengine/api/v1/GetMcpAuthorizationWait` | 读取当前 MCP 授权等待的状态和允许执行的操作。 | +| `POST /agentengine/api/v1/OpenMcpAuthorization` | 为待授权的 MCP 服务取得浏览器授权地址。 | +| `POST /agentengine/api/v1/RetryMcpAuthorization` | 在授权失败或被拒绝后重新发起授权。 | +| `POST /agentengine/api/v1/RetryMcpConnection` | 在授权凭据仍有效时重试 MCP 服务连接。 | +| `POST /agentengine/api/v1/CancelMcpAuthorizationWait` | 取消当前授权等待,阻止迟到的授权结果继续该等待。 | + +五个接口使用以下公共请求参数: + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `WaitId` | body | `string` | 是 | `—` | 当前 MCP 授权等待标识。 最短 1;最长 64。 | +| `ExpectedRevision` | body | `integer / null` | 否 | `null` | 期望的交互或授权等待版本;从当前状态获取。 最小 1。 | +| `AgentId` | body | `string / null` | 否 | `null` | 目标 Agent 标识。 | +| `SessionId` | body | `string / null` | 否 | `null` | 会话标识。 | +| `IdempotencyKey` | body | `string / null` | 否 | `null` | 可选兼容字段;本组操作以 ExpectedRevision 检查状态版本,不承诺按此字段去重。 | + +读取等待状态示例: + +```json +{"WaitId":"wait-example","AgentId":"agent-example","SessionId":"session-example"} +``` + +打开、重试或取消时,应传入当前等待状态返回的 ExpectedRevision: + +```json +{"WaitId":"wait-example","ExpectedRevision":1,"AgentId":"agent-example","SessionId":"session-example"} +``` + +授权状态 Data: + +| 字段 | 类型 | 说明 | +| --- | --- | --- | +| wait_id / run_id / config_id | string | 等待、运行与连接配置标识 | +| revision | integer | 当前版本,后续操作使用此值 | +| status | string | 授权/连接当前状态 | +| display_name | string | MCP 服务显示名 | +| scopes | string[] | 本次授权范围 | +| allowed_actions | string[] | 当前状态允许执行的操作 | +| requires_resume | boolean | 是否涉及等待后的恢复 | +| deadline | number | 授权等待截止时间,Unix 时间秒 | +| error | string / null | 失败原因 | +| authorization_url | string,可选 | OpenMcpAuthorization 返回的浏览器打开地址 | + +先读取等待状态。allowed_actions 中 query、open、retry_authorization、retry_connection、cancel 分别对应查询、打开授权、重试授权、重试连接和取消等待;仅执行当前状态允许的操作。浏览器完成真实授权后重新读取状态。取消后,不应把迟到的回调当作新的授权成功。业务状态冲突可返回 HTTP 409,并携带 ReasonCode;刷新状态后再决定下一步。 + +## AG-UI 对话 + +`POST /agentengine/agui` 为默认地址;优先使用初始化返回的 HostedChat.Transports 中 AG-UI Endpoint。 + +用途:接收标准 AG-UI 运行输入,返回文本、工具、状态和结构化交互事件。A2UI 卡片通过相应消息/事件承载,不需要调用单独的 A2UI HTTP 接口。 + +| 参数 | 位置 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | --- | +| `threadId` | body | `string` | 是 | `—` | AG-UI 会话标识。 | +| `runId` | body | `string` | 是 | `—` | AG-UI 运行标识。 | +| `protocolVersion` | body | `string / null` | 否 | `null` | 请求采用的 AG-UI 协议版本。 | +| `parentRunId` | body | `string / null` | 否 | `null` | 父运行标识,用于关联派生运行。 | +| `state` | body | `JSON value / null` | 否 | `null` | 图的初始或当前状态。 | +| `messages` | body | `array` | 是 | `—` | AG-UI 消息数组。 | +| `tools` | body | `array / null` | 否 | `null` | 客户端声明的工具列表。 | +| `context` | body | `array / null` | 否 | `null` | 上下文条目列表。 | +| `forwardedProps` | body | `JSON value / null` | 否 | `null` | 传递给 Agent 的扩展属性。 | +| `resume` | body | `array / null` | 否 | `null` | 待恢复交互的响应列表。 | + +**返回**:`text/event-stream`。客户端按 AG-UI 事件协议处理开始、文本、工具、状态、交互、结束或错误事件。 + +RunAgentInput 中的 messages 为消息数组;tools 为工具描述;context 为上下文数组;forwardedProps 为扩展属性。threadId 用于关联会话,runId 用于标识运行。不要把 AG-UI runId 与其他协议的 InvocationId 随意互换。 + +AG-UI 不可用时,应按初始化声明选择允许的聊天传输;不能只改 URL 就认为服务已经具备交互、恢复或 OAuth 能力。 + +## 公共返回对象 + +### Session 会话 + +| 字段 | 说明 | +| --- | --- | +| SessionId / AgentId / UserId | 会话及其所属 Agent、用户 | +| Title / TitleSource / Summary | 标题、标题来源和摘要 | +| FirstPrompt / LastPrompt | 首条与末条用户输入预览 | +| ActiveInvocationId / ActiveRunStatus | 当前或最近运行的调用标识与状态 | +| ActiveRunMode / ActiveRunTrigger | 运行模式与触发方式 | +| CreatedAt / UpdatedAt / Version | Unix 时间秒表示的创建/更新时间,以及整数版本号 | +| State | 允许公开的会话状态 | +| Continuity | 运行时连续性信息 | + +### Message 聊天消息 + +| 字段 | 说明 | +| --- | --- | +| MessageId / Role / Content | 消息标识、角色和内容 | +| Timestamp / SeqId / InvocationId | 时间、事件序号和所属调用 | +| Reasoning / Blocks | 可返回的推理及有序内容块 | +| ToolEvents | 工具执行与审批状态 | +| Attachments | 附件引用、名称、类型、大小和访问地址 | + +### SessionEvent 会话事件 + +| 字段 | 说明 | +| --- | --- | +| EventId / SessionId | 事件及会话标识 | +| Author / EventType | 产生方与事件类型 | +| Content | 类型相关的事件内容 | +| Timestamp / SeqId | 时间与序号 | +| InvocationId | 所属运行调用,有值时返回 | + +### Feedback 反馈 + +| 字段 | 说明 | +| --- | --- | +| AgentId / SessionId / ResponseId | 反馈目标 | +| Rating / Comment | up/down 与反馈文字 | +| EventId / TraceId / RootSpanId | 关联事件和调用链 | +| CreatedAt / UpdatedAt | 创建和更新时间 | + +## SSE 使用约定 + +使用支持增量读取的 HTTP 客户端,按空行拆分 SSE 帧,不按一次网络读取对应一个 JSON 对象。冒号开头的帧为心跳注释。SubscribeRunEvents 的 data 为事件对象,接收到 `[DONE]` 后本轮订阅结束。RunAgent 的非 Kernel 分支按 ApiFormat 返回兼容事件;Kernel 分支使用具名 Responses 事件,例如 response.completed、response.failed、response.canceled。交互等待也可能返回 response.incomplete 并关闭前台流,不能把连接关闭一律视为成功。AG-UI 按 AG-UI 协议解析。 + +断线续订使用同一 SessionId、InvocationId 和最后确认的 AfterSeqId;不要通过重发用户消息模拟恢复。HTTP 200 不代表流中的运行一定成功,仍需处理运行失败和中断事件。 + +## 可选文件预览与本地原生终端 + +以下入口仅在对应能力启用时使用。原生终端不等同于对所有托管用户开放的远程 Shell。 + +### 文件预览资源 + +`GET /_ksadk/workspace/v1/files/{file_path}` + +file_path 为工作区相对路径,可包含多段目录。各路径段分别进行 URL 编码。返回文件原始内容,按 Content-Type 渲染;HTML 页面依赖的相对图片、样式等资源可通过同一工作区路径读取。 + +### 创建或复用终端会话 + +`POST /_ksadk/terminal/sessions` + +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| --- | --- | --- | --- | --- | +| session_id | string | 否 | 空 | 关联聊天会话 | +| mode | string | 否 | tui | 终端模式,以运行时支持的模式为准 | +| cols / rows | integer | 否 | 80 / 24 | 终端尺寸 | +| force_new | boolean | 否 | false | 是否强制创建新终端 | +| cwd | string | 否 | 不指定 | 工作目录,受运行时限制 | + +请求示例: + +```json +{"session_id":"session-example","mode":"tui","cols":80,"rows":24,"force_new":false} +``` + +返回 `{"session":{...}}`,其中 terminal_session_id 用于后续连接和关闭。 + +### 查询终端会话 + +`GET /_ksadk/terminal/sessions` + +Query 参数 session_id 和 mode 均可选,用于筛选。返回 `{"sessions":[...]}`。 + +### 关闭终端会话 + +`DELETE /_ksadk/terminal/sessions/{terminal_session_id}` + +返回 deleted 和 terminal_session_id;会话不存在时可返回 HTTP 404。 + +### 连接终端 WebSocket + +`WS /_ksadk/terminal/ws?terminal_session_id=` + +远程安全连接使用 WSS;握手必须协商 `Sec-WebSocket-Protocol: ks-terminal.v1`。terminal_session_id 来自终端创建结果。服务端拒绝终端能力或身份访问时,客户端应停止连接,不通过修改身份头绕过。 diff --git a/docs-site/content/docs/references/index.en.mdx b/docs-site/content/docs/references/index.en.mdx index 4ee7ac2a1..d80ff927d 100644 --- a/docs-site/content/docs/references/index.en.mdx +++ b/docs-site/content/docs/references/index.en.mdx @@ -5,6 +5,7 @@ title: Reference Reference material for KsADK: CLI, environment variables, OpenAI-compatible API, project config, remote runtime API, runtime sessions and files, security boundaries, troubleshooting, and contributing. + diff --git a/docs-site/content/docs/references/index.mdx b/docs-site/content/docs/references/index.mdx index 5b5d88d90..caf33084a 100644 --- a/docs-site/content/docs/references/index.mdx +++ b/docs-site/content/docs/references/index.mdx @@ -5,6 +5,7 @@ title: 参考 KsADK 的参考资料:CLI、环境变量、OpenAI-Compatible API、项目配置、远程运行时 API、运行时会话与文件、安全边界、故障排查与贡献指南。 + diff --git a/docs-site/content/docs/references/meta.en.json b/docs-site/content/docs/references/meta.en.json index 6df7b9984..dd348e343 100644 --- a/docs-site/content/docs/references/meta.en.json +++ b/docs-site/content/docs/references/meta.en.json @@ -7,6 +7,7 @@ "---[Settings]Configuration and APIs---", "project-config", "environment-variables", + "agent-web-api", "openai-compatible-api", "---[Activity]Runtime Contracts---", "remote-runtime-api", diff --git a/docs-site/content/docs/references/meta.json b/docs-site/content/docs/references/meta.json index 6653ff733..9f45341d7 100644 --- a/docs-site/content/docs/references/meta.json +++ b/docs-site/content/docs/references/meta.json @@ -7,6 +7,7 @@ "---[Settings]配置与接口---", "project-config", "environment-variables", + "agent-web-api", "openai-compatible-api", "---[Activity]运行时合同---", "remote-runtime-api", diff --git a/docs-site/content/docs/references/remote-runtime-api.en.mdx b/docs-site/content/docs/references/remote-runtime-api.en.mdx index 44dcb8b2e..57dcfc5e8 100644 --- a/docs-site/content/docs/references/remote-runtime-api.en.mdx +++ b/docs-site/content/docs/references/remote-runtime-api.en.mdx @@ -2,6 +2,8 @@ title: Remote Runtime API --- +For chat interface integration, see [Agent Web API](/en/docs/references/agent-web-api) for session, run, file, feedback, and MCP OAuth request parameters and responses. + This reference describes the public-safe runtime API shape after an agent or runtime product is deployed. The externally visible base URL is the hosted `PublicEndpoint` returned by the control plane. diff --git a/docs-site/content/docs/references/remote-runtime-api.mdx b/docs-site/content/docs/references/remote-runtime-api.mdx index fb4b3d709..87e74fda4 100644 --- a/docs-site/content/docs/references/remote-runtime-api.mdx +++ b/docs-site/content/docs/references/remote-runtime-api.mdx @@ -2,6 +2,8 @@ title: 远程运行时 API --- +聊天界面接入请参阅 [Agent Web API](/cn/docs/references/agent-web-api),其中列出会话、运行、文件、反馈及 MCP OAuth 的请求参数与响应。 + 这页说明 Agent 或运行时产品部署后的公开安全 API 形态。外部可见 base URL 是控制面 返回的 hosted `PublicEndpoint`。 diff --git a/tests/test_public_release_positioning.py b/tests/test_public_release_positioning.py index c3cc4f357..6be7c2dd2 100644 --- a/tests/test_public_release_positioning.py +++ b/tests/test_public_release_positioning.py @@ -29,6 +29,7 @@ f"{DOCS_ROOT_URL}cn/docs/framework/guides/tool-tunnel/", f"{DOCS_ROOT_URL}cn/docs/framework/guides/a2a-runtime/", f"{DOCS_ROOT_URL}cn/docs/references/environment-variables/", + f"{DOCS_ROOT_URL}cn/docs/references/agent-web-api/", } EN_DOC_URLS = { f"{DOCS_ROOT_URL}en/docs/framework/getting-started/quickstart/", @@ -49,6 +50,7 @@ f"{DOCS_ROOT_URL}en/docs/framework/guides/tool-tunnel/", f"{DOCS_ROOT_URL}en/docs/framework/guides/a2a-runtime/", f"{DOCS_ROOT_URL}en/docs/references/environment-variables/", + f"{DOCS_ROOT_URL}en/docs/references/agent-web-api/", } _DOCS_LINK_PATTERN = re.compile( @@ -784,3 +786,39 @@ def test_public_release_materials_do_not_include_internal_environment_details(): text = _read(relative_path) for fragment in forbidden: assert fragment not in text, f"{relative_path} contains {fragment}" + + +def test_agent_web_api_is_discoverable_in_both_languages(): + for suffix, locale in (("", "cn"), (".en", "en")): + meta = json.loads(_read(f"docs-site/content/docs/references/meta{suffix}.json")) + assert meta["pages"].count("agent-web-api") == 1 + target = f"/{locale}/docs/references/agent-web-api" + for page in ("index", "remote-runtime-api"): + assert target in _read(f"docs-site/content/docs/references/{page}{suffix}.mdx") + + +def test_agent_web_api_language_variants_have_matching_contract_tables(): + """Translation must preserve endpoint spelling and request contract cells.""" + cn = _read("docs-site/content/docs/references/agent-web-api.mdx") + en = _read("docs-site/content/docs/references/agent-web-api.en.mdx") + endpoints = re.compile(r"`((?:POST|GET|DELETE|WS) /[^`]+)`") + assert endpoints.findall(cn) == endpoints.findall(en) + assert len(set(endpoints.findall(cn))) == 37 + + def contract_rows(text): + result = [] + for line in text.splitlines(): + if not line.startswith("| `"): + continue + cells = [cell.strip() for cell in line.strip("|").split("|")] + if len(cells) == 6 and cells[1] in {"body", "query", "form"}: + required = {"是": True, "否": False, "Yes": True, "No": False}[cells[3]] + result.append((cells[0], cells[1], cells[2], required, cells[4])) + return result + + assert len(contract_rows(cn)) > 150 + assert contract_rows(cn) == contract_rows(en) + for text in (cn, en): + for unsupported in ("CompactSession", "SubmitAgentControl", "GetAgentStatus", "SubscribeSessionEvents"): + assert f"/agentengine/api/v1/{unsupported}" not in text + assert "/_ksadk/terminal/v1/" not in text