
How-Tos
How to create a first Microsoft Agent Framework agent
Install Microsoft Agent Framework's Foundry package, sign in with the Azure CLI, and run the documented first agent against a Foundry project endpoint.
Searcher → Analyst → Writer → Editor · subagentic-20261016-0800
Microsoft's get-started path for Agent Framework starts with a short program: create an agent, send it one prompt, and print the reply. The Step 1 page calls that exercise "Create an agent and get a response — in just a few lines of code." Later steps add tools, sessions, memory, workflows, a harness, and hosting. This walkthrough follows the Python Foundry sample on that page. The C# and Go tabs are documented alternatives, not a second path you have to finish first.
The index page describes the tutorial as building an AI agent from scratch, one concept at a time. Its table says Step 1 is to create an agent, invoke it, and stream the response. The Python block shows the invoke half: one run that prints a reply. Streaming appears on the C# and Go listings, not in the Python example.
What the sample expects
The Python example does not create a Foundry project for you. The step page says to replace project_endpoint with your Microsoft Foundry project endpoint and model with your model deployment name. Without those two values, the listing has only placeholders.
You also sign in before you run it. The page says to sign in with the Azure CLI by running az login. The sample then supplies an Azure CLI credential to the Foundry client, which is why that sign-in step comes first. The C# and Go listings construct a different credential, covered below only as the other tabs.
Install the Foundry package
Install the two packages named on the Python tab:
pip install agent-framework-foundry azure-identity
The step page says what that first package does: agent-framework-foundry installs agent-framework-core with the Microsoft Foundry integration. It also notes that the agent-framework metapackage installs agent-framework-core, together with many other optional integrations. The documented first-agent install is the Foundry package plus the identity package named in that command, not the metapackage.
Save the documented agent
Save the complete example as hello_agent.py. This is the listing on the page:
import asyncio
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
async def main() -> None:
agent = Agent(
client=FoundryChatClient(
project_endpoint="https://your-account.services.ai.azure.com/api/projects/your-project",
model="gpt-6-luna",
credential=AzureCliCredential(),
),
instructions="You are a friendly assistant. Keep your answers brief.",
)
print(await agent.run("What is the largest city of France?"))
if __name__ == "__main__":
asyncio.run(main())
Treat the file as a template. The client in the listing takes a project endpoint, a model, and a credential. The endpoint string is the placeholder the page printed. Replace it with your Microsoft Foundry project endpoint. Replace the model with your model deployment name. The model string in the listing is what the page printed; the same paragraph tells you to substitute your deployment name, so do not leave that sample value in place unless it is actually your deployment.
The agent is built with that client and one instructions string: a friendly assistant that keeps answers brief. The listing prints the result of a single run. The Python prompt asks what the largest city of France is. The C# and Go listings ask for the largest city in France. Keep the wording of the listing you run.
The step page also points to a full runnable sample for the complete file. The block above is the complete example it tells you to save as hello_agent.py.
Run it
After az login, and after the endpoint and model in the file are yours, run:
python hello_agent.py
That is the whole Python run step on the page. There is no extra flag in the documented command.
.env files are not loaded for you
Agent Framework does not automatically load .env files. If you want one, the page says to call load_dotenv() at the start of your script:
from dotenv import load_dotenv
load_dotenv()
That call is not part of the hello-agent listing. The documented alternative is to set environment variables directly in your shell or IDE. The page points to a settings migration note for details. The first sample does not need that note if you pass the endpoint and model in code, as the listing does. The page does not show a separate install command for that import, so do not invent one; use the call only if that import is already available in your environment.
C# and Go, as the other tabs
The same Step 1 page documents C# and Go. They are alternatives to the Python path.
For .NET, the install command is:
dotnet add package Microsoft.Agents.AI.Foundry --prerelease
The C# listing builds an agent from a Foundry project client. It reads an endpoint from the environment and throws if that variable is missing, with a message that tells you to set it. It reads a deployment name from the environment, and if that variable is absent it uses the fallback deployment name written in the listing. The agent name in that listing is HelloAgent, with the same brief-assistant instructions. The listing shows a one-shot run and a streaming loop. The credential is the default Azure credential, not the Azure CLI credential used by the Python sample.
The page warns that DefaultAzureCredential is convenient for development but requires careful consideration in production. In production, it says to consider a specific credential such as ManagedIdentityCredential, to avoid latency issues, unintended credential probing, and potential security risks from fallback mechanisms.
For Go, the install command is:
go get github.com/microsoft/agent-framework-go
The Go listing reads a project endpoint and a model from the environment, builds a token with the default Azure credential, and constructs the agent with the same brief-assistant instructions and the name HelloAgent. It can print a gathered text reply or stream updates. The page gives the same kind of warning: azidentity.NewDefaultAzureCredential is convenient for development, and in production it suggests a specific credential such as azidentity.NewManagedIdentityCredential.
The get-started index adds a Go limit that does not apply to the Python sample: Agent Framework for Go is in public preview. Declarative agents, RAG, CodeAct, and functional workflows are not yet available. The index says to file issues on GitHub.
Where Step 1 stops
This exercise stops at one agent and one prompt. It does not add a function tool, keep a session, or host the agent. The index lists the rest of the tutorial in order, each step building on the previous one:
- Give the agent a function tool it can call.
- Maintain conversation state with sessions.
- Inject persistent context via context providers.
- Compose a multi-step workflow.
- Create a harness agent that plans and tracks multi-step tasks.
- Expose the agent via hosting infrastructure.
When python hello_agent.py prints a reply from your own project endpoint and model deployment, continue with Step 2: Add Tools, on the same get-started path. If it does not get that far, replace the placeholder endpoint and model, run az login, and try the same file again before changing the agent code.