Agents with Retrieval, Function Calling and Memory
30-second answer
Give an agent the tool that matches the need. Function calling reaches live data and actions, where the model asks and your code runs the function. File search and Azure AI Search ground answers on documents. OpenAPI and MCP tools call outside services. Memory stores facts about a user, scoped per user, so a new conversation next week still knows the preference. The conversation only holds one chat.
Simulate it » No Azure account neededExam objective: 2.2.2 Build agents that integrate retrieval, function calling and conversation memory. 2.2.3 Integrate agent tools, including APIs, knowledge stores, search, content understanding and custom functions. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Tools come in kinds. <strong>File search</strong> reads documents, <strong>Azure AI Search</strong> reads your index, <strong>MCP</strong> and <strong>OpenAPI</strong> call outside services, and a <strong>function</strong> runs your own code.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Tools come in kinds. File search reads documents, Azure AI Search reads your index, MCP and OpenAPI call outside services, and a function runs your own code.
- File search chunks and embeds uploaded files into a vector store. The agent searches it when a question needs the documents.
- Memory keeps facts about a user across conversations. Set the scope so each customer only sees their own.
- Try it. A policy question uses file search, an order question uses the function, and a new conversation next week still knows the preference.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Retrieval, function calling and memory
One agent can use file search for documents, a function for live data and memory for what it learned about a user. The model asks to call a function; your code runs it and returns the result. Memory survives into a new conversation.
🤔 What happens if…
Read this tour as text
- Deploy a model, call the deployment. A deployment is a named copy of a model with a version, a deployment type and capacity. Your app calls the deployment name, never the model name. Pick a large model for hard work and a small language model for cheap, fast, simple work.
- RAG: retrieve first, then answer. Retrieval-augmented generation searches your own content (Azure AI Search, hybrid keyword plus vector), puts the best chunks in the prompt and asks the model to answer from them with citations. Without retrieval the model guesses.
- A multistep flow with checks. A workflow breaks one big request into steps you control: classify, extract to a JSON schema, call a tool, draft, then verify. Retries, fallbacks and a final check live in code, so one bad step can’t slip through unseen.
- Evaluate before you ship. Evaluators score each answer on a test set: groundedness (is it supported by the context?), relevance, coherence and safety checks. A fabrication shows up as a low groundedness score on one row, so you fix it before users see it.
- SDK, project endpoint and connections. The Foundry SDK (
azure-ai-projects) opens one door: AIProjectClient with the project endpoint and DefaultAzureCredential. From it your app gets an OpenAI-compatible client, deployments and connections (Azure AI Search, Application Insights) with no secrets in code. - Design the agent: role, goal, tool schema. An agent is a model plus instructions (role and goal), tools and a conversation (thread). A strict function schema names each parameter and marks the required ones, so the model asks the user instead of inventing a value.
- Retrieval, function calling and memory. One agent can use file search for documents, a function for live data and memory for what it learned about a user. The model asks to call a function; your code runs it and returns the result. Memory survives into a new conversation.
- Multi-agent orchestration. Several specialist agents can share a job. Sequential passes work down a line, concurrent fans out and merges, handoff moves control to the right specialist, group chat lets agents take turns in one shared conversation and Magentic lets a manager agent plan and delegate. Microsoft Agent Framework builds all five.
- Autonomy with approvals. Reads are safe, writes are not. A tool marked approval required pauses the run until a person decides. A hard limit in code blocks what no one should approve, whatever the model says.
- Monitor and debug agent runs. Agent evaluators read the whole run: intent resolution, tool call accuracy and task adherence. Error analysis groups the failing rows, such as a made-up tool argument, and points to the fix.
- Tune prompts and parameters. Instructions shape tone and rules, a few-shot example shows the format, temperature and top_p change how adventurous the wording is, and max output tokens caps length. A self-critique loop drafts, checks against a checklist and revises once.
- Trace every call and count tokens. OpenTelemetry spans record each agent run, model call and tool call, with tokens and latency, and Application Insights stores them. Tracing is opt-in, and recording message content is for development only because it captures prompts and answers.
- Route requests to the right model. A hybrid design puts rules first for answers code can decide, a small model for easy language work and a large or reasoning model only when needed. A model router can pick for you. Fewer big-model calls means a lower bill and faster replies.
Priya asks Contoso's order agent where her order is. Create the agent with a strict function schema and file search, see it ask for a missing order number instead of guessing, then give it memory so it remembers a preference next week.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
The agent can’t see order data, can’t read the policy PDFs and forgets the customer every time.
😊 THE SOLUTION
Give it a function for live data, file search for documents and memory for the customer.
- Live order status✓ Function calling
- Policy documents✓ File search or Azure AI Search
- “I told you last week”✓ Memory scoped to the user
Start with a question
How does a good shop assistant know your order, the policy and you?
Three different things are at work. She looks at the computer for where your parcel is right now. She flips the policy folder for the return rules. And she remembers you: “You like WhatsApp messages, don’t you?”
An agent has the same three. A function reads the live order system. File search or Azure AI Search reads the policy documents. Memory remembers you the next time you come in.
Explain it like I’m 10
The technical explanation
Which tool for which need
| The agent needs | Tool | Notes |
|---|---|---|
| Live data or an action | Function | The model asks, your code runs it, you send the result back |
| Answers from documents users or apps provide | File search | Vector store over uploaded files |
| Answers from a curated company index | Azure AI Search (or a Foundry IQ knowledge base) | Hybrid search, citations |
| A REST API with a spec | OpenAPI tool | Describe it once, the agent calls it |
| A remote tool server | MCP tool | Choose allowed tools and approval |
| Fields from a document or image | A Content Understanding analyzer, called from a function or tool | Predictable extraction |
| Facts about a user over time | Memory | Scoped per user |
The function-calling loop
conversation = openai.conversations.create()
r = openai.responses.create(conversation=conversation.id, input="Where is order ORD-1042?")
for item in r.output:
if item.type == "function_call": # the model ASKS
result = lookup_order(**json.loads(item.arguments)) # your code RUNS it
r = openai.responses.create(conversation=conversation.id,
input=[{"type": "function_call_output", "call_id": item.call_id,
"output": json.dumps(result)}]) # send the result back
print(r.output_text)
The model never runs your code. That’s why a function is the safest way to reach private systems: you decide what it can do and you can add checks inside it.
Memory across conversations
A conversation holds one chat. Memory (preview as of 25 November 2026) extracts durable facts, such as “prefers WhatsApp updates”, stores them in a memory store, and retrieves them in a later chat. It stores user profile facts and chat summaries.
tools.append(MemorySearchPreviewTool(memory_store_name="customer-memory",
scope="{{$userId}}", # one memory per customer
update_delay=300))
Set the scope so each user sees only their own memory, and set a retention period. A memory store needs a chat deployment and an embedding deployment, because recall uses search over the stored items.
Architect level Why a function beats pasting data into the prompt
Order data changes every minute and belongs to one customer. Putting it in the prompt up front wastes tokens and risks showing the wrong customer’s data. A function fetches only what the question needs, for the signed-in customer, at the moment of the question. It can also enforce rules, such as only returning orders for the current user ID, because your code decides what it returns.
Real-world business scenario
Contoso Retail (fictional)
- The problem
- Customers repeated their preferences in every chat, and the agent couldn't see order status or read the returns policy.
- What they used
- One order-agent with a get_order_status function, file search over the policy PDFs, and a customer-memory store scoped by user ID with a 90-day retention.
- Why that choice
- Each need has its own tool: live data through code, documents through search, preferences through memory.
- The result
- The agent answered order and policy questions in one chat and remembered WhatsApp as the preferred channel in later ones.
When to use it and when not to
✓ Use it when…
- The agent needs live data, documents or user preferences it can't know on its own.
- You want answers to cite sources.
- Users return and should be recognised across sessions.
✕ Think twice when…
- Memory for shared company knowledge. Use a knowledge base or search.
- Letting a tool do anything. Limit what each function can do.
- Adding every tool just in case. Each tool adds confusion and risk.
↔ Alternatives to consider
- A Foundry IQ knowledge base for managed multi-source retrieval.
- A workflow if the steps are fixed.
- A single prompt if no tools are needed.
Test yourself with exercises
5 original practice questions in the AI-103 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Who runs a function when an agent calls it?
Model answer
Your code does. The model only asks, for example "call get_order_status with ORD-1042". Your app runs it, then sends the result back so the model can write the answer.
Intermediate When do you pick file search and when Azure AI Search?
Model answer
File search suits documents given to the agent or a conversation, such as an uploaded contract. Azure AI Search suits a curated index the company maintains, with hybrid search and ranking.
Experienced developer How do you stop memory leaking between customers?
Model answer
I scope the memory store per user, with the user ID as the scope key, so searches and updates only touch that user's items. I also set a retention period and keep an eye on what it stores.
Scenario The agent must also call a partner API. What are the options?
Model answer
If the partner publishes an OpenAPI spec, I add an OpenAPI tool. If they run an MCP server, I add an MCP tool and decide which of its tools are allowed and whether approval is required. For my own logic, a function.
Quick revision
Key points
- Functions reach live data and actions; your code runs them.
- File search grounds on files; Azure AI Search on a curated index.
- OpenAPI and MCP tools reach outside services.
- Memory carries user facts across conversations, scoped per user.
- The conversation only covers the current chat.
Important terminology
- Function calling
- The model returns a request to call your function with arguments; your code runs it and sends the result back.
- File search
- An agent tool that searches files in a vector store, such as uploaded policy documents.
- Memory
- Long-term storage of facts about a user, extracted from conversations and recalled in later ones.
- Memory scope
- The key, such as a user ID, that decides whose memory is read and written.
- MCP tool
- A tool that connects an agent to a remote Model Context Protocol server and its tools.
- OpenAPI tool
- A tool that lets an agent call a REST API described by an OpenAPI specification.
Common mistakes
- Using memory for company documents.
- Forgetting that your code must run the function.
- Memory with no scope, so users could see each other's facts.
Exam tips
- "Live order status" = function calling.
- "Documents users upload mid-chat" = file search.
- "Remember preferences across sessions" = memory scoped to the user.
Five quick revision questions
-
1.Who executes a function call?Show
The application code.
-
2.Which tool searches uploaded files?Show
File search.
-
3.What keeps facts between conversations?Show
Memory.
-
4.What decides whose memory is used?Show
The scope key.
-
5.Which tool calls a REST API with a spec?Show
An OpenAPI tool.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Multi-Agent Orchestration
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.