- This event has passed.
7 PM – AI Agent – Darin
Today We Did
- Got started on the grep method for local file search
Homework: Adding Memory to Your AI Chatbot
Background
Your chatbot already displays previous messages in the conversation. However, the AI agent only receives the latest message, meaning it cannot remember what was said earlier.
Your task is to modify the existing code so that the AI agent can access the entire conversation history.
Part 1: Reading
Before starting, review:
- OpenAI Agents SDK — Running Agents (focus on conversation history).
- Streamlit Session State.
- The existing
query_agent()function and howst.session_state.messagesworks.
Part 2: Coding
Task 1 — Modify the agent function
In ai_file_search_sdk.py:
- Modify
query_agent()so it accepts a list of messages instead of a string. - Pass this list to
Runner.run().
Task 2 — Update the chatbot
In ai_chatbot_lesson_2.py:
- Change the assistant’s message role from
"ai"to"assistant"so that the history uses the correct roles for the agent. - Modify the call to
query_agent()so that it receives the entirest.session_state.messageslist rather than only the latest prompt.
Part 3: Testing
Start the chatbot and send these messages in order:
- “My favorite animal is a penguin.”
- “What is my favorite animal?”
Verify that the agent remembers your answer.
Submission
Submit your modified Python files and a screenshot showing that your AI agent remembers a previous message.
Notes:
You can reach me at ddjapri@ayclogic.com.
All class notes can be found here.