Hello Agent

The smallest possible Python agent: a Foundry chat client plus instructions, run once collected and once streamed.

Part 1 of 72 Microsoft Agent Framework Python — Every Lesson

What this lesson demonstrates

This is the Agent primitive stripped to essentials. You wire a FoundryChatClient to a deployed model, hand it an instruction string and a name, and call it with a message. That single loop is what tools, memory, and workflows all build on. The lesson runs the same agent two ways: agent.run(...) collects the whole answer, and stream=True yields chunks as they arrive.

The code

Construction is factored out of main so it can be built and tested on its own:

client = FoundryChatClient(
    project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
    model=os.environ["FOUNDRY_MODEL"],
    credential=AzureCliCredential(),
)
instructions = (
    "You are a terse, knowledgeable travel guide. "
    "Answer in at most two sentences and never use bullet points."
)
return Agent(client=client, name="HelloAgent", instructions=instructions)

Then main runs it two ways off the same object:

result = await agent.run("What is the capital of France?")
async for chunk in agent.run("Tell me a fun fact.", stream=True):
    if chunk.text:
        print(chunk.text, end="", flush=True)

What to notice

How it maps to Azure AI Foundry

FoundryChatClient binds the agent to your Foundry project endpoint, keyed by the deployed model name. AzureCliCredential reuses the token from az login, so there are no secrets in code. instructions is the system prompt; name is how the agent identifies itself.

Run it

uv run tutorial/01-get-started/01_hello_agent.py

Expected: a non-streaming answer, then the same agent streaming a second reply. The live call needs Foundry creds and az login.


Next: Add Tools

Sources & References

The Python SDK this lesson exercises
Building a basic agent from a chat client and instructions