mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: update tool output format, use plain string instead of json string (#881)
This commit is contained in:
@@ -555,7 +555,7 @@ export const AppContainer = (props: AppContainerProps) => {
|
|||||||
historyManager.addItem(
|
historyManager.addItem(
|
||||||
{
|
{
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
text: 'Refreshing hierarchical memory (GEMINI.md or other context files)...',
|
text: 'Refreshing hierarchical memory (QWEN.md or other context files)...',
|
||||||
},
|
},
|
||||||
Date.now(),
|
Date.now(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import { OpenAIContentConverter } from './converter.js';
|
import { OpenAIContentConverter } from './converter.js';
|
||||||
import type { StreamingToolCallParser } from './streamingToolCallParser.js';
|
import type { StreamingToolCallParser } from './streamingToolCallParser.js';
|
||||||
|
import type { GenerateContentParameters, Content } from '@google/genai';
|
||||||
|
|
||||||
describe('OpenAIContentConverter', () => {
|
describe('OpenAIContentConverter', () => {
|
||||||
let converter: OpenAIContentConverter;
|
let converter: OpenAIContentConverter;
|
||||||
@@ -68,4 +69,77 @@ describe('OpenAIContentConverter', () => {
|
|||||||
expect(parser.getBuffer(0)).toBe('');
|
expect(parser.getBuffer(0)).toBe('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('convertGeminiRequestToOpenAI', () => {
|
||||||
|
const createRequestWithFunctionResponse = (
|
||||||
|
response: Record<string, unknown>,
|
||||||
|
): GenerateContentParameters => {
|
||||||
|
const contents: Content[] = [
|
||||||
|
{
|
||||||
|
role: 'model',
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
functionCall: {
|
||||||
|
id: 'call_1',
|
||||||
|
name: 'shell',
|
||||||
|
args: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
role: 'user',
|
||||||
|
parts: [
|
||||||
|
{
|
||||||
|
functionResponse: {
|
||||||
|
id: 'call_1',
|
||||||
|
name: 'shell',
|
||||||
|
response,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
model: 'models/test',
|
||||||
|
contents,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should extract raw output from function response objects', () => {
|
||||||
|
const request = createRequestWithFunctionResponse({
|
||||||
|
output: 'Raw output text',
|
||||||
|
});
|
||||||
|
|
||||||
|
const messages = converter.convertGeminiRequestToOpenAI(request);
|
||||||
|
const toolMessage = messages.find((message) => message.role === 'tool');
|
||||||
|
|
||||||
|
expect(toolMessage).toBeDefined();
|
||||||
|
expect(toolMessage?.content).toBe('Raw output text');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should prioritize error field when present', () => {
|
||||||
|
const request = createRequestWithFunctionResponse({
|
||||||
|
error: 'Command failed',
|
||||||
|
});
|
||||||
|
|
||||||
|
const messages = converter.convertGeminiRequestToOpenAI(request);
|
||||||
|
const toolMessage = messages.find((message) => message.role === 'tool');
|
||||||
|
|
||||||
|
expect(toolMessage).toBeDefined();
|
||||||
|
expect(toolMessage?.content).toBe('Command failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should stringify non-string responses', () => {
|
||||||
|
const request = createRequestWithFunctionResponse({
|
||||||
|
data: { value: 42 },
|
||||||
|
});
|
||||||
|
|
||||||
|
const messages = converter.convertGeminiRequestToOpenAI(request);
|
||||||
|
const toolMessage = messages.find((message) => message.role === 'tool');
|
||||||
|
|
||||||
|
expect(toolMessage).toBeDefined();
|
||||||
|
expect(toolMessage?.content).toBe('{"data":{"value":42}}');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -276,10 +276,7 @@ export class OpenAIContentConverter {
|
|||||||
messages.push({
|
messages.push({
|
||||||
role: 'tool' as const,
|
role: 'tool' as const,
|
||||||
tool_call_id: funcResponse.id || '',
|
tool_call_id: funcResponse.id || '',
|
||||||
content:
|
content: this.extractFunctionResponseContent(funcResponse.response),
|
||||||
typeof funcResponse.response === 'string'
|
|
||||||
? funcResponse.response
|
|
||||||
: JSON.stringify(funcResponse.response),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -359,6 +356,36 @@ export class OpenAIContentConverter {
|
|||||||
return { textParts, functionCalls, functionResponses, mediaParts };
|
return { textParts, functionCalls, functionResponses, mediaParts };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractFunctionResponseContent(response: unknown): string {
|
||||||
|
if (response === null || response === undefined) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof response === 'string') {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof response === 'object') {
|
||||||
|
const responseObject = response as Record<string, unknown>;
|
||||||
|
const output = responseObject['output'];
|
||||||
|
if (typeof output === 'string') {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = responseObject['error'];
|
||||||
|
if (typeof error === 'string') {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const serialized = JSON.stringify(response);
|
||||||
|
return serialized ?? String(response);
|
||||||
|
} catch {
|
||||||
|
return String(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine media type from MIME type
|
* Determine media type from MIME type
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -131,16 +131,14 @@ describe('ExitPlanModeTool', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await invocation.execute(signal);
|
const result = await invocation.execute(signal);
|
||||||
const expectedLlmMessage =
|
|
||||||
'User has approved your plan. You can now start coding. Start with updating your todo list if applicable.';
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result.llmContent).toContain(
|
||||||
llmContent: expectedLlmMessage,
|
'User has approved your plan. You can now start coding',
|
||||||
returnDisplay: {
|
);
|
||||||
type: 'plan_summary',
|
expect(result.returnDisplay).toEqual({
|
||||||
message: 'User approved the plan.',
|
type: 'plan_summary',
|
||||||
plan: params.plan,
|
message: 'User approved the plan.',
|
||||||
},
|
plan: params.plan,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockConfig.setApprovalMode).toHaveBeenCalledWith(
|
expect(mockConfig.setApprovalMode).toHaveBeenCalledWith(
|
||||||
@@ -188,15 +186,12 @@ describe('ExitPlanModeTool', () => {
|
|||||||
|
|
||||||
const result = await invocation.execute(signal);
|
const result = await invocation.execute(signal);
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result.llmContent).toBe(
|
||||||
llmContent: JSON.stringify({
|
'Plan execution was not approved. Remaining in plan mode.',
|
||||||
success: false,
|
);
|
||||||
plan: params.plan,
|
expect(result.returnDisplay).toBe(
|
||||||
error: 'Plan execution was not approved. Remaining in plan mode.',
|
'Plan execution was not approved. Remaining in plan mode.',
|
||||||
}),
|
);
|
||||||
returnDisplay:
|
|
||||||
'Plan execution was not approved. Remaining in plan mode.',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockConfig.setApprovalMode).toHaveBeenCalledWith(
|
expect(mockConfig.setApprovalMode).toHaveBeenCalledWith(
|
||||||
ApprovalMode.PLAN,
|
ApprovalMode.PLAN,
|
||||||
@@ -215,50 +210,6 @@ describe('ExitPlanModeTool', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle execution errors gracefully', async () => {
|
|
||||||
const params: ExitPlanModeParams = {
|
|
||||||
plan: 'Test plan',
|
|
||||||
};
|
|
||||||
|
|
||||||
const invocation = tool.build(params);
|
|
||||||
const confirmation = await invocation.shouldConfirmExecute(
|
|
||||||
new AbortController().signal,
|
|
||||||
);
|
|
||||||
if (confirmation) {
|
|
||||||
// Don't approve the plan so we go through the rejection path
|
|
||||||
await confirmation.onConfirm(ToolConfirmationOutcome.Cancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a spy to simulate an error during the execution
|
|
||||||
const consoleSpy = vi
|
|
||||||
.spyOn(console, 'error')
|
|
||||||
.mockImplementation(() => {});
|
|
||||||
|
|
||||||
// Mock JSON.stringify to throw an error in the rejection path
|
|
||||||
const originalStringify = JSON.stringify;
|
|
||||||
vi.spyOn(JSON, 'stringify').mockImplementationOnce(() => {
|
|
||||||
throw new Error('JSON stringify error');
|
|
||||||
});
|
|
||||||
|
|
||||||
const result = await invocation.execute(new AbortController().signal);
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
llmContent: JSON.stringify({
|
|
||||||
success: false,
|
|
||||||
error: 'Failed to present plan. Detail: JSON stringify error',
|
|
||||||
}),
|
|
||||||
returnDisplay: 'Error presenting plan: JSON stringify error',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(consoleSpy).toHaveBeenCalledWith(
|
|
||||||
'[ExitPlanModeTool] Error executing exit_plan_mode: JSON stringify error',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Restore original JSON.stringify
|
|
||||||
JSON.stringify = originalStringify;
|
|
||||||
consoleSpy.mockRestore();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return empty tool locations', () => {
|
it('should return empty tool locations', () => {
|
||||||
const params: ExitPlanModeParams = {
|
const params: ExitPlanModeParams = {
|
||||||
plan: 'Test plan',
|
plan: 'Test plan',
|
||||||
|
|||||||
@@ -115,17 +115,12 @@ class ExitPlanModeToolInvocation extends BaseToolInvocation<
|
|||||||
const rejectionMessage =
|
const rejectionMessage =
|
||||||
'Plan execution was not approved. Remaining in plan mode.';
|
'Plan execution was not approved. Remaining in plan mode.';
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: rejectionMessage,
|
||||||
success: false,
|
|
||||||
plan,
|
|
||||||
error: rejectionMessage,
|
|
||||||
}),
|
|
||||||
returnDisplay: rejectionMessage,
|
returnDisplay: rejectionMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const llmMessage =
|
const llmMessage = `User has approved your plan. You can now start coding. Start with updating your todo list if applicable.`;
|
||||||
'User has approved your plan. You can now start coding. Start with updating your todo list if applicable.';
|
|
||||||
const displayMessage = 'User approved the plan.';
|
const displayMessage = 'User approved the plan.';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -142,11 +137,11 @@ class ExitPlanModeToolInvocation extends BaseToolInvocation<
|
|||||||
console.error(
|
console.error(
|
||||||
`[ExitPlanModeTool] Error executing exit_plan_mode: ${errorMessage}`,
|
`[ExitPlanModeTool] Error executing exit_plan_mode: ${errorMessage}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const errorLlmContent = `Failed to present plan: ${errorMessage}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: errorLlmContent,
|
||||||
success: false,
|
|
||||||
error: `Failed to present plan. Detail: ${errorMessage}`,
|
|
||||||
}),
|
|
||||||
returnDisplay: `Error presenting plan: ${errorMessage}`,
|
returnDisplay: `Error presenting plan: ${errorMessage}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,9 +241,7 @@ describe('MemoryTool', () => {
|
|||||||
expectedFsArgument,
|
expectedFsArgument,
|
||||||
);
|
);
|
||||||
const successMessage = `Okay, I've remembered that in global memory: "${params.fact}"`;
|
const successMessage = `Okay, I've remembered that in global memory: "${params.fact}"`;
|
||||||
expect(result.llmContent).toBe(
|
expect(result.llmContent).toBe(successMessage);
|
||||||
JSON.stringify({ success: true, message: successMessage }),
|
|
||||||
);
|
|
||||||
expect(result.returnDisplay).toBe(successMessage);
|
expect(result.returnDisplay).toBe(successMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -271,9 +269,7 @@ describe('MemoryTool', () => {
|
|||||||
expectedFsArgument,
|
expectedFsArgument,
|
||||||
);
|
);
|
||||||
const successMessage = `Okay, I've remembered that in project memory: "${params.fact}"`;
|
const successMessage = `Okay, I've remembered that in project memory: "${params.fact}"`;
|
||||||
expect(result.llmContent).toBe(
|
expect(result.llmContent).toBe(successMessage);
|
||||||
JSON.stringify({ success: true, message: successMessage }),
|
|
||||||
);
|
|
||||||
expect(result.returnDisplay).toBe(successMessage);
|
expect(result.returnDisplay).toBe(successMessage);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -298,10 +294,7 @@ describe('MemoryTool', () => {
|
|||||||
const result = await invocation.execute(mockAbortSignal);
|
const result = await invocation.execute(mockAbortSignal);
|
||||||
|
|
||||||
expect(result.llmContent).toBe(
|
expect(result.llmContent).toBe(
|
||||||
JSON.stringify({
|
`Error saving memory: ${underlyingError.message}`,
|
||||||
success: false,
|
|
||||||
error: `Failed to save memory. Detail: ${underlyingError.message}`,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
expect(result.returnDisplay).toBe(
|
expect(result.returnDisplay).toBe(
|
||||||
`Error saving memory: ${underlyingError.message}`,
|
`Error saving memory: ${underlyingError.message}`,
|
||||||
@@ -319,6 +312,8 @@ describe('MemoryTool', () => {
|
|||||||
expect(result.llmContent).toContain(
|
expect(result.llmContent).toContain(
|
||||||
'Please specify where to save this memory',
|
'Please specify where to save this memory',
|
||||||
);
|
);
|
||||||
|
expect(result.llmContent).toContain('Global:');
|
||||||
|
expect(result.llmContent).toContain('Project:');
|
||||||
expect(result.returnDisplay).toContain('Global:');
|
expect(result.returnDisplay).toContain('Global:');
|
||||||
expect(result.returnDisplay).toContain('Project:');
|
expect(result.returnDisplay).toContain('Project:');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ Preview of changes to be made to GLOBAL memory:
|
|||||||
if (!fact || typeof fact !== 'string' || fact.trim() === '') {
|
if (!fact || typeof fact !== 'string' || fact.trim() === '') {
|
||||||
const errorMessage = 'Parameter "fact" must be a non-empty string.';
|
const errorMessage = 'Parameter "fact" must be a non-empty string.';
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({ success: false, error: errorMessage }),
|
llmContent: `Error: ${errorMessage}`,
|
||||||
returnDisplay: `Error: ${errorMessage}`,
|
returnDisplay: `Error: ${errorMessage}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -324,10 +324,7 @@ Global: ${globalPath} (shared across all projects)
|
|||||||
Project: ${projectPath} (current project only)`;
|
Project: ${projectPath} (current project only)`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: errorMessage,
|
||||||
success: false,
|
|
||||||
error: 'Please specify where to save this memory',
|
|
||||||
}),
|
|
||||||
returnDisplay: errorMessage,
|
returnDisplay: errorMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -344,10 +341,7 @@ Project: ${projectPath} (current project only)`;
|
|||||||
await fs.writeFile(memoryFilePath, modified_content, 'utf-8');
|
await fs.writeFile(memoryFilePath, modified_content, 'utf-8');
|
||||||
const successMessage = `Okay, I've updated the ${scope} memory file with your modifications.`;
|
const successMessage = `Okay, I've updated the ${scope} memory file with your modifications.`;
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: successMessage,
|
||||||
success: true,
|
|
||||||
message: successMessage,
|
|
||||||
}),
|
|
||||||
returnDisplay: successMessage,
|
returnDisplay: successMessage,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
@@ -359,10 +353,7 @@ Project: ${projectPath} (current project only)`;
|
|||||||
});
|
});
|
||||||
const successMessage = `Okay, I've remembered that in ${scope} memory: "${fact}"`;
|
const successMessage = `Okay, I've remembered that in ${scope} memory: "${fact}"`;
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: successMessage,
|
||||||
success: true,
|
|
||||||
message: successMessage,
|
|
||||||
}),
|
|
||||||
returnDisplay: successMessage,
|
returnDisplay: successMessage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -372,11 +363,9 @@ Project: ${projectPath} (current project only)`;
|
|||||||
console.error(
|
console.error(
|
||||||
`[MemoryTool] Error executing save_memory for fact "${fact}" in ${scope}: ${errorMessage}`,
|
`[MemoryTool] Error executing save_memory for fact "${fact}" in ${scope}: ${errorMessage}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: `Error saving memory: ${errorMessage}`,
|
||||||
success: false,
|
|
||||||
error: `Failed to save memory. Detail: ${errorMessage}`,
|
|
||||||
}),
|
|
||||||
returnDisplay: `Error saving memory: ${errorMessage}`,
|
returnDisplay: `Error saving memory: ${errorMessage}`,
|
||||||
error: {
|
error: {
|
||||||
message: errorMessage,
|
message: errorMessage,
|
||||||
|
|||||||
@@ -141,7 +141,12 @@ describe('TodoWriteTool', () => {
|
|||||||
const invocation = tool.build(params);
|
const invocation = tool.build(params);
|
||||||
const result = await invocation.execute(mockAbortSignal);
|
const result = await invocation.execute(mockAbortSignal);
|
||||||
|
|
||||||
expect(result.llmContent).toContain('success');
|
expect(result.llmContent).toContain(
|
||||||
|
'Todos have been modified successfully',
|
||||||
|
);
|
||||||
|
expect(result.llmContent).toContain('<system-reminder>');
|
||||||
|
expect(result.llmContent).toContain('Your todo list has changed');
|
||||||
|
expect(result.llmContent).toContain(JSON.stringify(params.todos));
|
||||||
expect(result.returnDisplay).toEqual({
|
expect(result.returnDisplay).toEqual({
|
||||||
type: 'todo_list',
|
type: 'todo_list',
|
||||||
todos: [
|
todos: [
|
||||||
@@ -178,7 +183,12 @@ describe('TodoWriteTool', () => {
|
|||||||
const invocation = tool.build(params);
|
const invocation = tool.build(params);
|
||||||
const result = await invocation.execute(mockAbortSignal);
|
const result = await invocation.execute(mockAbortSignal);
|
||||||
|
|
||||||
expect(result.llmContent).toContain('success');
|
expect(result.llmContent).toContain(
|
||||||
|
'Todos have been modified successfully',
|
||||||
|
);
|
||||||
|
expect(result.llmContent).toContain('<system-reminder>');
|
||||||
|
expect(result.llmContent).toContain('Your todo list has changed');
|
||||||
|
expect(result.llmContent).toContain(JSON.stringify(params.todos));
|
||||||
expect(result.returnDisplay).toEqual({
|
expect(result.returnDisplay).toEqual({
|
||||||
type: 'todo_list',
|
type: 'todo_list',
|
||||||
todos: [
|
todos: [
|
||||||
@@ -208,7 +218,10 @@ describe('TodoWriteTool', () => {
|
|||||||
const invocation = tool.build(params);
|
const invocation = tool.build(params);
|
||||||
const result = await invocation.execute(mockAbortSignal);
|
const result = await invocation.execute(mockAbortSignal);
|
||||||
|
|
||||||
expect(result.llmContent).toContain('"success":false');
|
expect(result.llmContent).toContain('Failed to modify todos');
|
||||||
|
expect(result.llmContent).toContain('<system-reminder>');
|
||||||
|
expect(result.llmContent).toContain('Todo list modification failed');
|
||||||
|
expect(result.llmContent).toContain('Write failed');
|
||||||
expect(result.returnDisplay).toContain('Error writing todos');
|
expect(result.returnDisplay).toContain('Error writing todos');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -223,7 +236,10 @@ describe('TodoWriteTool', () => {
|
|||||||
const invocation = tool.build(params);
|
const invocation = tool.build(params);
|
||||||
const result = await invocation.execute(mockAbortSignal);
|
const result = await invocation.execute(mockAbortSignal);
|
||||||
|
|
||||||
expect(result.llmContent).toContain('success');
|
expect(result.llmContent).toContain('Todo list has been cleared');
|
||||||
|
expect(result.llmContent).toContain('<system-reminder>');
|
||||||
|
expect(result.llmContent).toContain('Your todo list is now empty');
|
||||||
|
expect(result.llmContent).toContain('no pending tasks');
|
||||||
expect(result.returnDisplay).toEqual({
|
expect(result.returnDisplay).toEqual({
|
||||||
type: 'todo_list',
|
type: 'todo_list',
|
||||||
todos: [],
|
todos: [],
|
||||||
|
|||||||
@@ -340,11 +340,30 @@ class TodoWriteToolInvocation extends BaseToolInvocation<
|
|||||||
todos: finalTodos,
|
todos: finalTodos,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create plain string format with system reminder
|
||||||
|
const todosJson = JSON.stringify(finalTodos);
|
||||||
|
let llmContent: string;
|
||||||
|
|
||||||
|
if (finalTodos.length === 0) {
|
||||||
|
// Special message for empty todos
|
||||||
|
llmContent = `Todo list has been cleared.
|
||||||
|
|
||||||
|
<system-reminder>
|
||||||
|
Your todo list is now empty. DO NOT mention this explicitly to the user. You have no pending tasks in your todo list.
|
||||||
|
</system-reminder>`;
|
||||||
|
} else {
|
||||||
|
// Normal message for todos with items
|
||||||
|
llmContent = `Todos have been modified successfully. Ensure that you continue to use the todo list to track your progress. Please proceed with the current tasks if applicable
|
||||||
|
|
||||||
|
<system-reminder>
|
||||||
|
Your todo list has changed. DO NOT mention this explicitly to the user. Here are the latest contents of your todo list:
|
||||||
|
|
||||||
|
${todosJson}. Continue on with the tasks at hand if applicable.
|
||||||
|
</system-reminder>`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent,
|
||||||
success: true,
|
|
||||||
todos: finalTodos,
|
|
||||||
}),
|
|
||||||
returnDisplay: todoResultDisplay,
|
returnDisplay: todoResultDisplay,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -353,11 +372,16 @@ class TodoWriteToolInvocation extends BaseToolInvocation<
|
|||||||
console.error(
|
console.error(
|
||||||
`[TodoWriteTool] Error executing todo_write: ${errorMessage}`,
|
`[TodoWriteTool] Error executing todo_write: ${errorMessage}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Create plain string format for error with system reminder
|
||||||
|
const errorLlmContent = `Failed to modify todos. An error occurred during the operation.
|
||||||
|
|
||||||
|
<system-reminder>
|
||||||
|
Todo list modification failed with error: ${errorMessage}. You may need to retry or handle this error appropriately.
|
||||||
|
</system-reminder>`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
llmContent: JSON.stringify({
|
llmContent: errorLlmContent,
|
||||||
success: false,
|
|
||||||
error: `Failed to write todos. Detail: ${errorMessage}`,
|
|
||||||
}),
|
|
||||||
returnDisplay: `Error writing todos: ${errorMessage}`,
|
returnDisplay: `Error writing todos: ${errorMessage}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user