Skip to content

Commit 4831cb3

Browse files
author
liuxiaopai-ai
committed
Agent UX: clarify missing API key model errors
1 parent 5008837 commit 4831cb3

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Docs: https://docs.openclaw.ai
4646
- BlueBubbles/Message metadata: harden send response ID extraction, include sender identity in DM context, and normalize inbound `message_id` selection to avoid duplicate ID metadata. (#23970) Thanks @tyler6204.
4747
- Gateway/Control UI method guard: allow POST requests to non-UI routes to fall through when no base path is configured, and add POST regression coverage for fallthrough and base-path 405 behavior. (#23970) Thanks @tyler6204.
4848
- Authentication: classify `permission_error` as `auth_permanent` for profile fallback. (#31324) Thanks @Sid-Qin.
49+
- TUI/Model auth errors: when a selected model fails due to missing provider API key, show a concise actionable hint (`openclaw configure`) instead of only surfacing the long fallback-chain error blob. (#31544)
4950
- Security/Prompt spoofing hardening: stop injecting queued runtime events into user-role prompt text, route them through trusted system-prompt context, and neutralize inbound spoof markers like `[System Message]` and line-leading `System:` in untrusted message content. (#30448)
5051
- Gateway/Node browser proxy routing: honor `profile` from `browser.request` JSON body when query params omit it, while preserving query-profile precedence when both are present. (#28852) Thanks @Sid-Qin.
5152
- Browser/Extension relay reconnect tolerance: keep `/json/version` and `/cdp` reachable during short MV3 worker disconnects when attached targets still exist, and retain clients across reconnect grace windows. (#30232) Thanks @Sid-Qin.

src/auto-reply/reply/agent-runner-execution.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ export type AgentRunLoopResult =
6969
}
7070
| { kind: "final"; payload: ReplyPayload };
7171

72+
function resolveMissingApiKeyProvider(message: string): string | null {
73+
const match = message.match(/No API key found for provider "([^"]+)"/i);
74+
const provider = match?.[1]?.trim();
75+
return provider || null;
76+
}
77+
7278
export async function runAgentTurnWithFallback(params: {
7379
commandBody: string;
7480
followupRun: FollowupRun;
@@ -570,11 +576,14 @@ export async function runAgentTurnWithFallback(params: {
570576
? sanitizeUserFacingText(message, { errorContext: true })
571577
: message;
572578
const trimmedMessage = safeMessage.replace(/\.\s*$/, "");
579+
const missingApiKeyProvider = resolveMissingApiKeyProvider(trimmedMessage);
573580
const fallbackText = isContextOverflow
574581
? "⚠️ Context overflow — prompt too large for this model. Try a shorter message or a larger-context model."
575582
: isRoleOrderingError
576583
? "⚠️ Message ordering conflict - please try again. If this persists, use /new to start a fresh session."
577-
: `⚠️ Agent failed before reply: ${trimmedMessage}.\nLogs: openclaw logs --follow`;
584+
: missingApiKeyProvider
585+
? `⚠️ Missing API key for provider "${missingApiKeyProvider}".\nRun openclaw configure (or set the provider API key), then retry.\nLogs: openclaw logs --follow`
586+
: `⚠️ Agent failed before reply: ${trimmedMessage}.\nLogs: openclaw logs --follow`;
578587

579588
return {
580589
kind: "final",

src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ describe("runReplyAgent onAgentRunStart", () => {
177177

178178
expect(onAgentRunStart).not.toHaveBeenCalled();
179179
expect(result).toMatchObject({
180-
text: expect.stringContaining('No API key found for provider "anthropic".'),
180+
text: expect.stringContaining('Missing API key for provider "anthropic".'),
181181
});
182+
expect(result.text).toContain("openclaw configure");
182183
});
183184

184185
it("emits start callback when cli runner starts", async () => {

0 commit comments

Comments
 (0)