Q77: a session keeps the model and account it started with
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8fcdd61bc5
commit
d557e42676
8 files changed
+89
-11
No files matched your search
@@ -67,4 +67,51 @@ describe("agent model", () => {
|
||||
await expect(execution.runTask({ orgId, taskId })).rejects.toThrow('Azure OpenAI calls the deployment configured on the provider; this agent asks for "gpt-5.4-mini".');
|
||||
connection.close();
|
||||
});
|
||||
|
||||
test("a session keeps the model and account it started with", async () => {
|
||||
const models: string[] = [];
|
||||
let onTurn = (_turn: number) => {};
|
||||
let lastPrompt = "";
|
||||
const turn = async (input: ProviderToolTurnInput): Promise<AgentTurnResult> => {
|
||||
models.push(input.model);
|
||||
const first = input.messages[0];
|
||||
if (first?.role === "user") lastPrompt = first.text;
|
||||
onTurn(models.length);
|
||||
return models.length < 3
|
||||
? { text: "Working.", toolCalls: [{ id: `c${models.length}`, name: "read_messages", arguments: {} }], rawResponseJson: "{}" }
|
||||
: { text: "done", toolCalls: [], rawResponseJson: "{}" };
|
||||
};
|
||||
const connection = new DatabaseConnection(join(tmpdir(), `ac-model-pin-${randomUUID()}.db`));
|
||||
const organization = new OrganizationService(connection.db);
|
||||
const providers = new ProviderService(connection.db, providerAdapters, testVault, undefined, turn);
|
||||
const execution = new TaskExecutionService(connection.db, providers);
|
||||
let orgId = "";
|
||||
let taskId = "";
|
||||
let providerId = "";
|
||||
connection.transaction(() => {
|
||||
orgId = organization.createOrganization({ organizationName: "Acme", employeeName: "Dana", mission: "m", goal: "g" });
|
||||
providerId = (connection.db.prepare("select id from providers where org_id = ? and provider_key = 'openai'").get(orgId) as { id: string }).id;
|
||||
providers.saveCredential({ orgId, providerId, secret: "sk-test", model: "gpt-5.4" });
|
||||
const agentId = organization.createAgent({ orgId, name: "Ada", role: "Engineer", department: "Engineering", modelProviderId: providerId, modelId: null, budgetCents: 1000, managerAgentId: null });
|
||||
taskId = organization.createTask({ orgId, title: "Work", description: "d", status: TASK_STATUS.IN_PROGRESS, assigneeAgentId: agentId, risk: RISK_LEVEL.LOW, projectId: null, goalId: null, workspaceId: null, priority: TASK_PRIORITY.NORMAL, requiresFilesystem: false });
|
||||
});
|
||||
onTurn = (count) => { if (count === 1) connection.db.prepare("update providers set model = 'gpt-6' where id = ?").run(providerId); };
|
||||
await execution.runTask({ orgId, taskId });
|
||||
expect(models).toEqual(["gpt-5.4", "gpt-5.4", "gpt-5.4"]);
|
||||
|
||||
// A resumed run builds its prompt and calls with the model it was pinned to, not today's configuration.
|
||||
models.length = 0;
|
||||
onTurn = () => {};
|
||||
const resumedId = (connection.db.prepare("select id from task_runs where task_id = ?").get(taskId) as { id: string }).id;
|
||||
connection.db.prepare("update task_runs set state = 'running', completed_at = null where id = ?").run(resumedId);
|
||||
await execution.executeRun(orgId, resumedId);
|
||||
expect(models).toEqual(["gpt-5.4", "gpt-5.4", "gpt-5.4"]);
|
||||
expect(lastPrompt).toContain("Provider: OpenAI gpt-5.4");
|
||||
|
||||
models.length = 0;
|
||||
onTurn = (count) => { if (count === 1) connection.db.prepare("update providers set credential_id = 'cred_reconnected' where id = ?").run(providerId); };
|
||||
await expect(execution.runTask({ orgId, taskId })).rejects.toThrow("The provider's account was reconnected during this session");
|
||||
expect(models).toEqual(["gpt-6"]);
|
||||
connection.close();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user