Skip to content
THE EXAMTOPICS EDITORIAL Explore practice exams

MICROSOFT

Microsoft AI-901: Build a Foundry Chat App and Agent

A beginner-friendly Microsoft AI-901 lab for deploying a model, calling the Foundry Python SDK, testing a single prompt agent and troubleshooting identities and responses.

Microsoft AI-901 preparation can benefit from a small, controlled exercise that follows a request from client to model deployment and back. The demonstration here introduces project setup, a chat request and an optional agent workflow, but these activities have not been independently mapped against every current official AI-901 task. Follow the study guide applicable to the date of your exam and validate the code against a pinned, permitted development environment before treating it as a working quickstart.

This walkthrough uses a limited, illustrative Foundry project configuration to contrast a direct model call with a simple agent. No code shown here was independently executed against a pinned SDK and tenant, and neither this lab nor the archived guide establishes complete current examination coverage.

Know what you’re building before opening the portal

A model deployment exposes the inference capability. A Foundry project organizes the resource access and interfaces the application uses. A chat client supplies instructions and a user message, sends the request, and processes the response. An agent adds a named definition—its model, instructions and optional tools—so requests can be sent through the agent rather than directly to a model. These components may work together, but they are not synonyms.

For a beginner scenario, imagine a help-desk assistant that explains a synthetic return policy. The direct chat model answers a short question. The prompt agent enforces an intended scope and preserves a conversation so the user can ask a follow-up. Neither has permission to issue refunds or read private customer records. That constraint is deliberate: it lets you understand the client and agent path before tackling tools that can alter state.

Microsoft distinguishes the Foundry project endpoint, which commonly follows https://<resource>.services.ai.azure.com/api/projects/<project>, from OpenAI-compatible and specialized Foundry Tools endpoints. This example assumes a Foundry SDK 2.x client with a matching project API; that compatibility must be checked against the installed versions and endpoint before use. Examples written for the classic Azure AI Projects 1.x SDK may use different shapes. Mixing a classic endpoint with new-client code is a source of avoidable errors, not a useful exam trick.

This lab needs only a deployed model and a narrowly scoped agent. Adding speech, vision and extraction tools at this stage would obscure the distinction between a direct model call and an agent workflow.

Prepare a project, model and approved identity

You need an Azure subscription, a Foundry project and access to a supported model deployed for that project. The account performing day-to-day development should have a Foundry role appropriate for the operation; creating resources or granting permissions can require different administrative rights. Use an authorized subscription and check whether your intended model and region are available. Models, quotas and service costs can vary. A tutorial that selects a model by name cannot guarantee it is deployed in your project.

Open the current Foundry portal and confirm the project endpoint shown for the intended project. Create a supported chat-capable model deployment, record its exact deployment name and test a harmless prompt in the portal. If the portal call fails, debug it there before introducing Python. A working portal request establishes that at least one identity and deployment path function, but it does not prove that a separate script has equivalent permissions.

For the current Microsoft Foundry project API, create a virtual environment and install azure-ai-projects>=2.3.0 with Azure Identity, as illustrated in Microsoft’s new Foundry prompt-agent quickstart. Package and method names can change, and a classic-project sample is not interchangeable with the newer project endpoint API. Verify the actual Python runtime and SDK version, sign in with an authorized user identity and choose a deployed model that your project can access before copying the code below.

Environment note: The setup commands below have not been executed in a fresh environment for a pinned Python and azure-ai-projects dependency set. Verify interpreter compatibility, package versions, sign-in permissions and resource charges in an approved sandbox before using them; the commands are illustrative rather than an independently tested installation procedure.

python -m venv .venv
# Activate the environment using your operating system's command
pip install "azure-ai-projects>=2.3.0" azure-identity
az login

Set environment variables for the project endpoint and model deployment. A name such as AZURE_AI_PROJECT_ENDPOINT is simply a local variable convention in this example; it is not the name of a required Azure configuration object. A developer might use an IDE run configuration or local environment file for these non-secret values. Secrets and credential configuration belong in approved environment or identity tooling and must never be published.

Set the two environment variables in the same shell or IDE run configuration that launches Python; defining them in another terminal does not make them visible to the process. For a POSIX shell, an illustrative setup is shown below. Use the exact endpoint and model deployment name shown in your own approved Foundry project, and never paste access tokens into a script or a blog post.

export AZURE_AI_PROJECT_ENDPOINT="https://YOUR_RESOURCE.services.ai.azure.com/api/projects/YOUR_PROJECT"
export AZURE_MODEL_DEPLOYMENT="YOUR_DEPLOYED_MODEL_NAME"
python your_client.py

On Windows PowerShell the corresponding variables use $env:AZURE_AI_PROJECT_ENDPOINT and $env:AZURE_MODEL_DEPLOYMENT. The client still needs successful Azure identity authentication and the necessary project role. This article does not claim the command has been executed against your subscription.

Call a deployed model from a minimal chat client

The first application should do only three things: authenticate, make a short model request and display the output. In the Foundry SDK 2.x, AIProjectClient connects to the project endpoint with DefaultAzureCredential. The project client can provide the OpenAI-compatible interface used by the Responses API. Use the deployment name actually created in the project, not a model label copied from a tutorial screenshot.

import os
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential


project = AIProjectClient(
    endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
)
client = project.get_openai_client()


response = client.responses.create(
    model=os.environ["AZURE_MODEL_DEPLOYMENT"],
    input=[
        {"role": "system", "content": "Explain a fictitious store policy clearly. Ask when facts are missing."},
        {"role": "user", "content": "Can a customer return an unused item after 14 days?"},
    ],
)
print(response.output_text)

The client code is an unexecuted illustrative example that follows Microsoft’s documented Foundry project-client and Responses API approach. It has not been run against a tenant here. If it fails, record the installed package version, project endpoint, Entra role, deployment name, request identifier and error category before modifying the prompt. Never interpret sample text in this article as evidence that a model was actually called or that a response met a business requirement.

Next, provide a short, fictional policy as part of the prompt and repeat the question. Does the response rely on the supplied evidence or invent extra conditions? What if the policy says returns are allowed within 14 days except for final-sale items? Try a final-sale example and check whether the exception survives summarization. These are better learning tests than getting one reassuring answer in the chat window.

Keep the prompt and output in a local test record, but avoid logging production personal data. If you change a model setting, note which setting and why. The prompting and grounding concepts become much clearer when you can compare a response with and without relevant evidence.

Create a single prompt agent and test it

A prompt agent is a defined assistant with instructions and a model that can be reused through an endpoint. For AI-901, keep the purpose small. Create an agent whose job is to answer only questions about a fictitious store policy, request clarification if important facts are absent and avoid inventing a refund decision. In the Foundry portal, inspect the definition and try both an in-scope and an out-of-scope request. The goal is not to build an entire customer-service department.

Microsoft’s new Foundry prompt-agent quickstart uses PromptAgentDefinition with a versioned agent; verify these calls against the installed package and actual project API before attempting the lab. Versioning is important: changing an agent’s instructions can change its behavior even if the underlying model is unchanged. The following code expresses the concept using the same project client. Run it only in a project where the signed-in identity is permitted to create an agent; repeated runs can create new versions, so treat this as a controlled lab action.

import os
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import PromptAgentDefinition
from azure.identity import DefaultAzureCredential


project = AIProjectClient(
    endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
    credential=DefaultAzureCredential(),
)
agent_name = "ai901-policy-assistant"


agent = project.agents.create_version(
    agent_name=agent_name,
    definition=PromptAgentDefinition(
        model=os.environ["AZURE_MODEL_DEPLOYMENT"],
        instructions="Explain only the supplied fictitious policy. Ask when evidence is missing.",
    ),
)
print(agent.name, agent.version)

Notice what is not present: an unrestricted database connection, refund action or tool allowed to write to external systems. The agent can be useful without any such capability. Understanding why a narrow role is safer is an important bridge between the agentic AI concepts and a real implementation.

Connect an application to the agent

After creating the agent, send a message through an agent-scoped client. Microsoft’s Foundry SDK can supply an OpenAI-compatible client bound to the agent name. A conversation object maintains context across turns. Ask one question, then a follow-up that refers to the first answer, and inspect whether the agent maintains the intended thread. This is more informative than invoking unrelated single prompts and assuming they share state.

agent_client = project.get_openai_client(agent_name=agent_name)
conversation = agent_client.conversations.create()


first = agent_client.responses.create(
    conversation=conversation.id,
    input="What information do you need to check a return?",
)
print(first.output_text)


follow_up = agent_client.responses.create(
    conversation=conversation.id,
    input="And if the item is final sale?",
)
print(follow_up.output_text)

The client reuses the project object and agent name from the preceding example. The method names are illustrative and may differ between installed Foundry SDK and service API revisions; verify them in a version-pinned test environment before relying on the example. Do not assume the agent has a secret policy document merely because it is named “policy assistant.” You must supply or connect approved evidence. Agent instructions specify desired behavior, not data access or real-world authority.

Examine the follow-up’s relevance. If it loses the earlier topic, check conversation identity. If it invents a condition, examine grounding and instructions. If it fails to execute, distinguish model or agent deployment issues from identity and endpoint failures. A well-controlled lab is one in which you can name the layer responsible for each kind of result.

Troubleshoot the usual Foundry client failures

Observed issue Likely place to investigate First useful check
Authentication or authorization fails Microsoft Entra sign-in, project role or scope Which identity does the script use, and can it access this project?
Deployment not found Project, deployment name or model availability Does the exact deployment exist in the endpoint’s project?
Unexpected endpoint or API error Classic versus current project endpoint, SDK version Does the code match Foundry Projects 2.x and the copied endpoint?
Agent responds outside its task Agent instructions and missing grounding What instructions and evidence did the agent actually receive?
Follow-up ignores conversation history Conversation state or request parameters Are both turns using the same conversation ID?
Response is fluent but wrong Model choice, prompt, retrieved context or validation Can the answer be checked against an approved source?

These checks also teach an operational lesson: a model error is not always a model-quality error. A permissions problem cannot be fixed by increasing a token limit. A missing model deployment cannot be fixed by rewriting a system prompt. A correct network response can still contain wrong content. Debugging succeeds when you identify whether the failure is in the identity, service, data, orchestration or validation layer.

Use only the complexity the requirement justifies. A second agent does not make a simple task more correct; it creates another set of state, permissions and failure cases. A tool that can modify records should have independent authorization and idempotent recovery. For this AI-901 exercise, a simple prompt agent and conversation are sufficient to understand the relevant implementation objective.

Turn the lab into AI-901 exam reasoning

When an exam scenario describes a company that needs a simple model-backed chat experience, start with a supported Foundry deployment and a lightweight client. If the scenario mentions an agent that must preserve context and potentially use tools, think agent definition, conversation and controlled tool boundary. If a question describes a prompt that ignores company policy, ask whether the failure lies in instruction wording, missing approved context or an access rule that should be enforced outside the model.

A good self-test is to narrate a request from start to finish: the caller authenticates, the client targets a project and deployment or an agent, the application sends a system/user message, the service returns output, and the application validates or displays it. For the agent case, explain how conversation state and instructions modify the path. Name the logs and versions you would preserve to reproduce a bad answer.

Keep an explicit test matrix for the agent. One case should ask a question answered by the synthetic policy, another should ask for a refund action the agent is not authorized to perform, and a third should reference a policy exception that is deliberately absent. A safe implementation should give the known answer with evidence, refuse or hand off the write action, and ask for missing information rather than inventing it. An apparently fluent answer is not a substitute for these acceptance criteria, and the outcomes here remain proposed until someone executes and records the experiment.

Also know where this lab stops. It does not teach speech recognition, visual input or structured extraction in detail. Those have their own Foundry Tools or multimodal requirements in the current AI-901 syllabus. Use a second narrow exercise for those rather than expanding this chat agent into an untestable all-purpose application. The technical objective is controlled fluency with one model and one agent, not maximum infrastructure.

Before you consider this lab complete, deliberately trigger a wrong deployment-name error, test an out-of-scope prompt and check a policy answer against source facts. If you can explain the first as configuration, the second as an instruction/authorization issue and the third as an evidence-validation task, you are practicing the reasoning Microsoft expects from a beginning AI solution developer.

Continue exploring the technologies and certification concepts that matter most to you.