Lesson 1 of 3 Building Agents with Foundry Agent Service

Designing Agents: Instructions, Conversations and Tool Schemas

This lesson explains how to design and create agents in Foundry Agent Service. An agent pursues a goal by reasoning, calling tools and responding over a conversation, and its behaviour is defined by its instructions, its tools and how it tracks the conversation.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how an agent loops between the model and its tools.
  • Distinguish prompt agents, workflow agents and hosted agents.
  • Write effective agent instructions.
  • Use stored conversations to keep context.
  • Write tool schemas that lead the model to the right tool.

How an agent works

A generative application calls a model once and returns the result. An agent is different in one important way: it decides for itself what to do next. Given a goal such as "find out why order ORD-104233 is late and tell the customer", the agent can look up the order, notice that the carrier reported a problem, check the carrier's status, and only then write a reply. The sequence of steps is not written in code; the model chooses it at run time.

Every agent is built from three parts. The model provides the reasoning. The instructions tell it its role, its goals and its limits. The tools let it act beyond producing text: searching content, calling APIs, running code. An agent run proceeds as a loop. The model reads the conversation and either answers or requests a tool call; the tool runs and its result is added to the conversation; and the model reads the updated conversation and decides again. The loop ends when the model produces a final answer, when a limit on steps is reached, or when a step requires a person's approval.

This flexibility is both the value and the risk of agents. An agent can handle requests that no developer anticipated, but it can also choose the wrong tool, loop without finishing, or be manipulated by content it reads. Much of this module and the next is therefore about guiding the loop: precise instructions and tool descriptions so that the model chooses well, stored conversations so that it has the right context, and safeguards, approvals and monitoring so that its choices stay within acceptable limits.

Foundry Agent Service is the managed runtime for this loop. It stores agent definitions and conversations, runs built-in tools, applies guardrails at every step and records traces, so the application only sends the user's input and displays the result.

Agent types in Foundry

Foundry Agent Service is the managed service that stores, runs and governs agents in a Foundry project. Agents have names and immutable versions, and each version can have its own guardrail. The service supports three agent types, which differ in how the agent's behaviour is defined and who runs its logic.

Prompt agents are defined declaratively by a model, instructions and tools, and the service runs them.

Workflow agents orchestrate several agents and steps in a defined sequence, with branches and approvals.

Hosted agents run the team's own agent code, for example code built with the Microsoft Agent Framework, in a container managed by the service.

The three types trade simplicity for control. A prompt agent needs no code of its own: its behaviour comes entirely from the model, the instructions and the tools, which the service runs, so it is the quickest to build and the natural first choice for a single assistant with tools. A workflow agent is chosen when the process has defined stages, branches or approvals that should not be left to the model's judgement, such as triage followed by a specialist and a review step. A hosted agent is chosen when the team needs custom logic that a declarative definition cannot express, or already has agent code written with a framework, and wants the service to run, scale and govern it.

All three are published and called in the same way, through the Responses API with an agent reference, so an application does not need to change if an agent later moves from one type to another.

The following diagram compares the three agent types.

Foundry Agent Service agent types from simplest to most control: a prompt agent is a model, instructions and tools run by the service; a workflow agent orchestrates agents and steps with branches and approvals; a hosted agent runs your own agent code in a container. All three are called through the Responses API with an agent reference.
The types trade simplicity for control, but all three are published and called the same way, so an agent can change type without changing the application.
Sort into groups

Which agent type?

Exam skills 2.2.1

Choose the Foundry agent type for each requirement.

Log in to try this activity Interactive activities are free with an account.

Writing instructions

Instructions are the agent's system prompt, and they are the main way to shape its behaviour. Because the model chooses its own steps, vague instructions produce inconsistent behaviour: an agent told only to "help customers with orders" may promise refunds it cannot give, answer questions outside its scope, or write long replies when short ones are wanted. Good instructions answer the questions the model would otherwise have to guess.

The role and audience set the perspective and vocabulary. The goals define what a successful interaction looks like, so the model knows when it has finished. Tool guidance explains when each tool applies and what to do when a tool fails, which reduces wrong tool choices. Boundaries state what the agent must decline, confirm or never reveal; they guide behaviour but are not a security control, so anything that must never happen is also enforced in tool code or by approvals. Output style fixes tone, length and citation format. The following list summarizes these elements with examples.

  • Role and audience: "You are Contoso's order support agent for retail customers."
  • Goals: what a successful interaction achieves, such as resolving the order question in as few turns as possible.
  • Tool guidance: when to use each tool, and what to do when a tool fails.
  • Boundaries: topics to decline, actions that need confirmation, information never to reveal.
  • Output style: tone, length, citation format, language.

The following code creates a prompt agent with the Foundry SDK. create_version() stores a new, immutable version of the agent named order-support, with the model deployment, the instructions and one function tool. The tool's description tells the model when to use it, and the strict schema constrains the arguments it may send.

from azure.ai.projects.models import PromptAgentDefinition, FunctionTool

order_status = FunctionTool(
    name="get_order_status",
    description="Return shipping status and expected delivery date for an order. Use when the customer asks where an order is.",
    parameters={"type": "object",
                "properties": {"order_number": {"type": "string", "description": "Format ORD-123456"}},
                "required": ["order_number"], "additionalProperties": False},
    strict=True,
)
agent = project.agents.create_version(
    agent_name="order-support",
    definition=PromptAgentDefinition(
        model="chat-primary",
        instructions=("You are Contoso's order support agent. Use get_order_status for order questions. "
                      "Never promise refunds; offer to escalate instead. Answer in at most three sentences."),
        tools=[order_status],
    ),
)

The following screenshot shows a prompt agent in the Foundry portal's agent playground: its model deployment, its instructions and an MCP tool on the left, and on the right an answer grounded in the tool's results, with the source cited.

Agent playground with instructions, a Microsoft Learn MCP tool and an answer that cites a Microsoft Learn page
The instructions state the agent's scope, which tools to use for which requests and what to do when the tools do not cover a question.
Sort into groups

Parts of good instructions

Exam skills 2.2.1

Sort each instruction into the element of agent instructions it covers.

Log in to try this activity Interactive activities are free with an account.

Conversations

Foundry Agent Service stores conversations. The application creates a conversation with openai.conversations.create() and passes its ID in every responses.create() call; the service appends the input, the agent's output and any tool calls and results, and manages the context sent to the model. This keeps requests small and lets a conversation continue across sessions or devices. Applications that cannot store state server-side can instead send the history themselves or chain responses by previous_response_id.

openai = project.get_openai_client(agent_name="order-support")   # client bound to the agent
conversation = openai.conversations.create()
r1 = openai.responses.create(conversation=conversation.id, input="Where is order ORD-104233?")
r2 = openai.responses.create(conversation=conversation.id, input="Can it be delivered to my office instead?")

Tool schemas

The model chooses tools from their names and descriptions and fills arguments from their schemas, so schemas are part of the prompt. Good schemas use specific names, descriptions that say when to use the tool and what it returns, typed parameters with descriptions, enums for fixed values, patterns for identifiers, required fields and additionalProperties: false with strict mode. Overlapping tools with vague descriptions are a common cause of wrong tool selection.

Scenario questions

Design tool schemas

Exam skills 2.2.1 · 2.2.3

Practise writing schemas that lead to correct tool calls.

Log in to try this activity Interactive activities are free with an account.
Worked example

Wrong tool choices

An agent has two tools, search ("Searches data") and lookup ("Looks up information"). Traces show it often uses search for order numbers, which fails, and lookup for policy questions.

The descriptions do not tell the model which tool fits which request. Rename and describe them precisely, for example search_policies ("Searches return, warranty and shipping policies; use for policy questions") and get_order_status with an order number pattern, add tool guidance to the instructions, and re-run the tool call accuracy evaluator.

Check yourself

How does an agent keep the history of a multi-turn conversation?

Show answer

The client passes the conversation ID on each call, and the service stores the history and tool results.

Exam Tips

Remember for the exam

  • Instructions: role, goals, tool guidance, boundaries and output style.
  • Pass the conversation ID on each call; the service stores history and tool results.
  • Precise tool names, descriptions and strict schemas are the main fix for wrong tool calls.