Building Agents
Prompt, voice and hosted agents · conversations · function calling · tools & toolboxes · memory · workflows & A2A · approvals · tracing & evaluation
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Agent types and runtime components
| Agent type | You provide | Foundry manages | Pick it when |
|---|---|---|---|
| Prompt agent | Instructions, a model and tools (configuration only) | The runtime, scaling and a stable endpoint; no code, containers or compute for you to run | You want the fastest start, or a production agent without custom orchestration logic |
| Voice-based prompt agent | Model, instructions, audio settings, optional greeting and tools | The agent lifecycle; Voice Live handles speech recognition, turn taking and synthesis | You need real-time spoken conversations without hosting the voice orchestration |
| Hosted agent | Your own code and framework (for example Agent Framework, LangGraph, OpenAI Agents SDK) as a container image or .zip | A managed endpoint, automatic scaling and a dedicated Microsoft Entra identity | You need custom code, orchestration logic, middleware or protocols |
| Responses API (ephemeral agent) | The definition (instructions, tools, model) in your application code on every call | No agent resource in Foundry | Agent logic should ship with your app; it can't use the Copilot harness or the prompt-agent optimizer |
| Runtime component | Role | Use it when |
|---|---|---|
| Agent | Supplies reusable model, instructions and tools to a response | Several requests need the same behavior or tool setup |
| Conversation | Supplies persisted input and output items to responses | Later turns need server-side history |
| Response | Runs a model or agent against input and produces output items | Every interaction: one unit of execution, with or without an agent or conversation |
Tracking the conversation
- A conversation persists history across turns. It stores items: messages, tool calls, tool outputs and other data.
- By default the service stores response history server-side, so a follow-up can set
previous_response_id. - With
storeset tofalsenothing is persisted: you carry context forward by passing previous output items as input. - If a conversation outgrows the model's context size, the model truncates the input context. The conversation itself is not truncated.
- Saving a change to a prompt agent creates a new version.
Use the instructions to describe the agent's role, behavior, boundaries and expected output, and tell the model what each tool is for. If tools overlap, add a decision rule such as using File Search before Web Search for internal content.
Tools, function calling and toolboxes
Function calling flow
- Define function tools: name, parameters and purpose of each function.
- Create an agent registered with the function definitions.
- Send a prompt: the model requests a function call if needed.
- Execute and return: your app runs the function and submits the output (a
function_call_outputitem with thecall_id) back. - Get the final response: the agent uses your output to finish its answer.
- Your app executes the function, not Foundry. Runs expire 10 minutes after creation, so submit tool outputs before then.
- The portal can run an agent that has function tools, but it can't add, remove or update function definitions. Use the SDK or REST API.
- A function definition is a JSON-schema style object:
type,propertieswith descriptions, andrequiredparameters.
| Tool | Use it to |
|---|---|
| Function calling | Let the model request your own code; your app runs it |
| File search | Search user-provided documents through a vector store |
| Azure AI Search | Ground answers in an index you own, with inline citations |
| Memory search | Read and write long-term memory for the user |
| MCP | Call tools on a remote Model Context Protocol server |
| OpenAPI | Call a REST API described by an OpenAPI spec |
| Agent-to-agent (A2A) | Call another agent through a remote A2A endpoint |
| Web search, code interpreter | Built-in tools for current web information and running code |
Azure AI Search tool parameters
| Parameter | Required | Notes |
|---|---|---|
project_connection_id | Yes | Resource ID of the project connection to Azure AI Search |
index_name | Yes | Index in your search resource |
top_k | No | Defaults to 5 |
query_type | No | Defaults to vector_semantic_hybrid; also simple, vector, semantic, vector_simple_hybrid |
filter | No | Applies to all queries the agent makes to the index |
Control tool calling with tool_choice
| Value | Behavior |
|---|---|
auto | The model decides whether to call tools |
required | The model must call one or more tools |
none | The model doesn't call tools |
Toolbox
- A toolbox groups tools into one reusable unit behind a single MCP-compatible endpoint. Authentication, governance and versioning are central, so tools change without changing agent code.
- Create and test a new toolbox version, then promote it to default; agents pointing at the toolbox pick it up.
- Tool search hides tools by default and exposes two meta-tools,
tool_searchandcall_tool, so hundreds of tools don't flood the context window. - Tools define what an agent can do; skills define how it performs a task.
- Azure AI Search tool in a private virtual network: authenticate with the Microsoft Entra project managed identity. Key-based authentication isn't supported there.
- Azure AI Content Understanding turns messy multimodal files into predictable, standardized input for agents.
Memory
| Memory type | Holds | Retrieve |
|---|---|---|
| User profile memory | Durable user preferences and personal context | Near the start of each conversation |
| Chat summary memory | Distilled summaries of prior conversation topics and threads | Per turn, using current messages |
| Procedural memory | Reusable how-to routines inferred from prior interactions | When the user asks for a recurring task |
- Short-term memory tracks the current session's conversation. Long-term memory keeps distilled knowledge across sessions, and Foundry memory is built for long-term memory.
- Memory phases: extraction, consolidation (LLM-based merge of duplicates and conflicts), retrieval.
- Two ways to use it: attach the memory search tool to a prompt agent (simplest), or call the memory store APIs for control over individual records.
scopepartitions a memory store. With the memory search tool, setscopeto{{$userId}}for per-user isolation. With the low-level APIs you must setscopeexplicitly.- Limits: 100 scopes per memory store, 10,000 memories per scope. VNet integration isn't supported for memory stores.
- Memory needs compatible Azure OpenAI chat and embedding model deployments. The pages call Memory in Foundry Agent Service and the Memory Store API preview features.
| Need | Use |
|---|---|
| What the agent learned about this user over time | Memory |
| Curated organizational content | A Foundry IQ knowledge base |
| Documents the user provides during an interaction | File search |
Memory is filled from conversations, so protect it against prompt injection and memory corruption: use Azure AI Content Safety prompt injection detection and test the agent adversarially.
Orchestration, approvals and safeguards
| Workflow pattern | What it does | Typical use |
|---|---|---|
| Human in the loop | Asks the user a question and awaits input | Approval requests or collecting information |
| Sequential | Passes the result from one agent to the next in order | Pipelines and multi-stage processing |
| Group chat | Dynamically passes control between agents based on context or rules | Escalation, fallback or expert handoff |
- Workflows are UI-based: declarative sequences that orchestrate agents with branching and variables. Hosted agents aren't supported in the workflow designer.
- Foundry doesn't save workflows automatically; select Save after every change. Each save creates a new version.
- To connect one agent to another, use the A2A tool (the GA tool type is
a2a) or a workflow. The Connected Agents tool from the classic API isn't available in the new Agent Service. - For custom multi-agent orchestration in code, use a hosted agent with Microsoft Agent Framework or another framework.
Approval flow and safeguards
- MCP tool: set
require_approvaltoalwaysfor high-risk calls. The app answers eachmcp_approval_requestwith anmcp_approval_responsein the same conversation. allowed_toolsrestricts the tools. An empty list[]allows all tools the server exposes, not zero.- Treat tool descriptions, annotations and results from remote MCP servers as untrusted input; validate critical values and require user approval before consequential actions.
- Don't put keys, tokens or other credentials in prompts or traces.
- Route MCP traffic through an AI gateway to enforce authentication, rate limits, IP restrictions and audit logging without changing the MCP server or agent. Policies are applied in Azure API Management.
- Each agent can have its own Microsoft Entra identity; content filters and guardrails help mitigate prompt injection, including cross-prompt injection.
Monitoring, evaluation and error analysis
- Server-side tracing is the recommended start: connect an Application Insights resource to the project and Foundry enables it, with no code changes. Add client-side instrumentation later for your own application code.
- Traces are stored in Application Insights using OpenTelemetry conventions. Viewing them needs the Log Analytics Reader role on the connected Application Insights resource.
- A trace shows inputs and outputs of each step in order: tool calls, tool results, token use, latency. Spans are single operations and can nest, which helps find where an error began.
- The Monitor tab of an agent shows token usage, latency, success rates and evaluation results for production traffic.
| Evaluator | Kind | Asks |
|---|---|---|
| Task Completion | System | Did the agent fully complete the requested task? |
| Task Adherence | System | Did the agent follow the rules and constraints in its instructions? |
| Intent Resolution | System | Did the agent correctly identify and address user intentions? |
| Tool Selection | Process | Did the agent select the correct and necessary tools? |
| Tool Call Accuracy | Process | Did the agent make the right tool calls with correct parameters? |
| Tool Call Success | Process | Did the tool calls succeed without technical errors? |
| Tool Output Utilization | Process | Did the agent correctly use tool results in its reasoning and answer? |
System evaluation checks end-to-end outcomes. Process evaluation checks each step, mainly tool calls. Evaluators work like unit tests and return Pass/Fail scores, so you can set an acceptance threshold before release.
| Symptom | Check |
|---|---|
| Agent doesn't call a tool | Tool attached? Model supports the tool? Set tool_choice to required for deterministic behavior; review the trace |
| Tool returns empty or irrelevant results | Improve tool descriptions and instructions; for retrieval tools make sure the data is ingested and searchable |
| Tool call fails | Verify tool configuration and authentication; for MCP and OpenAPI confirm the endpoint is reachable |
| "Tool not supported" although tables show support | Tool needs support from both the model and the region |
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a conversation for multi-turn use (Python) | conversation = openai.conversations.create() | - |
| Respond inside a conversation (Python) | response = openai.responses.create(
conversation=conversation.id,
input="What is the size of France in square miles?",
) | - |
| Follow up on a stored response (Python) | follow_up = openai.responses.create(
previous_response_id=response.id,
input="What is the population of that city?",
) | - |
| Create a prompt agent version (Python) | agent = project.agents.create_version(
agent_name="my-agent",
definition=PromptAgentDefinition(
model="gpt-5-mini",
instructions="You are a helpful assistant.",
),
) | - |
Exam Tips
Tick each tip once you can answer it without looking.
“Foundry should run the agent from a saved definition: instructions, model, tools; no code, containers or compute to maintain” → Prompt agent. Trap: A hosted agent runs your own code in a container; the Responses API ephemeral pattern keeps the definition in your app and creates no agent resource.
“Bring your own framework (LangGraph, Agent Framework) or custom orchestration and protocols” → Hosted agent: container or .zip, managed endpoint, scaling, dedicated Entra identity. Trap: A prompt agent is configuration only; it has no custom runtime code.
“The model asks for a function call: who runs the function?” → Your app runs it and submits the output (function_call_output with the call_id) before the run expires, 10 minutes after creation. Trap: Foundry doesn't execute your function; late outputs miss the expiry.
“Add, remove or update function definitions on an agent” → SDK or REST API. Trap: The portal can run an agent with function tools but can't edit the function definitions.
“Multi-turn context without rebuilding it yourself” → Use a conversation (or previous_response_id); with store false you pass previous output items as input. Trap: Without a stored response or conversation, the service has nothing to continue from.
“Make tool calling deterministic” → tool_choice: required forces a call, none blocks calls, auto lets the model decide. Trap: Better instructions help but don't give the same deterministic control.
“MCP allowed_tools set to an empty list []” → Allows all tools the MCP server exposes. Trap: It doesn't mean zero tools; restrict access with a nonempty list.
“Human must approve high-risk MCP tool calls” → require_approval = always; reply with mcp_approval_response in the same conversation. Trap: Don't switch to previous_response_id for the Copilot harness; it needs a conversation.
“Remember each user's preferences across sessions, isolated per user” → Memory store + memory search tool with scope = {{$userId}}. Trap: Low-level memory APIs don't resolve scope automatically: set scope explicitly.
“Ground on curated organizational content vs. user-provided documents vs. learned user context” → Foundry IQ knowledge base vs. file search vs. memory. Trap: Memory is for what the agent learns from interactions, not for a document library.
“Share one governed set of tools with central auth and versioning across agents” → Toolbox (single MCP-compatible endpoint); add tool search for very large tool sets. Trap: Wiring each tool into each agent duplicates credentials and governance.
“Orchestrate agents with approvals, sequence or expert handoff, visually” → Workflow patterns: human in the loop, sequential, group chat. Trap: Hosted agents aren't supported in the workflow designer; workflows are retiring December 1, 2026 in favor of Microsoft Agent Framework.
“Call another agent from a Foundry agent” → A2A tool (a2a) or a workflow. Trap: The Connected Agents tool from the classic API isn't available in the new service.
“See why an agent behaved badly, with the least effort” → Connect Application Insights to the project (server-side tracing); read traces; Log Analytics Reader to view. Trap: Client-side instrumentation is a second step for your own code; the reader role doesn't turn tracing on.
“Check each step vs. check the final outcome” → Process evaluators (Tool Selection, Tool Call Accuracy, Tool Call Success) vs. system evaluators (Task Completion, Task Adherence, Intent Resolution). Trap: A passing final outcome can hide wrong or redundant tool calls.
Sources
- What is Microsoft Foundry Agent Service?
- Prompt agents in Foundry Agent Service
- Build with runtime components in Foundry Agent Service
- Tool best practices for Foundry Agent Service
- What is Toolbox in Microsoft Foundry?
- Use function calling with Foundry agents
- Connect an Azure AI Search index to Foundry agents
- File search tool for Foundry agents
- Connect to Model Context Protocol servers
- Connect to an A2A agent endpoint
- Govern MCP tools by using an AI gateway
- What is Memory?
- Create and use memory in Foundry Agent Service
- Build a workflow in Microsoft Foundry
- Agent tracing overview
- Set up tracing for AI agents
- Monitor agents with the Agent Monitoring Dashboard
- Agent evaluators
- Evaluate your AI agents
- Azure Content Understanding overview
- Quickstart: Get started with the Foundry SDK
Checked against Microsoft Learn on November 13, 2026.