Skip to content

Commit 97c031a

Browse files
authored
feat: Add first-class infer CLI for inference workflows (#62129)
* refresh infer branch onto latest main * flatten infer media commands * fix tts runtime facade export * validate explicit web search providers * fix infer auth logout persistence
1 parent dfb6c9c commit 97c031a

28 files changed

Lines changed: 3724 additions & 28 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Docs: https://docs.openclaw.ai
66

77
### Changes
88

9+
- CLI/infer: add a first-class `openclaw infer ...` hub for provider-backed inference workflows across model, media, web, and embedding tasks. Thanks @Takhoffman.
910
- Plugins/webhooks: add a bundled webhook ingress plugin so external automation can create and drive bound TaskFlows through per-route shared-secret endpoints. (#61892) Thanks @mbelinky.
1011
- Tools/media generation: preserve intent across auth-backed image, music, and video provider fallback, remap size, aspect ratio, resolution, and duration hints to the closest supported option, and surface explicit provider capabilities plus mode-aware video-to-video support.
1112
- Memory/wiki: restore the bundled `memory-wiki` stack with plugin, CLI, sync/query/apply tooling, and memory-host integration for wiki-backed memory workflows.
@@ -29,6 +30,7 @@ Docs: https://docs.openclaw.ai
2930
### Fixes
3031

3132
- Plugins/media: when `plugins.allow` is set, capability fallback now merges bundled capability plugin ids into the allowlist (not only `plugins.entries`), so media understanding providers such as OpenAI-compatible STT load for voice transcription without requiring `openai` in `plugins.allow`. (#62205) Thanks @neeravmakwana.
33+
- CLI/infer: keep provider-backed infer behavior aligned with actual runtime execution by fixing explicit TTS override handling, profile-aware gateway TTS prefs resolution, per-request transcription `prompt`/`language` overrides, image output MIME/extension mismatches, configured web-search fallback behavior, and agent-vs-CLI web-search execution drift.
3234
- Auth/OpenAI Codex OAuth: reload fresh on-disk credentials inside the locked refresh path and retry once after `refresh_token_reused` rotates only the stored refresh token, so relogin/restart recovery stops getting stuck on stale cached auth state. Thanks @owen-ever.
3335
- Agents/history and replies: buffer phaseless OpenAI WS text until a real assistant phase arrives, keep replay and SSE history sequence tracking aligned, hide commentary and leaked tool XML from user-visible history, and keep history-based follow-up replies on `final_answer` text only. (#61729, #61747, #61829, #61855, #61954) Thanks @100yenadmin, @afurm, and @openperf.
3436
- Plugins/channels: keep bundled channel artifact and secret-contract loading stable under lazy loading, preserve plugin-schema defaults during install, and fix Windows `file://` plus native-Jiti plugin loader paths so onboarding, doctor, `openclaw secret`, and bundled plugin installs work again. (#61832, #61836, #61853, #61856) Thanks @Zeesejo and @SuperMarioYL.

‎docs/cli/capability.md‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
---
2+
summary: "Infer-first CLI for provider-backed model, image, audio, TTS, video, web, and embedding workflows"
3+
read_when:
4+
- Adding or modifying `openclaw infer` commands
5+
- Designing stable headless capability automation
6+
title: "Inference CLI"
7+
---
8+
9+
# Inference CLI
10+
11+
`openclaw infer` is the canonical headless surface for provider-backed inference workflows.
12+
13+
`openclaw capability` remains supported as a fallback alias for compatibility.
14+
15+
It intentionally exposes capability families, not raw gateway RPC names and not raw agent tool ids.
16+
17+
## Command tree
18+
19+
```text
20+
openclaw infer
21+
list
22+
inspect
23+
24+
model
25+
run
26+
list
27+
inspect
28+
providers
29+
auth login
30+
auth logout
31+
auth status
32+
33+
image
34+
generate
35+
edit
36+
describe
37+
describe-many
38+
providers
39+
40+
audio
41+
transcribe
42+
providers
43+
44+
tts
45+
convert
46+
voices
47+
providers
48+
status
49+
enable
50+
disable
51+
set-provider
52+
53+
video
54+
generate
55+
describe
56+
providers
57+
58+
web
59+
search
60+
fetch
61+
providers
62+
63+
embedding
64+
create
65+
providers
66+
```
67+
68+
## Transport
69+
70+
Supported transport flags:
71+
72+
- `--local`
73+
- `--gateway`
74+
75+
Default transport is implicit auto at the command-family level:
76+
77+
- Stateless execution commands default to local.
78+
- Gateway-managed state commands default to gateway.
79+
80+
Examples:
81+
82+
```bash
83+
openclaw infer model run --prompt "hello" --json
84+
openclaw infer image generate --prompt "friendly lobster" --json
85+
openclaw infer tts status --json
86+
openclaw infer embedding create --text "hello world" --json
87+
```
88+
89+
## JSON output
90+
91+
Capability commands normalize JSON output under a shared envelope:
92+
93+
```json
94+
{
95+
"ok": true,
96+
"capability": "image.generate",
97+
"transport": "local",
98+
"provider": "openai",
99+
"model": "gpt-image-1",
100+
"attempts": [],
101+
"outputs": []
102+
}
103+
```
104+
105+
Top-level fields are stable:
106+
107+
- `ok`
108+
- `capability`
109+
- `transport`
110+
- `provider`
111+
- `model`
112+
- `attempts`
113+
- `outputs`
114+
- `error`
115+
116+
## Notes
117+
118+
- `model run` reuses the agent runtime so provider/model overrides behave like normal agent execution.
119+
- `tts status` defaults to gateway because it reflects gateway-managed TTS state.

‎docs/cli/index.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This page describes the current CLI behavior. If commands change, update this do
3535
- [`logs`](/cli/logs)
3636
- [`system`](/cli/system)
3737
- [`models`](/cli/models)
38+
- [`infer`](/cli/capability)
3839
- [`memory`](/cli/memory)
3940
- [`directory`](/cli/directory)
4041
- [`nodes`](/cli/nodes)
@@ -248,6 +249,16 @@ openclaw [--dev] [--profile <name>] <command>
248249
fallbacks list|add|remove|clear
249250
image-fallbacks list|add|remove|clear
250251
scan
252+
infer (alias: capability)
253+
list
254+
inspect
255+
model run|list|inspect|providers|auth login|logout|status
256+
image generate|edit|describe|describe-many|providers
257+
audio transcribe|providers
258+
tts convert|voices|providers|status|enable|disable|set-provider
259+
video generate|describe|providers
260+
web search|fetch|providers
261+
embedding create|providers
251262
auth add|login|login-github-copilot|setup-token|paste-token
252263
auth order get|set|clear
253264
sandbox

‎extensions/memory-core/runtime-api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ export {
44
DEFAULT_LOCAL_MODEL,
55
getBuiltinMemoryEmbeddingProviderDoctorMetadata,
66
listBuiltinAutoSelectMemoryEmbeddingProviderDoctorMetadata,
7+
registerBuiltInMemoryEmbeddingProviders,
78
} from "./src/memory/provider-adapters.js";
9+
export { createEmbeddingProvider } from "./src/memory/embeddings.js";
810
export {
911
resolveMemoryCacheSummary,
1012
resolveMemoryFtsState,

‎extensions/speech-core/runtime-api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {
99
isTtsProviderConfigured,
1010
listSpeechVoices,
1111
maybeApplyTtsToPayload,
12+
resolveExplicitTtsOverrides,
1213
resolveTtsAutoMode,
1314
resolveTtsConfig,
1415
resolveTtsPrefsPath,

‎extensions/speech-core/src/tts.ts‎

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import type { ReplyPayload } from "openclaw/plugin-sdk/reply-runtime";
2525
import { isVerbose, logVerbose } from "openclaw/plugin-sdk/runtime-env";
2626
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/sandbox";
2727
import {
28-
CONFIG_DIR,
2928
normalizeOptionalString,
29+
resolveConfigDir,
3030
resolveUserPath,
3131
stripMarkdown,
3232
} from "openclaw/plugin-sdk/text-runtime";
@@ -41,6 +41,7 @@ import {
4141
summarizeText,
4242
type SpeechModelOverridePolicy,
4343
type SpeechProviderConfig,
44+
type SpeechProviderOverrides,
4445
type SpeechVoiceOption,
4546
type TtsDirectiveOverrides,
4647
type TtsDirectiveParseResult,
@@ -173,7 +174,7 @@ function resolveTtsPrefsPathValue(prefsPath: string | undefined): string {
173174
if (envPath) {
174175
return resolveUserPath(envPath);
175176
}
176-
return path.join(CONFIG_DIR, "settings", "tts.json");
177+
return path.join(resolveConfigDir(process.env), "settings", "tts.json");
177178
}
178179

179180
function resolveModelOverridePolicy(
@@ -502,6 +503,66 @@ export function setTtsProvider(prefsPath: string, provider: TtsProvider): void {
502503
});
503504
}
504505

506+
export function resolveExplicitTtsOverrides(params: {
507+
cfg: OpenClawConfig;
508+
prefsPath?: string;
509+
provider?: string;
510+
modelId?: string;
511+
voiceId?: string;
512+
}): TtsDirectiveOverrides {
513+
const providerInput = params.provider?.trim();
514+
const modelId = params.modelId?.trim();
515+
const voiceId = params.voiceId?.trim();
516+
const config = resolveTtsConfig(params.cfg);
517+
const prefsPath = params.prefsPath ?? resolveTtsPrefsPath(config);
518+
const selectedProvider =
519+
canonicalizeSpeechProviderId(providerInput, params.cfg) ??
520+
(modelId || voiceId ? getTtsProvider(config, prefsPath) : undefined);
521+
522+
if (providerInput && !selectedProvider) {
523+
throw new Error(`Unknown TTS provider "${providerInput}".`);
524+
}
525+
526+
if (!modelId && !voiceId) {
527+
return selectedProvider ? { provider: selectedProvider } : {};
528+
}
529+
530+
if (!selectedProvider) {
531+
throw new Error("TTS model or voice overrides require a resolved provider.");
532+
}
533+
534+
const provider = getSpeechProvider(selectedProvider, params.cfg);
535+
if (!provider) {
536+
throw new Error(`speech provider ${selectedProvider} is not registered`);
537+
}
538+
if (!provider.resolveTalkOverrides) {
539+
throw new Error(
540+
`TTS provider "${selectedProvider}" does not support model or voice overrides.`,
541+
);
542+
}
543+
544+
const providerOverrides = provider.resolveTalkOverrides({
545+
talkProviderConfig: {},
546+
params: {
547+
...(voiceId ? { voiceId } : {}),
548+
...(modelId ? { modelId } : {}),
549+
},
550+
});
551+
if ((voiceId || modelId) && (!providerOverrides || Object.keys(providerOverrides).length === 0)) {
552+
throw new Error(
553+
`TTS provider "${selectedProvider}" ignored the requested model or voice overrides.`,
554+
);
555+
}
556+
557+
const overridesRecord = providerOverrides as SpeechProviderOverrides;
558+
return {
559+
provider: selectedProvider,
560+
providerOverrides: {
561+
[provider.id]: overridesRecord,
562+
},
563+
};
564+
}
565+
505566
export function getTtsMaxLength(prefsPath: string): number {
506567
const prefs = readPrefs(prefsPath);
507568
return prefs.tts?.maxLength ?? DEFAULT_TTS_MAX_LENGTH;

‎src/agents/pi-embedded-runner/model.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ function findInlineModelMatch(params: {
232232
);
233233
}
234234

235-
export { buildModelAliasLines };
236-
export { buildInlineProviderModels };
235+
export { buildModelAliasLines, buildInlineProviderModels };
237236

238237
function resolveConfiguredProviderConfig(
239238
cfg: OpenClawConfig | undefined,
@@ -336,7 +335,6 @@ function applyConfiguredProviderOverrides(params: {
336335
providerRequest,
337336
);
338337
}
339-
340338
function resolveExplicitModelWithRegistry(params: {
341339
provider: string;
342340
modelId: string;

‎src/agents/tools/web-search.ts‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { RuntimeWebSearchMetadata } from "../../secrets/runtime-web-tools.t
44
import {
55
resolveWebSearchDefinition,
66
resolveWebSearchProviderId,
7+
runWebSearch,
78
} from "../../web-search/runtime.js";
89
import type { AnyAgentTool } from "./common.js";
910
import { jsonResult } from "./common.js";
@@ -16,16 +17,17 @@ export function createWebSearchTool(options?: {
1617
}): AnyAgentTool | null {
1718
const runtimeProviderId =
1819
options?.runtimeWebSearch?.selectedProvider ?? options?.runtimeWebSearch?.providerConfigured;
20+
const preferRuntimeProviders =
21+
Boolean(runtimeProviderId) &&
22+
!resolveManifestContractOwnerPluginId({
23+
contract: "webSearchProviders",
24+
value: runtimeProviderId,
25+
origin: "bundled",
26+
config: options?.config,
27+
});
1928
const resolved = resolveWebSearchDefinition({
2029
...options,
21-
preferRuntimeProviders:
22-
Boolean(runtimeProviderId) &&
23-
!resolveManifestContractOwnerPluginId({
24-
contract: "webSearchProviders",
25-
value: runtimeProviderId,
26-
origin: "bundled",
27-
config: options?.config,
28-
}),
30+
preferRuntimeProviders,
2931
});
3032
if (!resolved) {
3133
return null;
@@ -36,7 +38,19 @@ export function createWebSearchTool(options?: {
3638
name: "web_search",
3739
description: resolved.definition.description,
3840
parameters: resolved.definition.parameters,
39-
execute: async (_toolCallId, args) => jsonResult(await resolved.definition.execute(args)),
41+
execute: async (_toolCallId, args) => {
42+
const result = await runWebSearch({
43+
config: options?.config,
44+
sandboxed: options?.sandboxed,
45+
runtimeWebSearch: options?.runtimeWebSearch,
46+
preferRuntimeProviders,
47+
args,
48+
});
49+
return jsonResult({
50+
...result.result,
51+
provider: result.provider,
52+
});
53+
},
4054
};
4155
}
4256

0 commit comments

Comments
 (0)