What are Agents?
Agents are the core building blocks of AutoGen applications. Each agent is an autonomous entity that can:- Generate responses using language models
- Execute functions and tools
- Communicate with other agents
- Maintain conversation history
- Apply custom logic through middleware
Core Agent Types
AutoGen for .NET provides several built-in agent types:AssistantAgent
An AI-powered agent that uses language models to generate intelligent responses.string
required
Unique identifier for the agent in conversations
string
default:"You are a helpful AI assistant"
Instructions that define the agent’s personality, role, and behavior
ConversableAgentConfig
required
Configuration for the language model, including API keys and parameters
HumanInputMode
default:"NEVER"
When to request human input (NEVER, ALWAYS, TERMINATE)
Func<IEnumerable<IMessage>, CancellationToken, Task<bool>>
Custom function to determine when to end the conversation
UserProxyAgent
Represents a human user or autonomous proxy in the conversation.ConversableAgent Base Class
BothAssistantAgent and UserProxyAgent inherit from ConversableAgent, which provides:
- Message generation and handling
- Function execution capabilities
- Middleware support
- Conversation management
Agent Configuration
ConversableAgentConfig
Configures the language model behavior:System Messages
Craft effective system messages to guide agent behavior:Message Generation
Basic Message Sending
Streaming Responses
Stream responses token-by-token for real-time output:Agent Communication
Two-Agent Chat
Direct conversation between two agents:GenerateReplyAsync
Lower-level method for custom conversation control:Middleware and Extensions
Enhance agents with middleware:Print Message Middleware
Format and display messages:Custom Middleware
Create custom message processing logic:Message Connector Middleware
Convert between different message formats:Termination Conditions
Default Termination
Conversations end when:- Maximum rounds reached
- Termination message received
- Custom termination condition met
Custom Termination
Provider-Specific Agents
OpenAIChatAgent
AnthropicClientAgent
ChatCompletionsClientAgent (Azure AI)
SemanticKernelAgent
Best Practices
System Message Design
System Message Design
- Be specific about the agent’s role and responsibilities
- Include output format requirements
- Specify constraints and limitations
- Use examples when needed
- Keep it concise but complete
Agent Naming
Agent Naming
- Use descriptive, unique names
- Avoid special characters
- Keep names short and memorable
- Use lowercase for consistency
Configuration
Configuration
- Set
Temperature = 0for deterministic output - Use
Temperature = 0.7-1.0for creative tasks - Set appropriate token limits to control costs
- Configure timeouts for long-running operations
Error Handling
Error Handling
Next Steps
Group Chat
Create multi-agent conversations
Function Calling
Add custom functions to agents
Code Execution
Execute code dynamically
OpenAI Integration
Learn about OpenAI-specific features