Build Custom AI Agents with Azure AI Foundry
Back to Tutorials
Azure AIIntermediate5 Steps

Build Custom AI Agents with Azure AI Foundry

Microsoft LearnDecember 1, 202535 min watch35 min video

Deep dive into building custom AI agents using Azure AI Foundry Agent Service. Learn how to ground agents with your data, add tools, and deploy production-ready agents.

Building AI Agents with Azure AI Foundry

Azure AI Foundry Agent Service allows you to build autonomous AI agents that can reason, plan, and execute multi-step tasks using tools, functions, and grounded data.

What Makes an AI Agent Different from a Chatbot?

Feature Chatbot AI Agent
Conversation Responds to prompts Plans and executes autonomously
Tools None Code interpreter, file search, custom functions
Memory Session-based Persistent threads with history
Data Static training data Grounded with your real-time data

Prerequisites

  • Azure AI Foundry project (see the Getting Started tutorial)
  • An Azure OpenAI GPT-4o deployment
  • (Optional) Azure AI Search for grounding

Step 1: Create an Agent

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

# Connect to your project
client = AIProjectClient.from_connection_string(
    conn_str="your-connection-string",
    credential=DefaultAzureCredential()
)

# Create an agent
agent = client.agents.create_agent(
    model="gpt-4o",
    name="my-research-agent",
    instructions="""You are a helpful research agent.
    Use your tools to find information and provide accurate,
    well-cited answers."""
)

Step 2: Add Tools

Code Interpreter

Lets the agent write and execute Python code for data analysis, chart generation, and calculations.

from azure.ai.projects.models import CodeInterpreterTool

agent = client.agents.create_agent(
    model="gpt-4o",
    name="data-analyst-agent",
    instructions="Analyze data using code interpreter.",
    tools=[CodeInterpreterTool()]
)

File Search (RAG)

Connects the agent to your documents via Azure AI Search.

from azure.ai.projects.models import FileSearchTool

agent = client.agents.create_agent(
    model="gpt-4o",
    name="knowledge-agent",
    instructions="Answer questions based on the provided documents.",
    tools=[FileSearchTool(vector_store_ids=["vs_abc123"])]
)

Custom Functions

Define your own functions that the agent can call.

from azure.ai.projects.models import FunctionTool

tools = FunctionTool(functions=[{
    "name": "get_weather",
    "description": "Get current weather for a location",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "City name"}
        },
        "required": ["location"]
    }
}])

Step 3: Create a Thread and Run

# Create a conversation thread
thread = client.agents.create_thread()

# Add a user message
client.agents.create_message(
    thread_id=thread.id,
    role="user",
    content="Analyze the Q4 sales data and create a summary chart."
)

# Run the agent
run = client.agents.create_and_process_run(
    thread_id=thread.id,
    assistant_id=agent.id
)

# Get the response
messages = client.agents.list_messages(thread_id=thread.id)
print(messages.data[0].content[0].text.value)

Step 4: Deploy to Production

  1. Test thoroughly in the Foundry playground
  2. Set up content filters and safety guardrails
  3. Deploy as an API endpoint
  4. Monitor with Azure Monitor and Application Insights

Resources

Video: Find the official walkthrough on Microsoft Developer YouTube — search for "Azure AI Agent Service"

AI AgentsAzure AI FoundryAzure AI SearchRAGAzure

Share this tutorial

Chapters (5)

  1. 1

    What are AI Agents?

    Understanding autonomous AI agents and their architecture

    00:00
  2. 2

    Creating an Agent in Foundry

    Set up your first agent with instructions and model selection

    06:00
  3. 3

    Grounding with Your Data

    Connect agents to Azure AI Search and custom data sources

    14:30
  4. 4

    Adding Tools & Functions

    Extend agent capabilities with code interpreter and custom functions

    22:00
  5. 5

    Testing & Deployment

    Test agent behavior and deploy to production

    30:00

About the Author

KH

Microsoft Learn

Microsoft MVP | AI Engineer

Software & AI Engineer specializing in Microsoft Azure, .NET, and cutting-edge AI technologies.

Need help with your project?

Let's discuss how I can help bring your ideas to life.

Get In Touch