Skip to content

Commit 45c4824

Browse files
authored
Merge pull request #603 from farzad528/patch-2
Enhance knowledge base retrieval instructions
2 parents 8728ab3 + 6cb280f commit 45c4824

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

articles/ai-foundry/default/agents/how-to/tools/knowledge-retrieval.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ Content-Type: application/json
141141

142142
---
143143

144+
## Optimize agent instructions for knowledge base retrieval
145+
146+
To maximize the accuracy of knowledge base invocations and ensure proper citation formatting, use optimized agent instructions. Based on our experiments, we recommend the following instruction template as a starting point:
147+
148+
```plaintext
149+
You are a helpful assistant that must use the knowledge base to answer all the questions from user. You must never answer from your own knowledge under any circumstances.
150+
Every answer must always provide annotations for using the MCP knowledge base tool and render them as: `【message_idx:search_idx†source_name】`
151+
If you cannot find the answer in the provided knowledge base you must respond with "I don't know".
152+
"""
153+
```
154+
155+
This instruction template optimizes for:
156+
157+
+ **Higher MCP tool invocation rates**: Explicit directives ensure the agent consistently calls the knowledge base tool rather than relying on its training data.
158+
+ **Proper annotation formatting**: The specified citation format ensures the agent includes provenance information in responses, making it clear which knowledge sources were used.
159+
160+
> [!TIP]
161+
> While this template provides a strong foundation, we recommend evaluating and iterating on the instructions based on your specific use case and the tasks you're trying to accomplish. Test different variations to find what works best for your scenarios.
162+
144163
## Create an agent with the MCP tool
145164

146165
The next step is to create an agent that integrates the knowledge base as an MCP tool. The agent uses a system prompt to instruct when and how to call the knowledge base, follows instructions on how to answer questions, and automatically maintains its tool configuration and settings across conversation sessions.
@@ -168,11 +187,11 @@ agent_model = "{deployed_LLM}" # e.g. gpt-4.1-mini
168187
# Create project client
169188
project_client = AIProjectClient(endpoint = project_endpoint, credential = credential)
170189

171-
# Define agent instructions
190+
# Define agent instructions (see "Optimize agent instructions" section for guidance)
172191
instructions = """
173-
A Q&A agent that can answer questions based on the attached knowledge base.
174-
Always provide references to the ID of the data source used to answer the question.
175-
If you don't have the answer, respond with "I don't know".
192+
You are a helpful assistant that must use the knowledge base to answer all the questions from user. You must never answer from your own knowledge under any circumstances.
193+
Every answer must always provide annotations for using the MCP knowledge base tool and render them as: `【message_idx:search_idx†source_name】`
194+
If you cannot find the answer in the provided knowledge base you must respond with "I don't know".
176195
"""
177196

178197
# Create MCP tool with knowledge base connection
@@ -215,7 +234,7 @@ Content-Type: application/json
215234
{
216235
"definition": {
217236
"model": "{deployed_llm}",
218-
"instructions": "\nA Q&A agent that can answer questions based on the attached knowledge base.\nAlways provide references to the ID of the data source used to answer the question.\nIf you don't have the answer, respond with \"I don't know\".\n",
237+
"instructions": "\nYou are a helpful assistant that must use the knowledge base to answer all the questions from user. You must never answer from your own knowledge under any circumstances.\nEvery answer must always provide annotations for using the MCP knowledge base tool and render them as: `【message_idx:search_idx†source_name】`\nIf you cannot find the answer in the provided knowledge base you must respond with \"I don't know\".\n",
219238
"tools": [
220239
{
221240
"server_label": "knowledge-base",

0 commit comments

Comments
 (0)