Skip to content

query_knowledge

The query_knowledge tool lets agents look up factual information from their linked knowledge bases during a phone call. Instead of stuffing documents into the realtime model’s context, a separate GPT-4o-mini call handles retrieval on demand.

The tool is registered at session start only if the agent has at least one linked knowledge base. If no knowledge bases are assigned, the tool doesn’t exist and the model won’t attempt to use it.

{
"name": "query_knowledge",
"description": "Searches the agent's knowledge bases for relevant information
and returns a concise answer. You MUST call this tool before answering any
question that could be covered by the available knowledge — do not guess
or make up information. Available knowledge bases and topics: {kb_descriptions}.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "A natural language description of the information
you need. Be specific about what you're looking for."
}
},
"required": ["query"]
}
}

The description dynamically includes knowledge base titles and document names so the model knows what topics are available before deciding to call the tool.

When registered, a behavioral instruction is appended to the agent’s system prompt:

You have access to knowledge bases covering: {kb_titles}.
When the user asks about any of these topics, always use the query_knowledge
tool to look up accurate information — never guess or make up answers.
Model calls query_knowledge({ "query": "What are the office hours?" })
→ Parse arguments, extract query string
→ Fetch all documents from agent's linked knowledge bases
→ Format as: ## Document: "{title}"\n\n{content}
→ Send to GPT-4o-mini with grounding prompt
→ Return concise answer to realtime model
→ Model speaks the answer

System:

You are a knowledge base assistant. Your task is to answer questions
based ONLY on the provided documents.
Rules:
- Answer concisely — your response will be read aloud by a voice agent
during a phone call.
- Use ONLY information from the provided documents. Do not add external
knowledge.
- If the documents do not contain relevant information, respond with:
"I don't have information about that in the available documents."
- Do not mention that you are reading from documents — just provide
the answer naturally.

User:

# Documents
## Document: "{title}"
{content}
---
# Question
{query}
  • Missing or invalid query argument → returns "Error: missing 'query' argument"
  • No linked knowledge bases → returns "Agent has no linked knowledge bases"
  • Empty documents → returns "The knowledge bases contain no documents."
  • LLM failure → error logged, error string returned to model