Documentation Index Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/azure-ai-docs/llms.txt
Use this file to discover all available pages before exploring further.
Microsoft Foundry Quickstart
This quickstart will help you get started with Microsoft Foundry by creating a project, deploying a model, running chat completions, and creating an agent with file search capabilities.
Prerequisites
An Azure subscription (Create one for free )
Azure CLI installed and authenticated
Python 3.8 or later (for Python examples)
Step 1: Create a Foundry Project
A Foundry project is where you do most of your development work. Projects provide isolation for agents, models, and data.
Create a Foundry resource and project
You can create resources using the Azure portal or deploy using Azure CLI with Bicep templates. For a basic setup: # Deploy basic agent setup
az deployment group create \
--resource-group < your-resource-grou p > \
--template-uri https://raw.githubusercontent.com/azure-ai-foundry/foundry-samples/main/infrastructure/infrastructure-setup-bicep/40-basic-agent-setup/azuredeploy.json
This creates:
Foundry account
Foundry project
GPT-4.1 model deployment
Get your project endpoint
After deployment, navigate to your project in the Azure portal and copy the endpoint URL: https://<resource-name>.services.ai.azure.com/api/projects/<project-name>
Step 2: Install the SDK
pip install openai azure-identity azure-ai-projects== 1.0.0
Step 3: Chat with a Model
Create your first chat completion using a deployed model.
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
# Initialize project client
project = AIProjectClient(
endpoint = "https://<resource-name>.services.ai.azure.com/api/projects/<project-name>" ,
credential = DefaultAzureCredential(),
)
# Get OpenAI client
models = project.get_openai_client( api_version = "2024-10-21" )
# Create chat completion
response = models.chat.completions.create(
model = "gpt-4o" ,
messages = [
{ "role" : "system" , "content" : "You are a helpful assistant" },
{ "role" : "user" , "content" : "What is the size of France in square miles?" },
],
)
print (response.choices[ 0 ].message.content)
Step 4: Create an Agent
Create an intelligent agent that can assist with tasks.
from azure.ai.projects import AIProjectClient
from azure.identity import DefaultAzureCredential
import os
import time
# Initialize client
project = AIProjectClient(
endpoint = os.environ[ "PROJECT_ENDPOINT" ],
credential = DefaultAzureCredential(),
)
# Create agent
agent = project.agents.create_agent(
model = os.environ[ "MODEL_DEPLOYMENT_NAME" ],
name = "my-agent" ,
instructions = "You are a helpful assistant" ,
)
print ( f "Created agent, ID: { agent.id } " )
# Create thread
thread = project.agents.threads.create()
print ( f "Created thread, ID: { thread.id } " )
# Send message
message = project.agents.messages.create(
thread_id = thread.id,
role = "user" ,
content = "Hello, what can you help me with?" ,
)
# Run agent
run = project.agents.runs.create( thread_id = thread.id, agent_id = agent.id)
# Wait for completion
while run.status in [ "queued" , "in_progress" ]:
time.sleep( 1 )
run = project.agents.runs.get( thread_id = thread.id, run_id = run.id)
print ( f "Run completed with status: { run.status } " )
# Get messages
messages = project.agents.messages.list( thread_id = thread.id)
for msg in messages:
print ( f " { msg[ 'role' ] } : { msg[ 'content' ] } " )
# Cleanup
project.agents.delete_agent(agent.id)
Step 5: Add File Search to Your Agent
Enhance your agent with knowledge retrieval capabilities.
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import FileSearchTool, FilePurpose
from azure.identity import DefaultAzureCredential
import os
project = AIProjectClient(
endpoint = os.environ[ "PROJECT_ENDPOINT" ],
credential = DefaultAzureCredential(),
)
# Upload file
file = project.agents.files.upload_and_poll(
file_path = "product_info_1.md" ,
purpose = FilePurpose. AGENTS
)
print ( f "Uploaded file, file ID: { file .id } " )
# Create file search tool with file
file_search_tool = FileSearchTool( file_ids = [ file .id])
# Create agent with file search
agent = project.agents.create_agent(
model = os.environ[ "MODEL_DEPLOYMENT_NAME" ],
name = "file-search-agent" ,
instructions = "You are a helpful assistant that can search information from uploaded files." ,
tools = file_search_tool.definitions,
tool_resources = file_search_tool.resources,
)
print ( f "Created agent with file search, agent ID: { agent.id } " )
# Create thread and ask question
thread = project.agents.threads.create()
message = project.agents.messages.create(
thread_id = thread.id,
role = "user" ,
content = "What products does Contoso offer?" ,
)
# Run and wait for completion
run = project.agents.runs.create_and_poll(
thread_id = thread.id,
agent_id = agent.id
)
if run.status == "completed" :
messages = project.agents.messages.list( thread_id = thread.id)
for msg in messages:
print ( f " { msg[ 'role' ] } : { msg[ 'content' ] } " )
# Cleanup
project.agents.delete_agent(agent.id)
project.agents.files.delete( file .id)
Next Steps
Now that you’ve created your first agent with file search, explore more capabilities:
Agent Overview Learn about Foundry Agent Service capabilities
Environment Setup Configure your agent environment
Agent Tools Explore built-in tools for agents
SDK Overview Deep dive into the Foundry SDK
Clean Up Resources
To avoid incurring charges, delete the resources you created:
az group delete --name < your-resource-grou p > --yes --no-wait