Combining Retrieval, Function Calling and Memory in Agents
This lesson explains how the most useful agents combine three capabilities, knowing the organization's content, acting in its systems and remembering the user, and how each is implemented in one agent.
Learning outcomes
After completing this lesson, you will be able to:
- Choose a knowledge tool for an agent's retrieval needs.
- Explain how a client completes a function call for an agent.
- Describe conversation memory and long-term memory.
- Personalize an agent safely within privacy rules.
Retrieval
Retrieval lets an agent answer from the organization's content rather than only from what its model learned in training. An agent does not query an index directly; it retrieves through knowledge tools. When the agent decides that a question needs facts, it calls a knowledge tool, which returns relevant passages, and the agent answers from them. All knowledge tools return citations as annotations that the application displays. The lesson on choosing memory, tools and knowledge for agents explains when to choose each tool; this section explains how each is configured.
File search creates a vector store from uploaded files and searches it with hybrid search and reranking. It suits files attached by users or a small agent-specific document set.
The Azure AI Search tool queries an existing index through a project connection, with a configured query type (simple, semantic, vector, hybrid or vector-semantic-hybrid), filters and the number of results to return (top-k).
A Foundry IQ knowledge base is connected as a tool through its MCP endpoint and performs agentic retrieval across several knowledge sources.
Function calling in agents
When a prompt agent decides to call a function tool, the response contains a function_call item, and the run waits. The application executes the function with its own credentials and business rules and returns a function_call_output item in the next request on the same conversation; the agent then continues. Built-in tools such as file search, code interpreter and web grounding run inside the service, and OpenAPI and MCP tools are called by the service directly using the configured authentication.
Who executes a tool decides where its controls live. With a function tool, the application runs the call, so it can apply the signed-in user's identity and permissions, check business rules and refuse a request before anything happens; the cost is that the application must stay in the loop for every call. With an OpenAPI or MCP tool, the service calls the API itself, which needs no application code, but the controls must be built into the API, its authentication and the tool's approval settings, because the application never sees the call before it is made.
A practical rule follows. Logic that exists only for this agent, or that needs the user's context in a way an API does not support, fits a function tool. A capability that already exists as a secured API, or that several agents should share, fits an OpenAPI or MCP tool, with approval required for any operation that changes data.
The following diagram compares who executes the call in each case.

Memory
Memory is the information an agent keeps and reuses, because the model itself retains nothing between requests. Foundry Agent Service provides two kinds.
Conversation memory is the stored conversation: the messages, tool calls and results of the current exchange, which let the agent understand follow-up questions.
Long-term memory in Foundry Agent Service (preview) extracts durable information from conversations, such as preferences and facts the user shares, and stores it in a memory store scoped by a user identifier. It retrieves relevant memories in later conversations so the agent can personalize responses.
Alternatives are application-managed memory in Azure Cosmos DB, retrieved and added to the instructions, or summaries of earlier conversations. Memory design must decide what may be stored, for how long, and how users can view or delete it.
Combining capabilities
The three capabilities answer different kinds of request, and a single conversation often needs all of them. A banking customer may ask about a fee, which is a fact in the bank's documents and calls for retrieval. The next question may be about the customer's own balance, which exists only in a live system and calls for a function. A request to "send it in Spanish, like last time" depends on long-term memory, and a follow-up such as "and for business accounts?" depends on the stored conversation to know what "it" refers to.
Recognizing which capability a request needs is a frequent exam skill. Facts that are the same for every user and change occasionally point to retrieval; data that is specific to the user or changes by the minute points to function calling; and information the user shared in earlier conversations points to memory. The following table summarizes the banking example.
| User need | Capability | Implementation |
|---|---|---|
| "What is the fee for international transfers?" | Retrieval | Azure AI Search tool over the fee schedule |
| "What is my current balance?" | Function calling | Function tool that calls the core banking API |
| "Send it in Spanish, like last time." | Long-term memory | Remembered language preference |
| "And for business accounts?" | Conversation memory | Stored conversation context |
Which capability answers it?
Personalizing safely
A travel agent should remember each traveller's seat preference and frequent flyer number across conversations. Privacy policy forbids storing passport numbers, which travellers sometimes type into the chat.
Use long-term memory scoped by the traveller's user ID for preferences, and prevent passport numbers from being stored by detecting and redacting them (with PII detection) before memory extraction, or by excluding that information type in the memory configuration, and tell users how to view and delete what is remembered. Relying on conversation history alone would not persist preferences across conversations.
The same rule can be written into a memory store. The following screenshot shows the user profile details of a memory store, which tell it what to remember and what never to store.

Which tools does the service call itself, and which does the application run?
Show answer
OpenAPI and MCP tools are called by the service. Function tools are executed by the application.
Exam Tips
Remember for the exam
- Agent files: file search. Existing index: Azure AI Search tool. Several sources: Foundry IQ knowledge base.
- Function tools are executed by the application; OpenAPI and MCP tools are called by the service.
- Long-term memory is scoped per user and must follow privacy and retention rules.