Get real-time responses as the agent generates them:
# Streaming: receive tokens as they are generatedprint("Agent (streaming): ", end="", flush=True)async for chunk in agent.run("Tell me a one-sentence fun fact.", stream=True): if chunk.text: print(chunk.text, end="", flush=True)print()
Give your agent capabilities by adding function tools:
from agent_framework import toolfrom typing import Annotatedfrom pydantic import Fieldfrom random import randint@tool(approval_mode="never_require")def get_weather( location: Annotated[str, Field(description="The location to get the weather for.")],) -> str: """Get the weather for a given location.""" conditions = ["sunny", "cloudy", "rainy", "stormy"] return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."# Create agent with the toolagent = client.as_agent( name="WeatherAgent", instructions="You are a helpful weather agent. Use the get_weather tool to answer questions.", tools=get_weather,)result = await agent.run("What's the weather like in Seattle?")print(f"Agent: {result}")
In production, use approval_mode="always_require" (Python) to get user confirmation before executing tools.
Maintain conversation context across multiple interactions:
# Create a session to maintain conversation historysession = agent.create_session()# First turnresult = await agent.run("My name is Alice and I love hiking.", session=session)print(f"Agent: {result}\n")# Second turn — the agent remembers the contextresult = await agent.run("What do you remember about me?", session=session)print(f"Agent: {result}")
Now that you have a working agent, explore more capabilities:
Installation Guide
Detailed setup instructions and configuration options
Core Concepts
Learn about agents, tools, sessions, and workflows
Add Memory
Give your agent long-term memory with context providers
Build Workflows
Chain multiple agents and executors together
Production consideration: DefaultAzureCredential (in .NET) is convenient for development but may cause latency in production. Consider using ManagedIdentityCredential or a specific credential type for production deployments.