What an agent is made of
An Agent is a thin, composable object. Only client is required — everything else is optional and additive.
client
Model provider connection
instructions
Role, rules, format
tools
Functions & MCP servers
session
Conversation state
context_providers
Memory & knowledge
middleware
Guardrails, logging
Set up in 90 seconds
1python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate2pip install -r requirements.txt # agent-framework-core, -openai, -orchestrations, pandas …3cp .env.example .env # then paste your GROQ_API_KEY4python ex1_first_agent.py
Google Colab? !pip install agent-framework-core agent-framework-openai and use await main() directly — notebooks already run an event loop.
All labs share one helper, common.make_client(), so changing provider is a one-file change.
1import os2from agent_framework.openai import OpenAIChatCompletionClient34def make_client() -> OpenAIChatCompletionClient:5 return OpenAIChatCompletionClient(6 model=os.getenv("GROQ_MODEL", "llama-3.3-70b-versatile"),7 api_key=os.environ["GROQ_API_KEY"],8 base_url="https://api.groq.com/openai/v1",9 )
Pick a provider — keep the agent
Every provider package exposes a chat client with the same interface. Groq, Ollama, LM Studio and vLLM speak the OpenAI Chat Completions protocol, so OpenAIChatCompletionClient + base_url covers them.
⚠️ In v1.x, OpenAIChatClient targets OpenAI's Responses API. For Groq use OpenAIChatCompletionClient.
Groq
This workshop · BYOKOpenAIChatCompletionClient + base_url
Azure OpenAI
EnterpriseOpenAIChatCompletionClient(azure_endpoint=…)
Microsoft Foundry
Hosted agentsagent_framework.foundry
OpenAI
OpenAIChatClient (Responses)
Anthropic
agent_framework.anthropic
Ollama / local
Offlineagent_framework.ollama
Gemini
agent_framework.gemini
Amazon Bedrock
agent_framework.amazon
Instructions, options & the as_agent shortcut
Good instructions = role + rules + output format + what to do when unsure. Model options such as temperature and max_tokens go in default_options (per-agent) or options= on a single run().
1agent = client.as_agent(2 name="OpsBot",3 instructions="""You are OpsBot, a business operations analyst.4- Be concise and use bullet points.5- State assumptions explicitly. If unsure, say so.""",6 default_options={"temperature": 0.2, "max_tokens": 400},7)
What happens inside agent.run()
run() returns an AgentResponse (.text, .messages, usage). Pass stream=True to get an async stream of AgentResponseUpdate chunks instead — essential for responsive UIs.
agent.run(msg)
Your request
before_run
Context providers add history & knowledge
middleware
Agent → chat middleware
chat client
Send to model provider
tool loop
Model calls tools ↺ until done
after_run
Store history / memories
AgentResponse
.text · .messages · usage
1result = await agent.run("Give me 3 KPIs for a support team.")2print(result.text)34async for update in agent.run("Explain the first KPI.", stream=True):5 print(update.text, end="", flush=True)
Key takeaways
Agent(client=…, instructions=…) is all you need to start.
client.as_agent(...) is a convenient shortcut.
default_options sets temperature / max_tokens for every run.
run() → AgentResponse; run(stream=True) → async updates.
Hands-on activity
Create and execute a basic AI agent using Python
- 1In the Playground, change the agent name and write a persona for ‘OpsBot’.
- 2Drop temperature to 0.1, ask the same question twice — compare. Then try 1.2.
- 3Open Code Lab → Exercise 2 and complete the TODOs (as_agent, default_options, streaming).
- 4Ask the AI reviewer to check your code.
Reference solution — labs/ex2_configured_agent.py (verified on agent-framework-core 1.26)
1"""Exercise 2 — Configure instructions, model options and streaming (Module 2)."""23import asyncio45from common import make_client67INSTRUCTIONS = """8You are "OpsBot", a business operations analyst for a mid-size SaaS company.9- Be concise and use bullet points.10- Always state assumptions explicitly.11- If you are not sure, say so instead of guessing.12"""131415async def main() -> None:16 client = make_client()1718 # Shortcut: every chat client can mint an agent with .as_agent(...)19 agent = client.as_agent(20 name="OpsBot",21 instructions=INSTRUCTIONS,22 default_options={"temperature": 0.2, "max_tokens": 400},23 )2425 # Non-streaming: wait for the full answer26 result = await agent.run("Give me 3 KPIs to track for a customer-support team.")27 print(result.text)28 print("-" * 60)2930 # Streaming: print tokens as they arrive31 async for update in agent.run("Now explain the first KPI to a new manager.", stream=True):32 if update.text:33 print(update.text, end="", flush=True)34 print()353637if __name__ == "__main__":38 asyncio.run(main())
Check your understanding
Q1.Which client class should you use with Groq's OpenAI-compatible endpoint in MAF 1.x?
Q2.How do you stream an agent's answer?
Q3.Where do you set temperature for every call an agent makes?