Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
a2e2d22
1
Parent(s): 9934918
improved search agent prompt and descriptions
Browse files
agent/prompts/search_docs_system_prompt.yaml
CHANGED
|
@@ -1,22 +1,21 @@
|
|
| 1 |
search_docs_system_prompt: |
|
| 2 |
-
You are a specialized documentation search agent. Your task is to comprehensively search and synthesize information from Hugging Face documentation.
|
| 3 |
|
| 4 |
# Search Strategy
|
| 5 |
|
| 6 |
You must search thoroughly before synthesizing results. Follow this approach:
|
| 7 |
|
| 8 |
-
1. **Query Analysis**: Identify the core concepts and intent of the query
|
| 9 |
2. **Initial Search**: Start with a broad search capturing the main topic
|
| 10 |
-
3. **Iterative Refinement**: Run multiple searches to go deeper into topics.
|
| 11 |
-
4. **You must get to the end truth**: You must get to the bottom of the truth for this search query. You CAN NOT say that somebody should look up documentation. You must look it up yourself and give the best answer you can.
|
| 12 |
|
| 13 |
-
#
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
-
|
| 18 |
-
- Include domain-specific terminology when applicable
|
| 19 |
-
- Try both specific terms and general related terms
|
| 20 |
|
| 21 |
# Response Guidelines
|
| 22 |
|
|
@@ -25,14 +24,13 @@ search_docs_system_prompt: |
|
|
| 25 |
1. **Analyze Relevance**: Evaluate which results directly answer the query
|
| 26 |
2. **Synthesize**: Combine information from multiple sources when applicable
|
| 27 |
3. **Prioritize**: Present information in order of relevance
|
| 28 |
-
4. **Cite Sources**:
|
| 29 |
5. **Acknowledge Gaps**: If documents don't fully answer the query, explicitly state this
|
| 30 |
6. **Handle Conflicts**: If sources contradict, note this and explain your reasoning
|
| 31 |
-
7. **Be Concise**: Provide a clear, direct answer without unnecessary elaboration
|
| 32 |
|
| 33 |
# Constraints
|
| 34 |
|
| 35 |
- Only provide information found in the documentation
|
| 36 |
- Do not make assumptions beyond what the sources state
|
| 37 |
- If information is not found, say so clearly rather than guessing
|
| 38 |
-
- Focus on
|
|
|
|
| 1 |
search_docs_system_prompt: |
|
| 2 |
+
You are a specialized documentation search agent. Your task is to comprehensively search and synthesize information from Hugging Face documentation. You are queried by a main agent who has to build a solution to a user. You have to give the best and the most comprehensive guidance on how to solve the user's task.
|
| 3 |
|
| 4 |
# Search Strategy
|
| 5 |
|
| 6 |
You must search thoroughly before synthesizing results. Follow this approach:
|
| 7 |
|
| 8 |
+
1. **Query Analysis**: Identify the core concepts and intent of the original user query and the search query passed by the LLM.
|
| 9 |
2. **Initial Search**: Start with a broad search capturing the main topic
|
| 10 |
+
3. **Iterative Refinement**: Run multiple searches to go deeper into topics. If you see links to other pages, also look into those pages for best information - first-pass results often miss key details
|
| 11 |
+
4. **You must get to the end truth**: You must get to the bottom of the truth for this search query. You CAN NOT say that somebody should look up documentation. You must look it up yourself and give the best answer you can including code snippets and relevant information. You are teaching the main agent how to solve the user's task and have to give ALL relevant information on how to do it.
|
| 12 |
|
| 13 |
+
# Quality metrics:
|
| 14 |
+
- You are optimizing for the minimum viable way to solve the user request reusing as much as possible from already available code from your research. Opt for reliability and reusability. Hugging Face has a lot of best practices laid out in the documentation and you must pass these to the main agent.
|
| 15 |
|
| 16 |
+
|
| 17 |
+
# Useful links:
|
| 18 |
+
- code examples for trl (covers most LLM training tasks): https://github.com/huggingface/trl/tree/main/examples/scripts and https://github.com/huggingface/trl/tree/main/trl/scripts
|
|
|
|
|
|
|
| 19 |
|
| 20 |
# Response Guidelines
|
| 21 |
|
|
|
|
| 24 |
1. **Analyze Relevance**: Evaluate which results directly answer the query
|
| 25 |
2. **Synthesize**: Combine information from multiple sources when applicable
|
| 26 |
3. **Prioritize**: Present information in order of relevance
|
| 27 |
+
4. **Cite Sources**: Find and pass the relevant code and other snippets from the analyzed articles for the main agent to read.
|
| 28 |
5. **Acknowledge Gaps**: If documents don't fully answer the query, explicitly state this
|
| 29 |
6. **Handle Conflicts**: If sources contradict, note this and explain your reasoning
|
|
|
|
| 30 |
|
| 31 |
# Constraints
|
| 32 |
|
| 33 |
- Only provide information found in the documentation
|
| 34 |
- Do not make assumptions beyond what the sources state
|
| 35 |
- If information is not found, say so clearly rather than guessing
|
| 36 |
+
- Focus on giving the best practices and comprehensive guidance on how to solve the user's task. Include all relevant code snippets without edits from the docs and simplest ways on how to solve the user's task.
|
agent/tools/search_docs_tool.py
CHANGED
|
@@ -96,10 +96,14 @@ async def search_docs_handler(arguments: dict[str, Any]) -> tuple[str, bool]:
|
|
| 96 |
Tuple of (search_results, success)
|
| 97 |
"""
|
| 98 |
query = arguments.get("query", "")
|
|
|
|
| 99 |
|
| 100 |
if not query:
|
| 101 |
return "Error: No search query provided", False
|
| 102 |
|
|
|
|
|
|
|
|
|
|
| 103 |
try:
|
| 104 |
# Import at runtime to avoid circular dependency
|
| 105 |
from pathlib import Path
|
|
@@ -149,9 +153,12 @@ async def search_docs_handler(arguments: dict[str, Any]) -> tuple[str, bool]:
|
|
| 149 |
),
|
| 150 |
)
|
| 151 |
|
|
|
|
|
|
|
|
|
|
| 152 |
# Run the sub-agent
|
| 153 |
result = await Handlers.run_agent(
|
| 154 |
-
session=sub_session, text=
|
| 155 |
)
|
| 156 |
|
| 157 |
# Return the final result or compiled events
|
|
@@ -163,41 +170,6 @@ async def search_docs_handler(arguments: dict[str, Any]) -> tuple[str, bool]:
|
|
| 163 |
return f"Error in search_docs tool: {str(e)}", False
|
| 164 |
|
| 165 |
|
| 166 |
-
# Tool specification to be used by the main agent
|
| 167 |
-
SEARCH_DOCS_TOOL_SPEC = {
|
| 168 |
-
"name": "search_docs",
|
| 169 |
-
"description": (
|
| 170 |
-
"Intelligently search HF documentation for libraries, repositories, and best practices with an agent that has access to: explore_hf_docs, fetch_hf_docs, search_hf_api_endpoints. "
|
| 171 |
-
"The agent acts like your personal search assistant. "
|
| 172 |
-
"Using the search agent is necessary to give the best quality answer to the user's question. Most questions require a search to get the best information on code examples.\n\n"
|
| 173 |
-
"WHEN TO USE THIS TOOL:\n"
|
| 174 |
-
" - When searching for high-level concepts like 'how to do GRPO training on a model?' or 'best way to do inference on a trained model?'\n"
|
| 175 |
-
" - When you need to get code examples for intricate ML code patterns like training loops, inference pipelines, data processing, etc.\n\n"
|
| 176 |
-
"USAGE GUIDELINES:\n"
|
| 177 |
-
" 1. Launch multiple agents concurrently for better performance.\n"
|
| 178 |
-
" 2. Be specific in your query - include exact terminology, expected file locations, or code patterns.\n"
|
| 179 |
-
" 3. Use the query as if you were talking to another engineer. Bad: logger impl Good: where is the logger implemented, we're trying to find out how to log to files.\n"
|
| 180 |
-
" 4. Make sure to formulate the query in such a way that the agent knows when it's done or has found the result."
|
| 181 |
-
),
|
| 182 |
-
"parameters": {
|
| 183 |
-
"type": "object",
|
| 184 |
-
"properties": {
|
| 185 |
-
"query": {
|
| 186 |
-
"type": "string",
|
| 187 |
-
"description": (
|
| 188 |
-
"The search query describing to the agent what it should do. Be "
|
| 189 |
-
"specific and include technical terms, file types, or expected "
|
| 190 |
-
"code patterns to help the agent find relevant code. Formulate "
|
| 191 |
-
"the query in a way that makes it clear to the agent when it "
|
| 192 |
-
"has found the right thing."
|
| 193 |
-
),
|
| 194 |
-
},
|
| 195 |
-
},
|
| 196 |
-
"required": ["query"],
|
| 197 |
-
},
|
| 198 |
-
}
|
| 199 |
-
|
| 200 |
-
|
| 201 |
async def make_search_agent_tools():
|
| 202 |
"""
|
| 203 |
Create a list of tools for the search agent
|
|
@@ -237,3 +209,64 @@ async def make_search_agent_tools():
|
|
| 237 |
handler=search_openapi_handler,
|
| 238 |
),
|
| 239 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
Tuple of (search_results, success)
|
| 97 |
"""
|
| 98 |
query = arguments.get("query", "")
|
| 99 |
+
user_query = arguments.get("user_query", "")
|
| 100 |
|
| 101 |
if not query:
|
| 102 |
return "Error: No search query provided", False
|
| 103 |
|
| 104 |
+
if not user_query:
|
| 105 |
+
return "Error: No user query provided", False
|
| 106 |
+
|
| 107 |
try:
|
| 108 |
# Import at runtime to avoid circular dependency
|
| 109 |
from pathlib import Path
|
|
|
|
| 153 |
),
|
| 154 |
)
|
| 155 |
|
| 156 |
+
# make search prompt
|
| 157 |
+
search_prompt = f"What the user tasked the main agent with: {user_query}\nWhat you have asked to research by the main agent: {query}. Use both to find the best practices, code examples, and determine the recommended approach for solving the user's task."
|
| 158 |
+
|
| 159 |
# Run the sub-agent
|
| 160 |
result = await Handlers.run_agent(
|
| 161 |
+
session=sub_session, text=search_prompt, max_iterations=30
|
| 162 |
)
|
| 163 |
|
| 164 |
# Return the final result or compiled events
|
|
|
|
| 170 |
return f"Error in search_docs tool: {str(e)}", False
|
| 171 |
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
async def make_search_agent_tools():
|
| 174 |
"""
|
| 175 |
Create a list of tools for the search agent
|
|
|
|
| 209 |
handler=search_openapi_handler,
|
| 210 |
),
|
| 211 |
]
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
# Tool specification to be used by the main agent
|
| 215 |
+
SEARCH_DOCS_TOOL_SPEC = {
|
| 216 |
+
"name": "research_solution",
|
| 217 |
+
"description": (
|
| 218 |
+
"Spawns a specialized research sub-agent to search to find best practices, locate code examples, and determine the recommended approach for solving the user's task.\n\n"
|
| 219 |
+
"SEARCH AGENT CAPABILITIES:\n"
|
| 220 |
+
"The search subagent has access to these specialized tools:\n"
|
| 221 |
+
" - explore_hf_docs: Discovers documentation structure by parsing sidebar navigation, returns page titles, URLs, and content glimpses\n"
|
| 222 |
+
" - fetch_hf_docs: Retrieves full markdown content from specific HF documentation pages\n"
|
| 223 |
+
" - search_hf_api_endpoints: Searches HF OpenAPI specification by tag to find API endpoints with usage examples\n"
|
| 224 |
+
" - GitHub tools: search_code, search_repositories, get_file_contents, list_issues, list_pull_requests (for searching HF repositories)\n"
|
| 225 |
+
"MANDATORY FIRST STEP for:\n"
|
| 226 |
+
" - ANY task involving training, fine-tuning, or model deployment with HF libraries\n"
|
| 227 |
+
" - Implementing ML workflows (data loading, preprocessing, training loops, inference pipelines)\n"
|
| 228 |
+
" - Working with specific HF libraries (transformers, diffusers, trl, datasets, accelerate, etc.)\n"
|
| 229 |
+
" - Finding the recommended/official way to accomplish ML tasks\n"
|
| 230 |
+
" - Understanding which libraries and methods to use for a user's goal\n\n"
|
| 231 |
+
"ALSO USE for:\n"
|
| 232 |
+
" - Verifying current API signatures, parameters, or available methods\n"
|
| 233 |
+
" - Finding code examples and best practices from official documentation\n"
|
| 234 |
+
" - Understanding relationships between HF libraries and components\n\n"
|
| 235 |
+
"SKIP ONLY when:\n"
|
| 236 |
+
" - User asks simple factual questions answerable from general ML knowledge (e.g., 'What is fine-tuning?')\n"
|
| 237 |
+
" - Task is about general Python/programming unrelated to ML or HF libraries\n"
|
| 238 |
+
"QUERY FORMAT:\n"
|
| 239 |
+
"Write queries as if delegating to an engineer. Include:\n"
|
| 240 |
+
" - Specific library names (e.g., 'trl', 'transformers', 'diffusers')\n"
|
| 241 |
+
" - Technical terminology from the domain (e.g., 'DPO trainer', 'GRPO', 'LoRA adapter')\n"
|
| 242 |
+
" - Clear success criteria (e.g., 'find code example', 'verify parameter exists', 'get recommended approach')\n\n"
|
| 243 |
+
"QUERY EXAMPLES:\n"
|
| 244 |
+
" Good: 'Find the best way to implement DPO training in trl. Get code example showing dataset format, trainer configuration, and reward model setup'\n"
|
| 245 |
+
" Bad: 'dpo trainer'\n"
|
| 246 |
+
" Good: 'Search transformers docs for the recommended approach to load and run quantized models with 4-bit precision. Find the specific classes and methods to use'\n"
|
| 247 |
+
" Bad: 'quantization'\n"
|
| 248 |
+
" Good: 'Research the best way to fine-tune a diffusion model for custom image generation. Find which library to use (diffusers/PEFT), required components, and complete training example'\n"
|
| 249 |
+
" Bad: 'fine-tune diffusion'\n\n"
|
| 250 |
+
),
|
| 251 |
+
"parameters": {
|
| 252 |
+
"type": "object",
|
| 253 |
+
"properties": {
|
| 254 |
+
"user_query": {
|
| 255 |
+
"type": "string",
|
| 256 |
+
"description": (
|
| 257 |
+
"The original user query that you received. This will be used to search the documentation."
|
| 258 |
+
),
|
| 259 |
+
},
|
| 260 |
+
"query": {
|
| 261 |
+
"type": "string",
|
| 262 |
+
"description": (
|
| 263 |
+
"Detailed search query for the specialized agent. Must include: (1) specific library/component names, "
|
| 264 |
+
"(2) technical terms or concepts to search for, (3) clear objective (e.g., 'find code example', "
|
| 265 |
+
"'verify API exists', 'get implementation details'). The search agent will autonomously explore "
|
| 266 |
+
"documentation structure, retrieve relevant pages, and compile results until the objective is met."
|
| 267 |
+
),
|
| 268 |
+
},
|
| 269 |
+
},
|
| 270 |
+
"required": ["user_query", "query"],
|
| 271 |
+
},
|
| 272 |
+
}
|