Creating Your First Agent — Building AI Agents
[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
Creating Your First Agent
Building an Agent in 5 Minutes
Via the Foundry Portal
- Navigate to Agents in your project sidebar
- Click + New Agent
- Select a deployed model (e.g., gpt-4o)
- Write system instructions defining the agent's role
- Add tools (code interpreter, file search, custom functions)
- Test in the Agent Playground
Via the SDK (Python)
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import PromptAgentDefinition, CodeInterpreterTool, MCPTool
from azure.identity import DefaultAzureCredential
with AIProjectClient(
endpoint="https://<foundry-name>.services.ai.azure.com/api/projects/<project>",
credential=DefaultAzureCredential()
) as project:
# 1. Create a versioned agent in Foundry Agent Service (v2 SDK)
agent = project.agents.create_version(
agent_name="ResearchAssistant",
definition=PromptAgentDefinition(
model="gpt-6.1-sol",
instructions="You are a research assistant. Analyze data and cite sources clearly.",
tools=[
CodeInterpreterTool(),
MCPTool(server_label="docs-mcp", server_url="https://learn.microsoft.com/api/mcp")
],
),
)
# 2. Run a stateful Conversation via the OpenAI Responses API
with project.get_openai_client() as openai_client:
conversation = openai_client.conversations.create()
response = openai_client.responses.create(
conversation=conversation.id,
extra_body={"agent": {"name": agent.name, "type": "agent_reference"}},
input="Analyze the latest trends in renewable energy",
)
print(response.output_text)
🎯 Pro Tip: Write agent instructions as if briefing a new employee. Be specific about what the agent should and should NOT do, what tone to use, and how to handle edge cases.
⌨ HANDS-ON LABCreate Foundry Agent with Code Interpreter Tool
⭐ +200 XPUse Python azure-ai-projects SDK to declare a new autonomous agent equipped with sandboxed Python code interpreter.
1Execute Python code declaring an agent with instructions and the code_interpreter tool definition.
OBJECTIVE 1 / 1 — type "hint" if stuck
FOUNDRY VERIFICATION
QUERY 1 // 1
What is the recommended approach for writing agent instructions?
Keep them as short as possible
Write them like briefing a new employee - specific about role, boundaries, and edge cases
Copy from documentation
Leave them empty and rely on the model