| title | Step 1: Your First Agent |
|---|---|
| description | Create and run your first AI agent with Agent Framework in under 5 minutes. |
| zone_pivot_groups | programming-languages |
| author | eavanvalkenburg |
| ms.topic | tutorial |
| ms.author | edvan |
| ms.date | 02/09/2026 |
| ms.service | agent-framework |
Create an agent and get a response — in just a few lines of code.
:::zone pivot="programming-language-csharp"
dotnet add package Azure.AI.Projects --prerelease
dotnet add package Azure.Identity
dotnet add package Microsoft.Agents.AI.Foundry --prerelease
Create the agent:
using System;
using Azure.AI.Projects;
using Azure.Identity;
using Microsoft.Agents.AI;
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
?? throw new InvalidOperationException("Set AZURE_OPENAI_ENDPOINT");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
AIAgent agent = new AIProjectClient(new Uri(endpoint), new DefaultAzureCredential())
.AsAIAgent(
model: deploymentName,
instructions: "You are a friendly assistant. Keep your answers brief.",
name: "HelloAgent");Warning
DefaultAzureCredential is convenient for development but requires careful consideration in production. In production, consider using a specific credential (e.g., ManagedIdentityCredential) to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
Run it:
Console.WriteLine(await agent.RunAsync("What is the largest city in France?"));Or stream the response:
await foreach (var update in agent.RunStreamingAsync("Tell me a one-sentence fun fact."))
{
Console.Write(update);
}Tip
See here for a full runnable sample application.
:::zone-end
:::zone pivot="programming-language-python"
pip install agent-frameworkCreate and run an agent:
:::code language="python" source="~/../agent-framework-code/python/samples/01-get-started/01_hello_agent.py" id="create_agent" highlight="8-11":::
:::code language="python" source="~/../agent-framework-code/python/samples/01-get-started/01_hello_agent.py" id="run_agent" highlight="2":::
Or stream the response:
:::code language="python" source="~/../agent-framework-code/python/samples/01-get-started/01_hello_agent.py" id="run_agent_streaming" highlight="3-5":::
Note
Agent Framework does not automatically load .env files. To use a .env file for configuration, call load_dotenv() at the start of your script:
from dotenv import load_dotenv
load_dotenv()Alternatively, set environment variables directly in your shell or IDE. See the settings migration note for details.
Tip
See the full sample for the complete runnable file.
:::zone-end
[!div class="nextstepaction"] Step 2: Add Tools
Go deeper:
- Agents overview — understand agent architecture
- Providers — see all supported providers