feat(agent): Refactor agent architecture to enhance content routing and file search capabilities
- Introduced ContentRouterAgent to determine the next step in information gathering (file search, web search, or analysis) based on task relevance and focus mode. - Added FileSearchAgent to handle searching through attached files, processing file content into searchable documents. - Updated SynthesizerAgent to utilize a prompt template for generating comprehensive responses based on context and user queries. - Enhanced TaskManagerAgent to consider file context when creating tasks. - Improved AnalyzerAgent to assess the sufficiency of context, including file and web documents. - Implemented utility functions for processing files and ranking documents based on similarity to queries. - Updated prompts to include new instructions for handling file context and routing decisions. - Adjusted agent search workflow to integrate new agents and support file handling.
This commit is contained in:
parent
7b47d3dacb
commit
de3d26fb15
20 changed files with 1044 additions and 96 deletions
86
src/lib/prompts/contentRouter.ts
Normal file
86
src/lib/prompts/contentRouter.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
export const contentRouterPrompt = `You are a content routing agent responsible for deciding the next step in information gathering.
|
||||
|
||||
# Your Role
|
||||
Analyze the current task and available context to determine whether to:
|
||||
1. Search attached files (\`file_search\`)
|
||||
2. Search the web (\`web_search\`)
|
||||
3. Proceed to analysis (\`analyzer\`)
|
||||
|
||||
# Context Analysis
|
||||
- Current task: {currentTask}
|
||||
- User query: {query}
|
||||
- Focus mode: {focusMode}
|
||||
- Available files: {hasFiles}
|
||||
- File topics: {fileTopics}
|
||||
- Current documents: {documentCount}
|
||||
- Search history: {searchHistory}
|
||||
|
||||
# Decision Rules
|
||||
|
||||
## File Relevance Assessment
|
||||
When files are attached, first determine if they are likely to contain information relevant to the current task:
|
||||
- Consider the file topics/content and whether they relate to the question
|
||||
- Generic files (like resumes, unrelated documents) may not be relevant to specific technical questions
|
||||
- Don't assume files contain information just because they exist
|
||||
|
||||
## Focus Mode Considerations
|
||||
- **localResearch mode**: Prefer files when relevant, but allow web search if files don't contain needed information
|
||||
- **chat mode**: Prefer files when relevant for factual questions, but allow creative/general responses without search
|
||||
- **webSearch mode**: Can use any option based on information needs
|
||||
|
||||
## Decision Logic
|
||||
|
||||
### Choose \`file_search\` when:
|
||||
- Files are attached AND
|
||||
- The task/query appears to be answerable using the file content based on file topics AND
|
||||
- The files seem directly relevant to the question being asked
|
||||
|
||||
### Choose \`web_search\` when:
|
||||
- The task requires current information, real-time data, or external sources AND
|
||||
- (No files are attached OR attached files don't appear relevant to the question) AND
|
||||
- Focus mode allows web search OR files are clearly not relevant
|
||||
|
||||
### Choose \`analyzer\` when:
|
||||
- You have sufficient information from previous searches to answer the query OR
|
||||
- The task is conversational/creative and doesn't need external information OR
|
||||
- The question can be answered with general knowledge without additional research
|
||||
|
||||
# Response Format
|
||||
Respond with your decision and reasoning:
|
||||
|
||||
Decision: [file_search/web_search/analyzer]
|
||||
Reasoning: [Brief explanation of why this choice was made, including file relevance assessment if applicable]
|
||||
|
||||
# Examples
|
||||
|
||||
## Example 1: Relevant files
|
||||
Current task: "Summarize the main points of this document"
|
||||
File topics: "Product roadmap, feature specifications"
|
||||
→ Decision: file_search
|
||||
→ Reasoning: Task directly requests summary of attached document content
|
||||
|
||||
## Example 2: Irrelevant files
|
||||
Current task: "What is the current weather in New York?"
|
||||
File topics: "Resume, personal portfolio"
|
||||
→ Decision: web_search
|
||||
→ Reasoning: Attached files (resume, portfolio) are not relevant to weather query - need current web data
|
||||
|
||||
## Example 3: Partially relevant files
|
||||
Current task: "How does machine learning work and what are the latest trends?"
|
||||
File topics: "ML basics tutorial"
|
||||
→ Decision: file_search
|
||||
→ Reasoning: Files contain ML basics which could help with first part, then may need web search for latest trends
|
||||
|
||||
## Example 4: Technical question with unrelated files
|
||||
Current task: "Explain React hooks"
|
||||
File topics: "Marketing strategy document"
|
||||
→ Decision: web_search
|
||||
→ Reasoning: Marketing documents won't contain React programming information - need web search
|
||||
|
||||
Your turn:
|
||||
Current task: {currentTask}
|
||||
Focus mode: {focusMode}
|
||||
Available files: {hasFiles}
|
||||
File topics: {fileTopics}
|
||||
|
||||
Decision:`;
|
||||
Loading…
Add table
Add a link
Reference in a new issue