A unified Azure platform for creating and managing AI models, agents, and applications with built‑in enterprise security, monitoring, and governance
Noopur Nanda hi, thx for sharing urs issue here at Q&A portal,
For this use case, don’t use the knowledge base path only. KB/RAG is good for answering from docs, but it’s not great for exact counts like ‘how many docs by type’. Best fit is a custom tool that calls Azure AI Search directly and returns the count. The agent can decide to call that tool when the user asks things like ‘total documents’, ‘count by document type’, etc.
U don’t need MCP for this if u already have an API in a Web App. Expose a small endpoint like /count-documents?type=invoice or /stats/documents, then add it to the agent as an OpenAPI/function tool. The tool should query Search with filters/facets, not ask the model to count text chunks.
For Azure AI Search, exact counting can be done with $count=true, and grouped counts are better done with facets if ur field is marked facetable https://learn.microsoft.com/en-us/azure/search/search-faceted-navigation
So flow would be somthing like user asks count -> agent calls ur API tool -> API queries Azure AI Search -> returns JSON count -> agent formats the answer.
Example API response could be
{
'documentType': 'Policy',
'count': 42
}
Code interpreter isn’t the best option here bc it won’t automatically have secure access to ur Search service and it’s more for ad-hoc file/data work. For live index queries, a tool/API is cleaner and easier to secure.
At the end )))) make sure documentName and documentType fields in ur search index are marked as filterable / facetable depending on how u wanna query them. If they aren’t, the agent/tool won’t be able to count them properly without reindexing.
rgds,
Alex
&
If my answer was helpful pls mark it and additional thx if u follow me at Q&A portal