Query Tool Transparency & error
# support
j
Hi team, Thanks in advance, this one's a bit long --- Running into a critical issue where the agent is prompted to use the query tool to look up details for a procedure. When using the query tool I can see it's querying the right knowledge base However, there are either no results returned or the wrong knowledge base is used. I have another agent with the exact same setup and it consistently gets it right, while the one in production consistently fails. We don't have transparency into HOW the agent is querying, only that it queries a specific KB: Query:
{"knowledgeBaseNames":["clinic_appointment_type"]}
Incorrect result: `[ { "name": "qr_j573wcg4bba9gb6gfeef2dt8s97tcprf", "toolCallId": "call_yXsBEQ0qYn9QBbP8MJoFiybA", "type": "query", "result": "```text\nMonday: 08:00 - 18:00\n```" } ]` Correct Query: Query :
{"knowledgeBaseNames": ["clinic_appointment_type"]}
Correct result: `[ { "name": "qr_j976q1pdjjwgwgznnf96wmdrsn7tntr5", "toolCallId": "call_N9auENLGPuszgbNFjV0EmM8F", "type": "query", "result": "```json\n[\n {\n \"_creationTime\": 1762168946683.3276,\n \"_id\": \"jh79dwk5k1be9sh0mttbr27ty57tqag2\",\n \"agentId\": \"j976q1pdjjwgwgznnf96wmdrsn7tntr5\",\n \"estimatedDuration\": 30,\n \"name\": \"Check Up/Scale Clean\",\n \"pmsId\": \"Sp4DmVITUEyTAPKMPnqupw\",\n \"eventClassId\": \"Sp4DmVITUEyTAPKMPnqupw\",\n \"practitioners\": [\n \"Stephen Vincent Strange\",\n \"Bruce Banner\",\n \"Tony Stark\",\n \"Natalia Romanov\"\n ]\n }\n]\n```" }, { "name": "qr_j976q1pdjjwgwgznnf96wmdrsn7tntr5", "toolCallId": "call_lqUo0ydWYu5nY4z2uRymRqn4", "type": "query", "result": "```text\nClinic Opening Hours:\nMonday: 09:00 - 17:00\nTuesday: 09:00 - 17:00\nWednesday: 09:00 - 17:00\nThursday: 09:00 - 17:00\nFriday: 09:00 - 17:00\nSaturday: 09:00 - 17:00\nSunday: 09:00 - 17:00\n```" } ]` Broken Call ID: 019b02db-f100-7bb8-987f-57eea4fe632c Working Call ID: 019b02e2-a3d1-7006-8667-088991a183be
v
To resolve inconsistent query tool results, ensure your assistant's system prompt explicitly instructs when to use the query tool and references the correct tool name. For example:
Copy code
json
{
  "role": "system",
  "content": "When users ask about appointment types, use the 'clinic-appointment-type-query' tool to search the knowledge base. Always call this tool before answering."
}
Review and align the system prompt and knowledge base description across both agents for consistent behavior ([documentation](https://docs.vapi.ai/knowledge-base/using-query-tool)). Source: - [Using the Query Tool for Knowledge Bases](https://docs.vapi.ai/knowledge-base/using-query-tool)
j
I have done this ^ The only difference I can think of currently is that the broken agent was created in October while the working agent was more recent. Is there some sort of caching that could be resolved by recreating the broken agent?
It looks like what the broken tool call is doing is returning parts of the system prompt as the response. eg `[ { "name": "qr_j573wcg4bba9gb6gfeef2dt8s97tcprf", "toolCallId": "call_c4ORQGfemxDm9yVSLyDOY4Bo", "type": "query", "result": "```text\n2. Ask: \"What days and times work best for you?\"\n```" } ] ` Call ID: 019b0311-bcbc-7cc2-8acf-38e64476d01d
Another example: 019b031b-9f8b-799d-8c2f-9b28fda721b6 `[ { "name": "qr_j573wcg4bba9gb6gfeef2dt8s97tcprf", "toolCallId": "call_FGjEHGNLrtTtJBGj8dNwcFqb", "type": "query", "result": "```text\nMonday: 08:00 - 18:00\n```" } ]`
Another example: 019b0358-d3dd-7114-be07-13e17073fe5e It's worth noting that the two broken queries are both in the same org, while the working query is in a separate org `[ { "name": "qr_j578hcrrz0c94ycfpnpg5pa0gs7wxf2p", "toolCallId": "call_3LgESgCRo01ibsGnK4IkOPVg", "type": "query", "result": "```text\nFriday: 09:00 - 17:00\n```" } ]`
Example here where the query returns part of the recent context call id: 019b07f5-2005-7441-b28e-57dfc5fdff44 [ { "name": "qr_j573wcg4bba9gb6gfeef2dt8s97tcprf", "toolCallId": "call_1VNMdm5QvM0ec8CNFx4mlQRJ", "type": "query", "result": "```text\nOur clinic is open Monday to Friday. We slightly shorter hours on Wednesdays.\n```" } ]
@Vapi sorry to tag
@User
c
Hi bobbychick, It seems you're experiencing inconsistent query tool results across different agents, despite having similar configurations. Here are a few steps to help resolve this: 1. **Confirm System Prompts**: Ensure the system prompts for both agents clearly specify when to use the query tool and reference the correct tool name. Consistency here can significantly impact tool invocation. 2. **Check Knowledge Base Descriptions**: Verify that the descriptions accurately reflect the intended use, as they help the assistant understand when to query. 3. **Logs Analysis**: Review the logs to ensure the queries reference the correct knowledge base. For example, make sure that
{"knowledgeBaseNames":["clinic_appointment_type"]}
is consistent across both agents. 4. **Tool and Agent Creation Date**: It's possible that the discrepancies might stem from updates or changes post-Agent creation. Consider recreating the agent to align configurations. 5. **Procedure in Separate Orgs**: If both agents are in separate organizations, there might be organization-specific configurations affecting query results. Review these steps and align configurations across both agents as per the [Query Tool documentation](https://docs.vapi.ai/knowledge-base/using-query-tool). If the issue persists, double-check the agent settings and tool configurations within your dashboard for accuracy.