Skip to content

Commit d93bb63

Browse files
committed
feat: add isolated pure-inference completion
1 parent 26f1070 commit d93bb63

66 files changed

Lines changed: 6169 additions & 1236 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"core": 2307,
3-
"channel": 3648,
4-
"plugin": 3601
3+
"channel": 3664,
4+
"plugin": 4055
55
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
b4fe14e0e5acb5deb187b1c910984849fd99e6b9fbd0b1cdd0ed588721fb369d config-baseline.json
2-
931ef09d0caab30725ccd1a7fe9249480cd92493f1950ba0fefc27c79ab2b368 config-baseline.core.json
3-
86d3787a38cb082b8abf238269384f4061f33f035887e2733b0367cce0841014 config-baseline.channel.json
4-
5b9ca40e66eeee315abca6ed89a72e72af0e19ce14592659ad1301223f56bca5 config-baseline.plugin.json
1+
820fe810979007010e2ade951ac178d204fcac10e48a6657cdd4b75de6ce0aee config-baseline.json
2+
b89715475e4b18a0d32765fda42bcce38537f6d49f949bb4ff0c7d1630101882 config-baseline.core.json
3+
26077716f773821c1ad07160632c3a5ed48f7bdcc95ea82cf77c99bb8bba5834 config-baseline.channel.json
4+
c02f1b49ac814cb27fd692a8107528b6ccfa7ea9e5aea854fc81830abca38eb4 config-baseline.plugin.json

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ e5e67ddf3cab38fcbf9220bc3160715897e2709d9a9ff6ff36f1ecc9453c2367 module/agent-c
66
74daa746deb548379d3f0d6eac3c4d082df1034c4360cc03bf51fee0f10a2e4d module/agent-harness
77
c706f6f39070110ad2ac9140e2962249f95aee7d4e2a2fa2f7276beb1dfc7efc module/agent-harness-runtime
88
5168648cd946abad8a92822889f13ceacc87ed502314a66190d0b1eb8ebe76ea module/agent-media-payload
9-
8a8b011fc9128301bfea6d7cd16023441fd4343696ef8cf63084dcc1f4fa5d4b module/agent-runtime
9+
2dcb4d62d90e5d71594f6b843c97534509a154784e378fb1c75bd86b5122b710 module/agent-runtime
1010
56b6d5fb6af3d95af1200065aca2e7d4f59e5fa59740505fe6ff433077ef6646 module/allow-from
1111
55cea5390d68839ca7768b4a0cc570b17b65fa0fa3bc4d76130ef0f16cb79ede module/allowlist-config-edit
1212
7ddd81bd5f55de9adf64bf4d92d012f24b37b6da0a72805a3a220d8feff24ca3 module/approval-auth-runtime

‎docs/gateway/configuration-reference.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ See [MCP](/cli/mcp#openclaw-as-an-mcp-client-registry) and
275275
- `plugins.entries.<id>.subagent.allowModelOverride`: explicitly trust this plugin to request per-run `provider` and `model` overrides for background subagent runs.
276276
- `plugins.entries.<id>.subagent.allowedModels`: optional allowlist of canonical `provider/model` targets for trusted subagent overrides. Use `"*"` only when you intentionally want to allow any model.
277277
- `plugins.entries.<id>.llm.allowModelOverride`: explicitly trust this plugin to request model overrides for `api.runtime.llm.complete`.
278-
- `plugins.entries.<id>.llm.allowedModels`: optional allowlist of canonical `provider/model` targets for trusted plugin LLM completion overrides. Use `"*"` only when you intentionally want to allow any model.
278+
- `plugins.entries.<id>.llm.allowedModels`: optional allowlist of canonical `provider/model` targets for trusted model overrides. Use `"*"` only when you intentionally want to allow any model override.
279+
- `plugins.entries.<id>.llm.allowedCompletionModels`: optional allowlist applied to every plugin LLM completion, including host-resolved defaults and overrides. Use `"*"` only when you intentionally want to allow any model.
280+
- `plugins.entries.<id>.llm.allowAuthProfileOverride`: explicitly trust this plugin to select a non-default auth profile for isolated `api.runtime.llm.complete` execution. Direct `model@profile` calls remain governed by model-override policy.
279281
- `plugins.entries.<id>.llm.allowAgentIdOverride`: explicitly trust this plugin to run `api.runtime.llm.complete` against a non-default agent id.
280282
- `plugins.entries.<id>.config`: plugin-defined config object (validated by native OpenClaw plugin schema when available).
281283
- Channel plugin account/runtime settings live under `channels.<id>` and should be described by the owning plugin's manifest `channelConfigs` metadata, not by a central OpenClaw option registry.

‎docs/plugins/sdk-agent-harness.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,29 @@ export default definePluginEntry({
153153
`authBootstrap` is intentionally absent from this generic example. Add
154154
`authBootstrap: "harness"` only when the harness meets the contract above.
155155

156+
### Isolated completion
157+
158+
The optional `runIsolatedCompletion(params)` capability serves product paths
159+
that require one fresh prompt-only inference call with a literal empty
160+
model-callable tool surface. Core passes the exact prepared `model`, `auth`,
161+
provider, model id, system prompt, user prompt, timeout, abort signal, and stream
162+
parameters. The harness must not re-resolve credentials, switch routes, reuse a
163+
native thread, attach tools, invoke agent lifecycle hooks, or deliver output.
164+
165+
Return `{ assistant: AssistantMessage }`. Core accepts only terminal text/thinking
166+
content with a `stop` or `length` stop reason; tool calls, failed stops, and empty
167+
output are rejected. If the harness cannot prove these semantics, omit the capability.
168+
Callers that require isolated completion then fail closed before invoking that
169+
harness; OpenClaw does not replay the request through another runtime.
170+
Plugin callers select this behavior through
171+
`api.runtime.llm.complete({ execution: { mode: "isolated-agent-runtime" } })`;
172+
the harness callback is the provider-side enforcement SPI, not a second caller
173+
API.
174+
175+
Native agent servers often have ambient built-in tools even when OpenClaw sends
176+
an empty tool list. In that case, use a separate provider transport that can
177+
serialize a true zero-tool request, or leave the capability unsupported.
178+
156179
### Delegated execution
157180

158181
A harness owner may set `delegatedExecutionPluginIds` to the ids of trusted

‎docs/plugins/sdk-runtime.md‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ two-party event loops that do not go through the shared inbound reply runner.
251251
});
252252
```
253253

254+
`maxTokens` and `temperature` are advisory sampling hints. The selected
255+
provider, CLI, or harness applies them when its transport exposes an
256+
equivalent control and otherwise may ignore them. They do not weaken the
257+
execution mode's isolation guarantees.
258+
259+
To require the configured agent runtime and a literal zero-tool model
260+
surface, select isolated execution explicitly:
261+
262+
```typescript
263+
const result = await api.runtime.llm.complete({
264+
messages: [{ role: "user", content: "Return one JSON value." }],
265+
systemPrompt: "You are a JSON-only function.",
266+
model: "openai/gpt-5.6-sol",
267+
execution: {
268+
mode: "isolated-agent-runtime",
269+
authProfileId: "openai:work",
270+
timeoutMs: 30_000,
271+
},
272+
});
273+
```
274+
275+
This mode accepts exactly one user message. Core derives the configured CLI
276+
or harness owner, starts a fresh context, exposes no model-callable tools,
277+
and never falls back to direct provider transport. Unsupported runtimes fail
278+
before inference. `result.execution.owner` reports the selected owner;
279+
token usage remains absent when a CLI cannot report it.
280+
281+
Completion failures expose a stable `code` on the thrown error. Isolated
282+
callers can distinguish authorization, invalid isolated input, unsupported
283+
or unavailable runtimes, aborts, timeouts, rejected output, and other
284+
completion failures without matching message text.
285+
254286
Provider orchestration can also acquire the configured local-service
255287
lifecycle before issuing an HTTP request:
256288

@@ -297,7 +329,7 @@ two-party event loops that do not go through the shared inbound reply runner.
297329
`medium`; `max` and `ultra` become `max` when supported, otherwise `xhigh`.
298330

299331
<Warning>
300-
Model overrides require operator opt-in via `plugins.entries.<id>.llm.allowModelOverride: true` in config. Use `plugins.entries.<id>.llm.allowedModels` to restrict trusted plugins to specific canonical `provider/model` targets. Cross-agent completions require `plugins.entries.<id>.llm.allowAgentIdOverride: true`.
332+
Model overrides require operator opt-in via `plugins.entries.<id>.llm.allowModelOverride: true` in config. `plugins.entries.<id>.llm.allowedModels` restricts those overrides; `plugins.entries.<id>.llm.allowedCompletionModels` separately restricts every completion, including host-resolved defaults. For direct completions, a `model@profile` override remains part of the authorized model override. Isolated `model@profile` overrides and `execution.authProfileId` require `plugins.entries.<id>.llm.allowAuthProfileOverride: true`. Cross-agent completions require `plugins.entries.<id>.llm.allowAgentIdOverride: true`.
301333
</Warning>
302334

303335
</Accordion>

‎docs/tools/llm-task.md‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ allowlist mode instead.
4747
"entries": {
4848
"llm-task": {
4949
"enabled": true,
50+
"llm": {
51+
"allowModelOverride": true,
52+
"allowedCompletionModels": ["openai/gpt-5.6-sol"],
53+
"allowAuthProfileOverride": true
54+
},
5055
"config": {
5156
"defaultProvider": "openai",
5257
"defaultModel": "gpt-5.6-sol",
5358
"defaultAuthProfileId": "main",
54-
"allowedModels": ["openai/gpt-5.6-sol"],
5559
"maxTokens": 800,
5660
"timeoutMs": 30000
5761
}
@@ -61,9 +65,15 @@ allowlist mode instead.
6165
}
6266
```
6367

64-
`allowedModels` is an allowlist of `provider/model` strings; a request for any
65-
other model is rejected. All other keys are per-call fallbacks used when the
66-
tool call omits that parameter.
68+
The `llm` block is host-owned authorization. `allowedCompletionModels` restricts every
69+
completion, so include the resolved agent default as well as any override targets.
70+
`allowAuthProfileOverride` permits `defaultAuthProfileId` and the per-call
71+
`authProfileId` parameter. The `config` keys are selection defaults used when a
72+
tool call omits the corresponding parameter.
73+
74+
Run `openclaw doctor --fix` once for llm-task entries created by older releases.
75+
Doctor grants the shipped model/profile selection permissions and moves any
76+
legacy `config.allowedModels` value into `llm.allowedCompletionModels` without widening it.
6777

6878
## Tool parameters
6979

@@ -85,6 +95,27 @@ tool call omits that parameter.
8595
Returns `details.json` (the parsed, schema-validated JSON) plus `details.provider`
8696
and `details.model` naming what actually ran.
8797

98+
Each call starts a fresh prompt-only inference operation. It does not reuse the
99+
calling agent's transcript or native runtime session, run agent lifecycle hooks,
100+
or deliver model output to a channel. OpenClaw uses the selected provider,
101+
model, auth profile, and runtime exactly once; it does not fall back to another
102+
route when that owner cannot provide a literal zero-tool call.
103+
104+
A selected agent harness must implement isolated completion. Otherwise the call
105+
fails before inference with a `does not support isolated completion` error.
106+
This fail-closed behavior prevents a JSON task from silently becoming a normal
107+
tool-capable agent turn.
108+
109+
CLI runtimes must provide the equivalent isolated preparation guarantee. The
110+
bundled Claude and Gemini CLI runtimes do; a different CLI runtime that has not
111+
adopted this internal contract fails before its process starts.
112+
113+
Gemini CLI isolated completion supports Gemini API-key and Vertex auth. Google
114+
OAuth and compute/Code Assist auth are rejected because managed-account policy
115+
can add administrator-required tools after local CLI settings are loaded.
116+
Gemini prompts containing native `@path` includes or a leading `/command` also
117+
fail before inference because Gemini CLI has no literal raw-input mode.
118+
88119
## Example: Lobster workflow step
89120

90121
### Important limitation
@@ -130,8 +161,11 @@ openclaw.invoke --tool llm-task --action json --args-json '{
130161

131162
- **JSON-only**: the model is instructed to return only a JSON value, no code
132163
fences, no commentary.
133-
- **No tools**: the underlying run has tools disabled, so the model cannot call
134-
out mid-task.
164+
- **No tools**: the selected runtime must expose a literal empty model-callable
165+
tool surface. OpenClaw rejects tool-shaped results instead of treating them as
166+
task output.
167+
- **Isolated**: the run has no agent transcript, session reuse, lifecycle hooks,
168+
channel delivery, or provider fallback.
135169
- Treat output as untrusted unless you validate it with `schema`.
136170
- Put approvals before any side-effecting step (send, post, exec) that consumes
137171
this output.

‎extensions/anthropic/cli-backend.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ClaudeCliAuthCredential =
2929
| { type: string };
3030

3131
type ClaudeCliPreparedExecution = CliBackendPreparedExecution & {
32+
isolatedCompletionEnforced?: true;
3233
secretInput: {
3334
fd: 3;
3435
fingerprint: string;
@@ -207,15 +208,21 @@ export function buildAnthropicCliBackend(): CliBackendPlugin {
207208
prepareExecution: (context) => {
208209
const credentialContext = context as typeof context & {
209210
authCredential?: ClaudeCliAuthCredential;
211+
isolatedCompletionPrompt?: string;
212+
isolatedCompletionSystemPrompt?: string;
210213
};
211214
const authInput = resolveClaudeCliAuthInput(credentialContext.authCredential);
215+
const isolatedCompletion = credentialContext.isolatedCompletionPrompt !== undefined;
212216
const env = {
213217
...resolveClaudeCliAutoCompactEnv(context.contextTokenBudget),
214218
...authInput?.env,
215219
};
216-
return Object.keys(env).length > 0
220+
return Object.keys(env).length > 0 || isolatedCompletion
217221
? {
218222
env,
223+
// The paired side-question argv projection disables settings, memory,
224+
// hooks, session persistence, and tools before process launch.
225+
...(isolatedCompletion ? { isolatedCompletionEnforced: true as const } : {}),
219226
...(authInput?.clearEnv ? { clearEnv: authInput.clearEnv } : {}),
220227
...(authInput?.secretInput ? { secretInput: authInput.secretInput } : {}),
221228
...(authInput?.cleanup ? { cleanup: authInput.cleanup } : {}),

‎extensions/anthropic/cli-shared.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ describe("Claude CLI adapter equivalence", () => {
6565
}),
6666
).toEqual({ env: { CLAUDE_CODE_AUTO_COMPACT_WINDOW: "100000" } });
6767
});
68+
69+
it("privately acknowledges isolated completion preparation", () => {
70+
const backend = buildAnthropicCliBackend();
71+
const prepared = backend.prepareExecution?.({
72+
workspaceDir: "/tmp/openclaw-claude-cli",
73+
provider: "claude-cli",
74+
modelId: "claude-opus-4-8",
75+
isolatedCompletionPrompt: "TASK: return JSON",
76+
isolatedCompletionSystemPrompt: "Return JSON.",
77+
} as Parameters<NonNullable<typeof backend.prepareExecution>>[0] & {
78+
isolatedCompletionPrompt: string;
79+
isolatedCompletionSystemPrompt: string;
80+
}) as { env?: Record<string, string>; isolatedCompletionEnforced?: true };
81+
82+
expect(prepared).toEqual({ env: {}, isolatedCompletionEnforced: true });
83+
});
6884
});
6985

7086
describe("resolveClaudeCliAutoCompactEnv", () => {

‎extensions/clickclack/src/inbound.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ function createRuntime(): PluginRuntime {
6767
model: "gpt-5.4-mini",
6868
agentId: "service-bot",
6969
usage: {},
70+
execution: {
71+
mode: "direct-provider",
72+
owner: { kind: "provider", id: "openai" },
73+
},
7074
audit: {
7175
caller: { kind: "plugin", id: "clickclack" },
7276
},
@@ -291,6 +295,10 @@ describe("handleClickClackInbound", () => {
291295
model: "gpt-5.4-mini",
292296
agentId: "service-bot",
293297
usage: {},
298+
execution: {
299+
mode: "direct-provider",
300+
owner: { kind: "provider", id: "openai" },
301+
},
294302
audit: { caller: { kind: "plugin", id: "clickclack" } },
295303
});
296304
setClickClackRuntime(runtime);

0 commit comments

Comments
 (0)