What is an Agent?
An agent encapsulates:- A language model client (e.g., Azure OpenAI, Anthropic, Ollama)
- Instructions that define the agent’s behavior and personality
- Tools (functions) the agent can call to access external data or perform actions
- Middleware for intercepting and modifying requests/responses
- Session management for multi-turn conversations
- Python
- .NET
In Python, agents implement the
SupportsAgentRun protocol and the framework provides:Agent- Main agent class with middleware and telemetryRawAgent- Core agent without built-in layersBaseAgent- Minimal base class for custom implementations
Agent class is the recommended starting point for most use cases.Creating Your First Agent
- Python
- .NET
Agent Lifecycle
Non-Streaming Mode
- Python
- .NET
run() method returns an AgentResponse containing:messages- List of response messagestext- Concatenated text from all messagesresponse_id- Unique identifier for this responseusage_details- Token usage and cost informationvalue- Structured output (if using response format)
Streaming Mode
- Python
- .NET
ResponseStream that yields AgentResponseUpdate objects and provides get_final_response() to retrieve the complete response.Agent Configuration
Instructions
Instructions define the agent’s behavior, personality, and capabilities:- Python
- .NET
Model Parameters
- Python
- .NET
temperature(0.0-2.0) - Controls randomnessmax_tokens- Maximum response lengthtop_p- Nucleus sampling parameterfrequency_penalty- Reduces repetitionpresence_penalty- Encourages topic diversityseed- Reproducible outputsstop- Stop sequences
Agent Protocol
- Python
- .NET
The This protocol uses structural subtyping (duck typing), so classes don’t need to explicitly inherit from it.
SupportsAgentRun protocol defines the agent interface:Agent Properties
- Python
- .NET
Converting Agents to Tools
- Python
- .NET
Agents can be converted to tools for use by other agents:
Best Practices
Agent Design Tips
- Clear Instructions: Be specific about the agent’s role, tone, and constraints
- Tool Selection: Only provide tools the agent actually needs
- Session Management: Reuse sessions for multi-turn conversations
- Error Handling: Always handle potential exceptions in production
- Observability: Enable telemetry to monitor agent behavior
- Cost Control: Set
max_tokensto prevent runaway costs
Next Steps
Tools
Learn how to give agents function-calling capabilities
Sessions
Manage multi-turn conversations with sessions
Middleware
Intercept and modify agent behavior with middleware
Observability
Monitor agent performance with OpenTelemetry