Skip to content

Commit

Permalink
feat: improve prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Feb 11, 2025
1 parent b819af4 commit b773a27
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 17 additions & 11 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,24 @@ ${learnedStrategy}

// Build actions section

if (allURLs && Object.keys(allURLs).length > 0 && allowRead) {
const urlList = Object.entries(allURLs)
.map(([url, desc]) => ` + "${url}": "${desc}"`)
.join('\n');
if (allowRead) {
let urlList = '';
if (allURLs && Object.keys(allURLs).length > 0) {
urlList = Object.entries(allURLs)
.map(([url, desc]) => ` + "${url}": "${desc}"`)
.join('\n');
}

actionSections.push(`
<action-visit>
<action-visit>
- This allows you to access the full content behind any URLs.
- If the <question> contains a URL, you must visit the URL to gather more information.
${urlList ? `
- Visit any URLs from below to gather external knowledge, choose the most relevant URLs that might contain the answer
<url-list>
${urlList}
</url-list>
- When you have enough search result in the context and want to deep dive into specific URLs
- It allows you to access the full content behind any URLs
`.trim() : ''}
</action-visit>
`);
}
Expand All @@ -213,8 +217,10 @@ ${allKeywords.join('\n')}
actionSections.push(`
<action-answer>
- If <question> is a simple greeting, chit-chat, or general knowledge, provide the answer directly.
- Provide final response only when 100% certain
- Responses must be definitive (no ambiguity, uncertainty, or disclaimers)${allowReflect ? '\n- If doubts remain, use <action-reflect> instead' : ''}
- Must provide "references" and each must specify "exactQuote" and "url"
- In the answer, use markdown footnote syntax like [^1], [^2] to refer to the references
- Responses must be definitive (no ambiguity, uncertainty, or disclaimers)
- Provide final response only when 100% certain${allowReflect ? '\n- If doubts remain, use <action-reflect> instead' : ''}
</action-answer>
`);
}
Expand Down Expand Up @@ -323,7 +329,7 @@ export async function getResponse(question: string, tokenBudget: number = 1_000_
}

// update all urls with buildURLMap
allowRead = allowRead && (Object.keys(allURLs).length > 0);
// allowRead = allowRead && (Object.keys(allURLs).length > 0);
allowSearch = allowSearch && (Object.keys(allURLs).length < 50); // disable search when too many urls already

// generate prompt for this step
Expand Down
9 changes: 5 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ function buildMdFromAnswer(answer: AnswerAction) {
let refStr = '';
if (answer.references?.length > 0) {
refStr = `
## References
<references>
${answer.references.map((ref, i) => `
${i + 1}. [${ref.exactQuote}](${ref.url})`).join('')}`;
${i + 1}. [${ref.exactQuote}](${ref.url})`).join('')}
</references>
`.trim();
}
return `${answer.answer.replace(/\(REF_(\d+)\)/g, (_, num) => `[^${num}]`)}${refStr}`;
return `${answer.answer.replace(/\(REF_(\d+)\)/g, (_, num) => `[^${num}]`)}\n${refStr}`;
}


Expand Down

0 comments on commit b773a27

Please sign in to comment.