Lesson 1: Basic Agent Creation with Conversation Memory¶
In this lesson we will create a basic AI agent using Microsoft Agent Framework with system instructions and automatic conversation memory capabilities.
-
Ensure all pre-requisites are met and installed.
-
Switch to Lesson 1 directory:
-
Copy the configuration file from the Solutions directory:
-
Open the project in your favorite IDE or text editor.
-
Open
Program.csand locate the TODO for each step and apply the following changes for each:-
TODO: Step 1 - Initialize the chat client using Microsoft Agent Framework:
-
TODO: Step 2 - Configure system message using Agent Framework pattern:
-
TODO: Step 3 - Create a ChatClientAgent with the chat client and system instructions:
-
TODO: Step 4 - Create a thread for conversation:
-
TODO: Step 5 - Use agent to respond to user input:
-
-
Run the program with this command:
-
When prompted ask for financial advice:
You will receive a similar response:
Assistant > Ah, the magical world of stock picking! Imagine walking into a buffet, and instead of loading your plate with mystery meat, you're strategically choosing the tastiest, most promising dishes. Here are a few general menus to consider, with a sprinkle of fun: 1. **Tech Tango** - Think companies that dance to the tune of innovation! Look for firms diving into AI or cloud computing. They're like the cool kids at the financial disco. 2. **Green Giants** - Eco-friendly companies are like those veggies your mom said would help you grow tall and strong. Renewable energy stocks might just add some height to your portfolio. 3. **Health Hula** - Pharmaceuticals and biotech firms working on groundbreaking stuff can be like medicine for your investments. Just remember, there's always a bit of a twirl and spin with these. 4. **Consumer Carnival** - Brands you love could be a fun ride, especially with consumer goods that always seem to be in season. 5. **Financial Fiesta** - Banks or fintech companies can be like salsa on your stock tacos—adding a bit of spice and zing! Remember, always research like you're planning the perfect vacation and balance your choices like you balance a pizza with just the right amount of toppings. And of course, consult a real-world financial oracle before making any big moves. Bon appétit in the stock market buffet!
Testing Conversation Memory¶
Agent Framework automatically maintains conversation history through the AgentThread. Test this feature by asking follow-up questions:
-
After receiving the initial response, ask a follow-up question that references the previous conversation:
-
The agent should remember your previous conversation and provide specific details about the tech stocks category without you having to repeat your original question.
-
Try another follow-up:
-
Again, the agent should reference the categories it mentioned earlier, demonstrating that conversation context is automatically preserved.
Key Learning: Notice how Agent Framework automatically maintains conversation history without any additional code. The AgentThread handles all conversation memory management for you.