Generative AI apps and agents in Foundry
Write effective prompts, deploy and test a model in the Foundry portal, build a small chat client with the Foundry SDK, and create and call a single agent.
In this lesson you'll learn
- System prompts, user prompts and prompt techniques
- Deploying a model and testing it in the playground
- A lightweight chat client with the Foundry SDK
- Creating a prompt agent, adding tools and calling it from code
1. Writing effective prompts
New to prompts? Start here
A system prompt (also called instructions) sets the model's role, rules and tone for the whole conversation, for example "You are a polite IT help-desk assistant. Only answer questions about company laptops." A user prompt is what the user asks each time.
- Be specific: say who the audience is, the format you want and the length.
- Give examples (few-shot): show one or two examples of the input and the exact output you want.
- Ground the answer: include the relevant facts or documents, and tell the model to answer only from them.
- Set boundaries: say what to do when the answer isn't known, for example "Say you don't know."
- Ask for structure: for example, "Reply in JSON with fields name and priority."
Example: improving a prompt
- Weak: "Write about our return policy."
- Better system prompt: "You are a customer service assistant for SS Kaiser. Answer only from the policy text provided. If the answer isn't in it, say so. Use a friendly tone and at most 3 sentences."
- User prompt: "Can I return shoes after 40 days?" plus the policy text as grounding data.
2. Deploying and testing a model in the Foundry portal
- Create a Foundry resource and a project (the project is your workspace).
- Choose a model in the model catalog and deploy it, choosing a deployment type such as Global Standard.
- Open the playground, write a system prompt, adjust settings such as temperature, and chat to test it.
- Use evaluations to check quality and safety before moving to code.
3. A lightweight chat client with the Foundry SDK
The Python package azure-ai-projects connects to your project endpoint. Authentication uses Microsoft Entra ID through DefaultAzureCredential, so there are no keys in code.
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
project = AIProjectClient(
endpoint="https://my-resource.services.ai.azure.com/api/projects/my-project",
credential=DefaultAzureCredential())
client = project.get_openai_client() # OpenAI-compatible client for the project
reply = client.responses.create(
model="my-chat-deployment", # the deployment name
instructions="You are a concise travel assistant.",
input="Suggest three things to do in Lisbon.")
print(reply.output_text)
For a multi-turn chat, keep the conversation going: create a conversation and pass its ID with each request, so the model sees earlier messages.
4. Creating and calling a single agent
A prompt agent combines a model, instructions and optional tools. Foundry hosts it, so there's no infrastructure to manage. Build it in the portal (Agents, then Create agent) or in code, test it in the agent playground, then call it from an app.
| Tool | Lets the agent... |
|---|---|
| File search | Answer from documents you upload |
| Azure AI Search | Answer from an existing search index |
| Web search | Use current information from the web |
| Code interpreter | Run Python to calculate, analyse data or create charts |
| Functions, OpenAPI tools and MCP servers | Call your own APIs and systems to take actions |
from azure.ai.projects.models import PromptAgentDefinition
project.agents.create_version(
agent_name="hr-helper",
definition=PromptAgentDefinition(
model="my-chat-deployment",
instructions="Answer HR policy questions politely. Say when you don't know."))
agent_client = project.get_openai_client(agent_name="hr-helper")
conversation = agent_client.conversations.create()
answer = agent_client.responses.create(
conversation=conversation.id,
input="How many days of annual leave do I get?")
print(answer.output_text)
Example
An HR team uploads its policy PDFs and creates an agent with the file search tool and instructions to answer only from the policies. After testing it in the agent playground, a developer adds it to the intranet with a few lines of SDK code, keeping one conversation per employee chat.
Exam traps to remember
- The system prompt sets behaviour for the whole conversation, and the user prompt is each request.
- Answers from your own documents need grounding (for example the file search tool or RAG), not a higher temperature.
- Agents need tools to take actions. Instructions alone only shape the text.
- Use DefaultAzureCredential (Entra ID) rather than hard-coding keys.
Test yourself: 3 check questions and exam-style practice questions on this topic are in the AI-901 Azure AI Fundamentals app.
Practise in the app