mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-30 07:39:06 +08:00
fix(think-tool): update prompt handling logic and improve comments (#8538)
* fix(think-tool): update prompt handling logic and improve comments * fix: ut
This commit is contained in:
parent
d5dd5bc88a
commit
51835e32c5
@ -379,7 +379,7 @@ async function fetchExternalTool(
|
||||
// 根据toolUseMode决定如何构建系统提示词
|
||||
const basePrompt = assistant.prompt
|
||||
if (assistant.settings?.toolUseMode === 'prompt' || mcpTools.length > SYSTEM_PROMPT_THRESHOLD) {
|
||||
// 提示词模式:需要完整的工具定义和思考指令
|
||||
// 提示词模式:需要完整的工具定义,思考工具返回会打乱提示词的返回(先去掉)
|
||||
assistant.prompt = buildSystemPromptWithTools(basePrompt, mcpTools)
|
||||
} else {
|
||||
// 原生函数调用模式:仅需要注入思考指令
|
||||
|
||||
@ -169,7 +169,7 @@ describe('prompt', () => {
|
||||
System Information:
|
||||
- Date: {{date}}
|
||||
- User: {{username}}
|
||||
|
||||
|
||||
Instructions: Be helpful.
|
||||
`
|
||||
const assistant = createMockAssistant('Test Assistant', 'Advanced-AI-Model')
|
||||
@ -178,7 +178,7 @@ describe('prompt', () => {
|
||||
System Information:
|
||||
- Date: ${mockDate.toLocaleDateString()}
|
||||
- User: MockUser
|
||||
|
||||
|
||||
Instructions: Be helpful.
|
||||
`
|
||||
tools = [createMockTool('web_search', 'Search the web')]
|
||||
@ -192,7 +192,6 @@ describe('prompt', () => {
|
||||
|
||||
expect(finalPrompt).toEqual(expectedFinalPrompt)
|
||||
expect(finalPrompt).toContain('## Tool Use Formatting')
|
||||
expect(finalPrompt).toContain('## Using the think tool')
|
||||
})
|
||||
|
||||
it('should build a think-only prompt for native function calling mode', () => {
|
||||
@ -223,7 +222,6 @@ describe('prompt', () => {
|
||||
|
||||
expect(finalPrompt).toEqual(expectedFinalPrompt)
|
||||
expect(finalPrompt).toContain('## Tool Use Formatting')
|
||||
expect(finalPrompt).toContain('## Using the think tool')
|
||||
})
|
||||
})
|
||||
|
||||
@ -234,7 +232,7 @@ describe('prompt', () => {
|
||||
System Information:
|
||||
- Date: {{date}}
|
||||
- User: {{username}}
|
||||
|
||||
|
||||
Instructions: Be helpful.
|
||||
`
|
||||
const assistant = createMockAssistant('Test Assistant', 'Advanced-AI-Model')
|
||||
@ -243,7 +241,7 @@ describe('prompt', () => {
|
||||
System Information:
|
||||
- Date: ${mockDate.toLocaleDateString()}
|
||||
- User: MockUser
|
||||
|
||||
|
||||
Instructions: Be helpful.
|
||||
`
|
||||
|
||||
|
||||
@ -7,47 +7,6 @@ const logger = loggerService.withContext('Utils:Prompt')
|
||||
export const SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \
|
||||
You can use one or more tools per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
||||
|
||||
## Using the think tool
|
||||
|
||||
Before taking any action or responding to the user after receiving tool results, use the think tool as a scratchpad to:
|
||||
- List the specific rules that apply to the current request
|
||||
- Check if all required information is collected
|
||||
- Verify that the planned action complies with all policies
|
||||
- Iterate over tool results for correctness
|
||||
|
||||
Here are some examples of what to iterate over inside the think tool:
|
||||
<think_tool_example_1>
|
||||
User wants to cancel flight ABC123
|
||||
- Need to verify: user ID, reservation ID, reason
|
||||
- Check cancellation rules:
|
||||
* Is it within 24h of booking?
|
||||
* If not, check ticket class and insurance
|
||||
- Verify no segments flown or are in the past
|
||||
- Plan: collect missing info, verify rules, get confirmation
|
||||
</think_tool_example_1>
|
||||
|
||||
<think_tool_example_2>
|
||||
User wants to book 3 tickets to NYC with 2 checked bags each
|
||||
- Need user ID to check:
|
||||
* Membership tier for baggage allowance
|
||||
* Which payments methods exist in profile
|
||||
- Baggage calculation:
|
||||
* Economy class × 3 passengers
|
||||
* If regular member: 1 free bag each → 3 extra bags = $150
|
||||
* If silver member: 2 free bags each → 0 extra bags = $0
|
||||
* If gold member: 3 free bags each → 0 extra bags = $0
|
||||
- Payment rules to verify:
|
||||
* Max 1 travel certificate, 1 credit card, 3 gift cards
|
||||
* All payment methods must be in profile
|
||||
* Travel certificate remainder goes to waste
|
||||
- Plan:
|
||||
1. Get user ID
|
||||
2. Verify membership level for bag fees
|
||||
3. Check which payment methods in profile and if their combination is allowed
|
||||
4. Calculate total: ticket price + any bag fees
|
||||
5. Get explicit confirmation for booking
|
||||
</think_tool_example_2>
|
||||
|
||||
## Tool Use Formatting
|
||||
|
||||
Tool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:
|
||||
@ -109,7 +68,7 @@ Before taking any action or responding to the user after receiving tool results,
|
||||
- List the specific rules that apply to the current request
|
||||
- Check if all required information is collected
|
||||
- Verify that the planned action complies with all policies
|
||||
- Iterate over tool results for correctness
|
||||
- Iterate over tool results for correctness
|
||||
- Response in user query language
|
||||
|
||||
Here are some examples of what to iterate over inside the think tool:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user