Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rakshith-git
Copy link
Contributor

Refactor OpenMemoryService Samples and readme to Use get_fast_api_app with URI Scheme

Summary

This PR refactors the open_memory sample to use get_fast_api_app with the openmemory:// URI scheme instead of directly instantiating AdkWebServer. The previous sample code was confusing and didn't work properly with ADK's standard patterns. The new implementation is cleaner, more maintainable, and works correctly with both Runner and the web UI.

Changes

Improvements

  • Simplified Architecture: Uses get_fast_api_app which is the recommended way to set up ADK FastAPI servers
  • URI-Based Configuration: Implements the openmemory:// URI scheme pattern consistent with other ADK services (e.g., rag://, agentengine://)
  • Proper Agent Structure: Moved agent to open_memory_agent/ subdirectory following ADK's agent loading conventions
  • Cleaner Code: Inlined service factory registration directly in main.py, removing the need for a separate registration file
  • Better Documentation: Updated README with clear usage instructions for both URI-based approach (recommended) and direct Runner usage
  • Environment Variable Security: API keys are now only read from environment variables, not passed in URIs

What Works Now

✅ Works with get_fast_api_app and web UI
✅ Works with Runner for programmatic usage
✅ Proper service registration via URI scheme
✅ Clear, maintainable code structure
✅ Comprehensive documentation

Files Changed

  • contributing/samples/open_memory/main.py - Refactored to use get_fast_api_app with URI scheme
  • contributing/samples/open_memory/README.md - Updated with clear usage instructions
  • contributing/samples/open_memory/open_memory_agent/ - Proper agent subdirectory structure

Testing

The sample can be run with:

python contributing/samples/open_memory/main.py

The server will start on http://0.0.0.0:8000 with the web UI enabled and memory working.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rakshith-git, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the open_memory sample to enhance its adherence to ADK's standard patterns and improve overall maintainability and clarity. The core change involves migrating the sample to use the get_fast_api_app utility with a new openmemory:// URI scheme, which streamlines the setup of FastAPI servers and standardizes service configuration. This ensures the sample is more robust, easier to understand, and correctly integrates with both the web UI and programmatic Runner usage, while also improving security by handling API keys via environment variables.

Highlights

  • Standardized API Setup: The open_memory sample now uses get_fast_api_app with a dedicated openmemory:// URI scheme, aligning with ADK's recommended patterns for FastAPI server setup.
  • Improved Code Structure: The agent definition has been moved into a proper open_memory_agent/ subdirectory, and service factory registration is inlined in main.py for a cleaner architecture.
  • Enhanced Documentation: The README.md has been significantly updated to provide clear usage instructions for both the new URI-based approach and direct Runner usage, including a detailed sample structure.
  • Secure API Key Handling: API keys are now exclusively read from environment variables, removing them from URIs for better security practices.
  • Agent Logic Refinement: The agent's after_agent_callback for auto-saving sessions has been removed, and memory tool imports (load_memory_tool, preload_memory_tool) have been updated to load_memory and preload_memory respectively, along with an updated agent instruction.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a great refactoring of the OpenMemory sample. Using get_fast_api_app with a custom URI scheme simplifies the code significantly and aligns it with ADK best practices. The new structure is cleaner and more maintainable. The updated agent instructions are also a welcome improvement. I have one suggestion regarding the CORS configuration for improved security.

@hangfei
Copy link
Collaborator

hangfei commented Nov 14, 2025

Please address or close Gemini Reviews before merge.

@rakshith-git
Copy link
Contributor Author

Please address or close Gemini Reviews before merge.

I have addressed the issues

@hangfei hangfei merged commit f167742 into google:main Nov 14, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants