mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:20:44 +00:00
fix(plugins): honor inferred agent model defaults
This commit is contained in:
@@ -922,6 +922,53 @@ describe("active-memory plugin", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("infers the configured provider for bare active-memory default models", async () => {
|
||||
api.config = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "gpt-5.5" },
|
||||
},
|
||||
},
|
||||
models: {
|
||||
providers: {
|
||||
"openai-codex": {
|
||||
baseUrl: "https://chatgpt.com/backend-api/codex",
|
||||
models: [
|
||||
{
|
||||
id: "gpt-5.5",
|
||||
name: "GPT 5.5",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 200_000,
|
||||
maxTokens: 128_000,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
api.pluginConfig = {
|
||||
agents: ["main"],
|
||||
};
|
||||
plugin.register(api as unknown as OpenClawPluginApi);
|
||||
|
||||
await hooks.before_prompt_build(
|
||||
{ prompt: "what wings should i order? bare model default", messages: [] },
|
||||
{
|
||||
agentId: "main",
|
||||
trigger: "user",
|
||||
sessionKey: "agent:main:main",
|
||||
messageProvider: "webchat",
|
||||
},
|
||||
);
|
||||
|
||||
expect(runEmbeddedPiAgent.mock.calls.at(-1)?.[0]).toMatchObject({
|
||||
provider: "openai-codex",
|
||||
model: "gpt-5.5",
|
||||
});
|
||||
});
|
||||
|
||||
it("skips recall when no model or explicit fallback resolves", async () => {
|
||||
api.config = {};
|
||||
api.pluginConfig = {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
resolveAgentDir,
|
||||
resolveAgentEffectiveModelPrimary,
|
||||
resolveAgentWorkspaceDir,
|
||||
resolveDefaultModelForAgent,
|
||||
} from "openclaw/plugin-sdk/agent-runtime";
|
||||
import {
|
||||
resolveLivePluginConfigObject,
|
||||
@@ -1550,13 +1551,11 @@ function extractRecentTurns(messages: unknown[]): ActiveRecallRecentTurn[] {
|
||||
return turns;
|
||||
}
|
||||
|
||||
function parseModelCandidate(modelRef: string | undefined) {
|
||||
function parseModelCandidate(modelRef: string | undefined, defaultProvider = DEFAULT_PROVIDER) {
|
||||
if (!modelRef) {
|
||||
return undefined;
|
||||
}
|
||||
return (
|
||||
parseModelRef(modelRef, DEFAULT_PROVIDER) ?? { provider: DEFAULT_PROVIDER, model: modelRef }
|
||||
);
|
||||
return parseModelRef(modelRef, defaultProvider) ?? { provider: defaultProvider, model: modelRef };
|
||||
}
|
||||
|
||||
function getModelRef(
|
||||
@@ -1570,14 +1569,20 @@ function getModelRef(
|
||||
): { provider: string; model: string } | undefined {
|
||||
const currentRunModel =
|
||||
ctx?.modelProviderId && ctx?.modelId ? `${ctx.modelProviderId}/${ctx.modelId}` : undefined;
|
||||
const configuredDefaultModel = resolveAgentEffectiveModelPrimary(api.config, agentId)
|
||||
? resolveDefaultModelForAgent({ cfg: api.config, agentId })
|
||||
: undefined;
|
||||
const defaultProvider = configuredDefaultModel?.provider ?? DEFAULT_PROVIDER;
|
||||
const candidates = [
|
||||
config.model,
|
||||
currentRunModel,
|
||||
resolveAgentEffectiveModelPrimary(api.config, agentId),
|
||||
configuredDefaultModel
|
||||
? `${configuredDefaultModel.provider}/${configuredDefaultModel.model}`
|
||||
: undefined,
|
||||
config.modelFallback,
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
const parsed = parseModelCandidate(candidate);
|
||||
const parsed = parseModelCandidate(candidate, defaultProvider);
|
||||
if (parsed) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user