Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion docs/en/docs/integrations/openclaw.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ gateway's `PC_GATEWAY_API_KEY` value as its `apiKey`, and select its model, for
apiKey: "${PC_GATEWAY_KEY}",
api: "openai-responses",
models: [
{ id: "approved-model", name: "Approved model", contextWindow: 400000, maxTokens: 32000 },
{ id: "approved-model", name: "Approved model", contextWindow: 128000, maxTokens: 32000 },
],
},
},
Expand All @@ -232,6 +232,21 @@ the gateway calls the model without streaming and replays the checked response a
and is captured. With `api: "openai-completions"`, the gateway forwards a streamed request on the Chat Completions route
and releases the stream unchanged; with `PC_GATEWAY_SEDIMENT=on`, it captures the completed turn from it.

The PowerContext gateway accepts a model request of at most 1 MiB, measured after it injects context and adds its cost
guidance, and configuration cannot raise this ceiling; see
[Gateway byte capacity](../operate/deploy-server.md#gateway-byte-capacity). A request that arrives larger fails with
HTTP 413, and one that grows past it through injection or cost guidance fails with HTTP 403
`request_payload_too_large`, before the model is called. OpenClaw sends the session's full history on every request, so
a long session reaches the ceiling unless OpenClaw compacts it first. Set `contextWindow` low enough that OpenClaw
compacts well before a request reaches 1 MiB.

According to the source of OpenClaw 2026.8.1-beta.2, its embedded agent compacts when the context that the model last
reported, which includes the tool definitions and system prompt, exceeds `contextWindow` minus a reserve of at least
20000 tokens. By default it checks after each run ends and before the next prompt, not between the model requests of
a tool loop. The example's `128000` therefore compacts by 108,000 tokens at the latest, about 432 KB at four UTF-8
bytes per token, and leaves the rest of the ceiling for injected context, cost guidance, JSON overhead, and the tool
results of one run. This value is derived from OpenClaw's source and the ceiling; it was not measured.

Configure Core and the gateway as well:

- Run Core in a non-enforcing privacy mode (`disabled`, `shadow`, or `advisory`). OpenClaw sends no `store` field to a
Expand Down
22 changes: 21 additions & 1 deletion docs/en/docs/integrations/pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ the gateway key as its `apiKey`; Pi sends it as the bearer token:
"baseUrl": "http://127.0.0.1:8787/gateway/v1",
"api": "openai-responses",
"apiKey": "$PC_GATEWAY_KEY",
"models": [{ "id": "approved-model", "contextWindow": 400000, "maxTokens": 32000 }]
"models": [{ "id": "approved-model", "contextWindow": 80000, "maxTokens": 32000 }]
}
}
}
Expand All @@ -172,6 +172,26 @@ the gateway key as its `apiKey`; Pi sends it as the bearer token:
Export the gateway's `PC_GATEWAY_API_KEY` value as `PC_GATEWAY_KEY` where Pi starts, then select the model with
`/model` or `pi --provider powercontext-gateway --model approved-model`.

The gateway accepts a model request of at most 1 MiB, measured after it injects context and adds its cost guidance,
and configuration cannot raise this ceiling; see
[Gateway byte capacity](../operate/deploy-server.md#gateway-byte-capacity). A request that arrives larger fails with
HTTP 413, and one that grows past it through injection or cost guidance fails with HTTP 403
`request_payload_too_large`, before the model is called. The window check of an enforcing Core is tighter: it counts
each byte as a token, so the example target withholds a request of more than about 368,000 bytes (400000 minus the
32000 output limit) with `context_window_exceeded`. Pi sends the session's full history on every request, so a long
session reaches these limits unless Pi compacts it first. Set `contextWindow` low enough that Pi compacts well before
a request reaches them.

According to its source, Pi 0.82.1 compacts when the context that the model last reported, which includes the tool
definitions and system prompt, exceeds `contextWindow` minus `compaction.reserveTokens` (16384 by default). It checks
after each prompt's run ends and before the next prompt, not between the model requests of a tool loop. The example's
`80000` therefore compacts above 63,616 tokens, about 254 KB at four UTF-8 bytes per token, and leaves the rest of the
example target's limit for injected context, cost guidance, JSON overhead, and the tool results of one prompt. With a
non-enforcing Core, only the 1 MiB ceiling applies, and `128000` compacts above 111,616 tokens, about 446 KB. These
values are derived from Pi's source and the limits; they were not measured. A much smaller value makes Pi compact
often, because after compaction a request still carries the tool definitions, system prompt, summary, and about 20000
recent tokens (`compaction.keepRecentTokens`).

Use the Responses API. Pi always streams. On the Responses route, the gateway calls the model without streaming and
replays the checked response to Pi as a stream, so the turn completes and is captured. On the Chat Completions route
(`openai-completions`), the gateway forwards Pi's streamed request. An enforcing Core withholds the streamed response,
Expand Down
15 changes: 14 additions & 1 deletion docs/zh/docs/integrations/openclaw.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ memory 工具照常工作,它们都不准备上下文。关闭采集后,插
apiKey: "${PC_GATEWAY_KEY}",
api: "openai-responses",
models: [
{ id: "approved-model", name: "Approved model", contextWindow: 400000, maxTokens: 32000 },
{ id: "approved-model", name: "Approved model", contextWindow: 128000, maxTokens: 32000 },
],
},
},
Expand All @@ -214,6 +214,19 @@ memory 工具照常工作,它们都不准备上下文。关闭采集后,插
gateway 在 Chat Completions 路由上转发流式请求,并原样放行流式响应;设置 `PC_GATEWAY_SEDIMENT=on` 后,
还会从中采集完成的一轮。

PowerContext gateway 接受的模型请求最多为 1 MiB,按注入上下文并加入成本指引之后的大小计算,配置无法提高这个上限;
见 [Gateway 字节容量](../operate/deploy-server.md#gateway-字节容量)。到达时就超过上限的请求以 HTTP 413 失败,
因注入或成本指引而超过上限的请求在调用模型之前以 HTTP 403 `request_payload_too_large` 失败。
OpenClaw 在每个请求中发送会话的完整历史,因此长会话会达到这个上限,除非 OpenClaw 先压缩会话。
请把 `contextWindow` 设得足够低,让 OpenClaw 在请求接近 1 MiB 之前就压缩。

根据 OpenClaw 2026.8.1-beta.2 的源码,它的内嵌 agent 在模型上一次报告的上下文超过 `contextWindow`
减去至少 20000 个 token 的预留时压缩,报告的上下文包括工具定义和 system prompt。
默认情况下,它在每次运行结束后、下一个提示词之前检查,不在工具循环的各个模型请求之间检查。
因此示例中的 `128000` 最晚在 108,000 个 token 时压缩,按每个 token 约四个 UTF-8 字节计约为 432 KB,
上限的其余部分留给注入的上下文、成本指引、JSON 开销和一次运行内的工具结果。
这个值是根据 OpenClaw 的源码和这个上限推算的,没有实际测量。

配置 Core 和 gateway 时还需要:

- 请让 Core 运行在非 enforcing 隐私模式(`disabled`、`shadow` 或 `advisory`)。OpenClaw 不向自定义 provider 发送 `store`
Expand Down
18 changes: 17 additions & 1 deletion docs/zh/docs/integrations/pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export POWERCONTEXT_SERVER_INFERENCE_PROTECTION='{
"baseUrl": "http://127.0.0.1:8787/gateway/v1",
"api": "openai-responses",
"apiKey": "$PC_GATEWAY_KEY",
"models": [{ "id": "approved-model", "contextWindow": 400000, "maxTokens": 32000 }]
"models": [{ "id": "approved-model", "contextWindow": 80000, "maxTokens": 32000 }]
}
}
}
Expand All @@ -163,6 +163,22 @@ export POWERCONTEXT_SERVER_INFERENCE_PROTECTION='{
在启动 Pi 的环境中,把 gateway 的 `PC_GATEWAY_API_KEY` 的值导出为 `PC_GATEWAY_KEY`,然后用 `/model` 或
`pi --provider powercontext-gateway --model approved-model` 选择这个模型。

gateway 接受的模型请求最多为 1 MiB,按注入上下文并加入成本指引之后的大小计算,配置无法提高这个上限;
见 [Gateway 字节容量](../operate/deploy-server.md#gateway-字节容量)。到达时就超过上限的请求以 HTTP 413 失败,
因注入或成本指引而超过上限的请求在调用模型之前以 HTTP 403 `request_payload_too_large` 失败。
enforcing 模式的 Core 的窗口检查更严格:它把每个字节计为一个 token,
因此示例目标会以 `context_window_exceeded` 暂缓超过约 368,000 字节(400000 减去 32000 的输出上限)的请求。
Pi 在每个请求中发送会话的完整历史,因此长会话会达到这些上限,除非 Pi 先压缩会话。
请把 `contextWindow` 设得足够低,让 Pi 在请求接近这些上限之前就压缩。

根据源码,Pi 0.82.1 在模型上一次报告的上下文超过 `contextWindow` 减去 `compaction.reserveTokens`(默认 16384)时压缩,
报告的上下文包括工具定义和 system prompt。Pi 在每个提示词的运行结束后、下一个提示词之前检查,
不在工具循环的各个模型请求之间检查。因此示例中的 `80000` 会在超过 63,616 个 token 时压缩,
按每个 token 约四个 UTF-8 字节计约为 254 KB,示例目标上限的其余部分留给注入的上下文、成本指引、JSON 开销和一个提示词内的工具结果。
Core 不处于 enforcing 模式时只有 1 MiB 上限,`128000` 会在超过 111,616 个 token、约 446 KB 时压缩。
这些值是根据 Pi 的源码和这些上限推算的,没有实际测量。值过小会让 Pi 频繁压缩,
因为压缩之后的请求仍包含工具定义、system prompt、摘要和约 20000 个最近的 token(`compaction.keepRecentTokens`)。

请使用 Responses API。Pi 总是流式请求。在 Responses 路由上,gateway 以非流式方式调用模型,
再把检查通过的响应以流的形式重放给 Pi,因此这一轮能够完成并被采集。在 Chat Completions 路由(`openai-completions`)上,
gateway 转发 Pi 的流式请求。enforcing 模式的 Core 会暂缓流式响应,gateway 返回 HTTP 400。非 enforcing 模式的
Expand Down