Key Concepts
- ADK (Agent Development Framework): Google's framework for building AI agents.
- System Instructions: Defines the agent's personality, goals, and behavior.
- Model: The "brain" of the agent, used for reasoning (e.g., Gemini 2.5 Flash).
- Tools: Python functions that give the agent special abilities.
- Session: A complete, continuous conversation between the user and the agent.
- State: The agent's "scratch pad" for the current conversation, storing key-value pairs.
- Database Session Service: Allows storing session data in a persistent SQL database.
- Memory Service: Responsible for storing and retrieving information across multiple sessions.
- Vertex AI Memory Bank: A memory service that uses Gemini to intelligently process conversations and extract key facts.
- Autosave to Memory Callback Function: Automates the saving of session events to Memory Bank.
Agent Architecture and Components
- A basic ADK agent consists of:
- System Instructions: Define the agent's personality and goals.
- Model: Acts as the agent's brain for reasoning. In the example, Gemini 2.5 Flash is used.
- Tools: Python functions that enable the agent to perform actions. Examples include
start quiz,submit answer, andget quiz status.
- The
LLM agentfunction in ADK combines these components into a single conversational agent.
Quiz Flow
- The Python tutor agent follows a clear quiz flow:
- Starts the quiz.
- Waits for a user response.
- Uses its tools to check the answer.
- Fetches the next question.
- Follows the logic defined in the system prompt.
Short-Term Memory: Sessions and State
- Session: Represents a single, continuous conversation. Each new chat starts a new session with a unique ID.
- Session Anatomy:
- Identification information.
- Complete conversational history.
- State: A key-value store for tracking the current conversation's progress.
- State Example (Python Tutor):
current question indexcorrect answersscore percentage
- The model and tools can interact with the state:
- The model can read values from the state using curly braces in the system prompt (e.g.,
current score: {score percentage}). - Tools can read from and write to the state. For example, the
submit answertool updates the score in the state.
- The model can read values from the state using curly braces in the system prompt (e.g.,
- By default, session data is stored in memory and lost when the application stops.
Database Session Service
- ADK provides a database session service for persistent storage of session data.
- It supports SQL databases like SQLite and Cloud SQL PostgreSQL.
- ADK automatically sets up the session tables and schemas.
- Session data survives ADK crashes and restarts.
Long-Term Memory: Memory Service and Vertex AI Memory Bank
- Long-term memory allows the agent to remember information across multiple sessions.
- ADK provides a memory service for this purpose.
- Vertex AI Memory Bank:
- Uses Gemini to intelligently process conversations.
- Extracts and summarizes the most important facts.
- Stores the summarized information for future use.
- Benefits:
- Efficiently provides the agent with key information.
- Avoids overwhelming the agent with the full chat history.
Implementing Long-Term Memory
- To implement long-term memory:
- Add memory instructions to the system prompt.
- Include a
search memorytool. - Register an
autosave to memorycallback function.
- Autosave to Memory Callback Function:
- Runs after each interaction.
- Sends the session events to Memory Bank for summarization and storage.
Intelligent Agent Flow with Long-Term Memory
- The agent starts a conversation and asks for the user's name.
- The agent calls the
search memorytool to check for any history with that user. - The agent proceeds with the quiz.
- After the quiz, the
autosave to memorycallback function runs automatically. - Memory Bank summarizes and stores the key facts from the session.
Memory Bank Example
- In a session with a user named Megan, who scored 75% on a Python dictionaries quiz, Memory Bank might save the following:
- "My name is Megan."
- "I took a quiz about Python dictionaries."
- "I scored 75% on the dictionaries quiz."
Conclusion
ADK provides tools for creating AI agents with both short-term and long-term memory. Short-term memory, using sessions and state, allows agents to track the progress of a single conversation. Long-term memory, using the memory service and Vertex AI Memory Bank, enables agents to remember information across multiple sessions, providing a more personalized and context-aware experience. The autosave to memory callback function automates the process of saving key information to Memory Bank, allowing the agent to learn and improve over time.
AI summaries can miss context or contain errors. Check important details against the original video.





