mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 08:00:06 +00:00
fix(assistant): the step after the ask for the answer may only write text, so Claude Sonnet 5.5 can no longer offer its follow-ups a second time instead (#3016)
This commit is contained in:
@@ -238,6 +238,23 @@ describe('AnthropicMessagesClient', () => {
|
||||
expect([0, 1, 2, 3].map((i) => dig(body, 'messages', i, 'role'))).toEqual(['user', 'assistant', 'user', undefined]);
|
||||
});
|
||||
|
||||
it('ANTH-009: a text-only request keeps the tools for the history and sets tool_choice none (#3016)', async () => {
|
||||
const http = fetchAnswering(streamResponse(STREAM));
|
||||
await run(
|
||||
new AnthropicMessagesClient('claude-sonnet', 'sk-ant-key', http.fetcher).stream(
|
||||
{ ...REQUEST, toolChoice: 'none' },
|
||||
signal(),
|
||||
),
|
||||
);
|
||||
const body = http.body();
|
||||
expect(body.tool_choice).toEqual({ type: 'none' });
|
||||
expect(dig(body, 'tools', 0, 'name')).toBe('create_place');
|
||||
|
||||
const plain = fetchAnswering(streamResponse(STREAM));
|
||||
await run(new AnthropicMessagesClient('claude-sonnet', 'sk-ant-key', plain.fetcher).stream(REQUEST, signal()));
|
||||
expect(plain.body().tool_choice).toBeUndefined();
|
||||
});
|
||||
|
||||
it('ANTH-006: marks the end of the history and the end of what came before the question for the cache', async () => {
|
||||
const http = fetchAnswering(streamResponse(STREAM));
|
||||
await run(new AnthropicMessagesClient('m', 'k', http.fetcher).stream(REQUEST, signal()));
|
||||
@@ -458,6 +475,17 @@ describe('OpenAiChatClient', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('OACH-009: tool_choice is auto unless the request asks for text only (#3016)', async () => {
|
||||
const client = (fetcher: AiFetch) =>
|
||||
new OpenAiChatClient('openai', 'gpt-5-mini', 'https://api.openai.com/v1', 'sk-key', fetcher);
|
||||
const auto = fetchAnswering(streamResponse(STREAM));
|
||||
await run(client(auto.fetcher).stream(REQUEST, signal()));
|
||||
expect(auto.body().tool_choice).toBe('auto');
|
||||
const none = fetchAnswering(streamResponse(STREAM));
|
||||
await run(client(none.fetcher).stream({ ...REQUEST, toolChoice: 'none' }, signal()));
|
||||
expect(none.body().tool_choice).toBe('none');
|
||||
});
|
||||
|
||||
it('OACH-002: streams the text and assembles the tool call by its index', async () => {
|
||||
const events = await run(
|
||||
new OpenAiChatClient('openai', 'm', 'https://x', 'k', fetchAnswering(streamResponse(STREAM)).fetcher).stream(
|
||||
@@ -689,6 +717,20 @@ describe('OpenAiResponsesClient', () => {
|
||||
expect(dig(body, 'input', 0)).toEqual({ type: 'message', role: 'developer', content: 'Trip: Japan, 3 days' });
|
||||
});
|
||||
|
||||
it('OARS-006: tool_choice is auto unless the request asks for text only (#3016)', async () => {
|
||||
const auto = fetchAnswering(streamResponse(STREAM));
|
||||
await run(new OpenAiResponsesClient('gpt-6.1-sol', tokens('at-1'), auto.fetcher).stream(REQUEST, signal()));
|
||||
expect(auto.body().tool_choice).toBe('auto');
|
||||
const none = fetchAnswering(streamResponse(STREAM));
|
||||
await run(
|
||||
new OpenAiResponsesClient('gpt-6.1-sol', tokens('at-1'), none.fetcher).stream(
|
||||
{ ...REQUEST, toolChoice: 'none' },
|
||||
signal(),
|
||||
),
|
||||
);
|
||||
expect(none.body().tool_choice).toBe('none');
|
||||
});
|
||||
|
||||
it('OARS-002: streams text, yields the call, then usage, the items to replay and the finish', async () => {
|
||||
const events = await run(
|
||||
new OpenAiResponsesClient('m', tokens('at'), fetchAnswering(streamResponse(STREAM)).fetcher).stream(
|
||||
|
||||
@@ -830,6 +830,10 @@ describe('runAgentLoop', () => {
|
||||
]);
|
||||
const outcome = await runAgentLoop(t.deps, t.input, t.writer, new AbortController().signal);
|
||||
expect(outcome.end).toBe('stop');
|
||||
// Only the step after the ask may not call a tool: a model offering follow-ups again has to write (#3016).
|
||||
expect(t.requests[0].toolChoice).toBeUndefined();
|
||||
expect(t.requests[1].toolChoice).toBe('none');
|
||||
expect(t.requests[1].tools.length).toBeGreaterThan(0);
|
||||
const second = t.requests[1].messages;
|
||||
expect(second.at(-2)).toEqual({
|
||||
role: 'assistant',
|
||||
@@ -860,6 +864,20 @@ describe('runAgentLoop', () => {
|
||||
expect(t.requests).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('ASTAGT-047: the text-only request is the one step after the ask, never the ones before or after it (#3016)', async () => {
|
||||
const t = setup([
|
||||
[{ type: 'tool-call', call: { id: 'l1', name: 'list_places', args: {} } }],
|
||||
[ask('toolu_9', ['More stops']), { type: 'finish', reason: 'tool-calls' }],
|
||||
[
|
||||
{ type: 'text-delta', delta: 'Two stops so far.' },
|
||||
{ type: 'finish', reason: 'stop' },
|
||||
],
|
||||
]);
|
||||
const outcome = await runAgentLoop(t.deps, t.input, t.writer, new AbortController().signal);
|
||||
expect(outcome.end).toBe('stop');
|
||||
expect(t.requests.map((request) => request.toolChoice)).toEqual([undefined, undefined, 'none']);
|
||||
});
|
||||
|
||||
it('ASTAGT-045: follow-ups with no answer after an announcing first answer are still asked for the answer', async () => {
|
||||
const t = setup([
|
||||
[{ type: 'text-delta', delta: 'Let me check your places:' }],
|
||||
|
||||
Reference in New Issue
Block a user