
Connect Foundry IQ to Your AI Agent in 20 Lines of Code
The Problem
Every team building AI agents rebuilds the same RAG infrastructure from scratch: data connections, chunking, embeddings, routing, permissions. It’s repetitive, error-prone, and slows down time-to-value.
You want your agent to access enterprise knowledge without managing complex retrieval pipelines.

The Nugget
Foundry IQ is Microsoft’s managed knowledge layer that treats retrieval as a reasoning task. Connect it to the Microsoft Agent Framework with the AzureAISearchContextProvider and get enterprise-grade RAG in ~20 lines of Python.
Quick Setup
Prerequisites: Azure AI Search service, Azure AI Foundry project, Python 3.10+
pip install agent-framework-azure-ai-search —prepip install agent-framework-azure-ai-search --pre
from agent_framework import ChatAgent
from agent_framework.azure import AzureAIAgentClient, AzureAISearchContextProvider from azure.identity.aio import DefaultAzureCredential
credential = DefaultAzureCredential()
AzureAISearchContextProvider( endpoint=“YOUR_SEARCH_ENDPOINT”, knowledge_base_name=“YOUR_KNOWLEDGE_BASE”, credential=credential, mode=“agentic”, ) as search, AzureAIAgentClient( project_endpoint=“YOUR_PROJECT_ENDPOINT”, model_deployment_name=“gpt-4o”, async_credential=credential, ) as client, ChatAgent(chat_client=client, context_providers=[search]) as agent, ):
print((await agent.run("What's in the knowledge base?")).text)
asyncio.run(main())import asyncio
from agent_framework import ChatAgent
from agent_framework.azure import AzureAIAgentClient, AzureAISearchContextProvider from azure.identity.aio import DefaultAzureCredential
credential = DefaultAzureCredential()
AzureAISearchContextProvider( endpoint=“YOUR_SEARCH_ENDPOINT”, knowledge_base_name=“YOUR_KNOWLEDGE_BASE”, credential=credential, mode=“agentic”, ) as search, AzureAIAgentClient( project_endpoint=“YOUR_PROJECT_ENDPOINT”, model_deployment_name=“gpt-4o”, async_credential=credential, ) as client, ChatAgent(chat_client=client, context_providers=[search]) as agent, ):
print((await agent.run("What's in the knowledge base?")).text)
asyncio.run(main())
Two Retrieval Modes
AspectSemantic ModeAgentic Mode (Foundry IQ)SpeedFastSlower (query planning)Query TypeSingle-hop lookupsMulti-hop reasoningBest ForSpeed-critical appsComplex research queries
Use mode="semantic" for simple lookups, mode="agentic" for complex questions that need context from multiple sources.
Why This Matters
-
36% better response relevance on complex multi-hop queries vs traditional RAG
-
Reusable Knowledge Bases – define once, connect from any agent
-
Built-in security – document-level ACLs, Entra identity, Purview integration
-
No RAG rebuilding – indexing, vectorization, chunking handled automatically
Pro Tip
Already have an Azure AI Search index? The provider auto-creates a Knowledge Base from your existing index:
AzureAISearchContextProvider( endpoint=“YOUR_SEARCH_ENDPOINT”, index_name=“your-existing-index”, <em># Not knowledge_base_name</em> mode=“agentic”, azure_openai_resource_url=“YOUR_OPENAI_URL”, model_deployment_name=“gpt-4o”, )AzureAISearchContextProvider( endpoint=“YOUR_SEARCH_ENDPOINT”, index_name=“your-existing-index”, <em># Not knowledge_base_name</em> mode=“agentic”, azure_openai_resource_url=“YOUR_OPENAI_URL”, model_deployment_name=“gpt-4o”,
No migration needed – your existing index becomes a Knowledge Base on the fly.
Connect Foundry IQ to Your AI Agent in 20 Lines of Code is about giving an AI agent access to enterprise knowledge without rebuilding every retrieval component manually. Foundry IQ can reduce implementation effort, but teams still need to validate authentication, permissions, data boundaries and monitoring before production use.
Runbook notes for Connect Foundry IQ to Your AI Agent in 20 Lines of Code
Connect Foundry IQ to Your AI Agent in 20 Lines of Code deserves a little more operational context because the decision usually affects AI knowledge retrieval. The related items are Foundry IQ, RAG, enterprise knowledge, permissions, grounding quality. Treat this Nugget as a starting point for a concrete tenant decision: who is in scope, which Microsoft portal or policy is touched, and what visible result should confirm that the configuration worked.
When validating Connect Foundry IQ to Your AI Agent in 20 Lines of Code, keep the test narrow enough to understand the result. Select one representative user, device, workload or subscription, capture the current state, then apply the change and compare the outcome. This avoids guessing later when support sees a different enrollment state, access result, model response, update status or admin center signal.
The most useful documentation for Connect Foundry IQ to Your AI Agent in 20 Lines of Code is practical rather than theoretical. Record the assignment logic, the owner, the expected monitoring view and the exception path. If the change affects users, include the wording support teams should use when they explain the behavior. If it affects devices or services, include the exact place where administrators can verify health.
For search consistency, keep the phrase Connect Foundry IQ to Your AI Agent in 20 Lines of Code connected to the body text, the internal links and the category context. That helps readers understand why this Microsoft admin topic belongs with the surrounding Intune, Entra, Azure, Copilot, Security or automation Nuggets, and it gives AI search systems clearer signals about the real subject of the page.