An ADK agent with Memory Bank integration that remembers user preferences and facts across sessions. Deployable to Vertex AI Agent Engine or Cloud Run.
| Key Features | |
|---|---|
| Cross-session memory | Remembers user preferences, personal info, and explicit instructions across conversations using Memory Bank's managed topics. |
| Automatic memory extraction | An after_agent_callback sends session events to Memory Bank after each turn — no manual tagging needed. |
| Preloaded recall | PreloadMemoryTool injects relevant memories into the system instruction at the start of each turn, so the model sees them automatically. |
| Two deployment targets | Same agent code, deployable to Agent Engine (fully managed) or Cloud Run (container-based with FastAPI). |
Memory Bank shines in multi-session conversations. Here are some examples showing how memories are saved and recalled:
Session 1 — tell the agent about yourself:
You: I live in Austin, Texas.
Agent: Got it! Austin is a great city — known for its live music scene and BBQ. Let me know if you need anything Austin-related!
Session 2 — the agent remembers without being reminded:
You: What's the weather like?
Agent: Here's the current weather for Austin, Texas: It's 90 degrees and sunny.
Session 1 — set a preference:
You: I want you to talk like a pirate from now on.
Agent: Aye aye, captain! Consider it done — I'll be speakin' in the tongue of the seven seas from here on out! What be yer next command?
Session 2 — the preference persists:
You: What can you help me with?
Agent: Ahoy, matey! I can help ye with weather reports, tellin' the time, and rememberin' all manner of facts about ye. What treasure of knowledge be ye seekin' today?
These work because:
PreloadMemoryToolretrieves "lives in Austin" and "wants pirate speak" at the start of each turngenerate_memories_callbackextracts those facts after the first session- Memory Bank consolidates them so they're available in every future session
- Python 3.10+
- uv — Python package manager (Install)
- Google Cloud SDK —
gcloudCLI (Install) - Google Cloud project with billing enabled
make installgcloud auth login
gcloud auth application-default login
gcloud config set project <your-project-id>make playgroundThis launches the ADK Web UI on port 8501. Select the app folder to interact with your agent.
When running locally, ADK uses InMemoryMemoryService — memories won't persist across restarts. To test against a real Memory Bank instance:
uv run adk web . --port 8501 --memory_service_uri=agentengine://<AGENT_ENGINE_RESOURCE_NAME>After completing the initial setup, you have two deployment options:
Agent Engine provides fully managed infrastructure — session management, memory, and scaling are handled automatically.
make deploy-agent-engineThis runs app/app_utils/deploy.py, which:
- Reads
memory_bank_configfromagent_engine_app.py - Wraps it in a
ReasoningEngineContextSpec - Passes it via
context_specin theAgentEngineConfig - Creates or updates the Agent Engine instance with Memory Bank configured
Entry point: app/agent_engine_app.py (AgentEngineApp, a subclass of AdkApp)
Cloud Run gives you full control over the serving infrastructure — custom endpoints, middleware, container environment.
make deploy-cloud-runOn first startup, the Cloud Run service will:
- Find or create an Agent Engine instance for session and memory storage
- If creating, pass
memory_bank_configviacontext_specto enable Memory Bank - Set
session_service_uriandmemory_service_urito the sameagentengine://URI - Start the FastAPI server with both services wired up
Entry point: app/fast_api_app.py (FastAPI via get_fast_api_app())
memory-bank-sample/
├── app/
│ ├── agent.py # Shared agent definition (tools, memory callback, PreloadMemoryTool)
│ ├── agent_engine_app.py # Agent Engine entry point + Memory Bank config
│ ├── fast_api_app.py # Cloud Run entry point + Memory Bank config
│ └── app_utils/
│ ├── deploy.py # Agent Engine deployment script
│ ├── telemetry.py # OpenTelemetry setup
│ └── typing.py # Pydantic models
├── tests/ # Unit, integration, and eval tests
├── Dockerfile # Cloud Run container
├── Makefile # Install, deploy, test, eval commands
└── pyproject.toml # Project dependencies
| Command | Description |
|---|---|
make install |
Install dependencies using uv |
make playground |
Launch local dev playground (ADK Web UI) |
make deploy-agent-engine |
Deploy to Vertex AI Agent Engine |
make deploy-cloud-run |
Deploy to Cloud Run |
make local-server |
Run FastAPI server locally with hot-reload |
make test |
Run unit and integration tests |
make eval |
Run agent evaluation |
make lint |
Run code quality checks |
See AGENT_GUIDE.md for a deeper reference on ADK concepts, Memory Bank integration patterns, deployment mechanics, session management, testing, and debugging strategies.
This software is provided as-is, without warranty or representation for any use or purpose. This is sample code intended for demonstration and learning purposes only. It is not intended for production use. Your use of this software is at your own risk.