-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feat/fastapi modular server contribution #2967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/fastapi modular server contribution #2967
Conversation
- Complete modular FastAPI server implementation for ADK agents - Server-Sent Events (SSE) streaming with three optimization levels - Clean architecture with proper separation of concerns - Includes greetings agent example with streaming capabilities - Comprehensive configuration management and logging - Ready-to-use with environment configuration template - Follows ADK best practices for production deployments Features: - Real-time agent streaming via SSE endpoints - Configurable optimization levels (minimal, balanced, full compatibility) - Modular agent system with easy extensibility - Proper error handling and logging - Environment-based configuration management Files added: - Modular server structure with agents, API, config, core, and models - SSE event mapper for optimized streaming - Streaming models and request handling - Greetings agent implementation - Environment configuration template - Comprehensive README documentation
Standardize time module usage across the codebase by replacing dynamic imports with direct imports. Also improve JSON error handling in SSE responses and update README numbering.
- Use json.dumps for SSE event formatting in agent_router - Replace loop with list comprehension in sse_event_mapper - Remove unused variables and outdated comments in custom_adk_server - Specify ModuleNotFoundError exception for web assets loading
- Update type hints from typing.List/Dict to modern list/dict - Add TYPE_CHECKING imports where needed - Rename greetings_agent file for consistency - Expand .gitignore with common development artifacts - Clean up unused imports in multiple files
…utorformat.sh) Reorganize imports to follow PEP 8 guidelines by grouping standard library, third-party, and local imports separately. This improves code readability and maintainability while keeping the same functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @FrigaZzz, 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 provides a concrete, production-ready template for developers looking to leverage the modular server capabilities introduced in ADK v1.9.0. It offers a structured approach to building custom FastAPI applications on top of ADK, enabling easy extension, performance optimization for streaming, and a streamlined development experience with hot-reloading. The goal is to guide users in creating robust and scalable ADK-powered services.
Highlights
- Reference Implementation: This PR introduces a comprehensive reference implementation for extending the newly modularized
adk_web_server.py
(from v1.9.0) into a production-ready FastAPI server. - Modular Architecture: It showcases how to add custom routers, override or extend ADK endpoints, and integrate custom business logic through a clean, modular router system.
- Optimized SSE Streaming: The implementation includes an optimized Server-Sent Events (SSE) streaming mapper with three distinct optimization levels (
MINIMAL
,BALANCED
,FULL_COMPAT
) to reduce payload sizes and improve performance. - Hot-Reload Development: The example demonstrates how to enable hot-reloading for agents during development using
watchdog
, facilitating faster iteration cycles. - Comprehensive Documentation: A detailed
README.md
is provided within the sample, offering a step-by-step guide for extending ADK servers, including customization examples for routers, SSE mappers, and middleware.
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
-
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. ↩
There was a problem hiding this 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 introduces an excellent and comprehensive example of a modular FastAPI server for the ADK. The project structure is well-organized, and the code follows modern Python and FastAPI best practices, including dependency injection, configuration management with Pydantic, and an application factory pattern. The inclusion of features like agent hot-reloading and optimized SSE streaming provides significant value as a reference implementation. My review focuses on improving the clarity and accuracy of the documentation to ensure it aligns perfectly with the provided code, making it even more helpful for developers.
There was a problem hiding this 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 provides an excellent and comprehensive example of how to build a modular FastAPI server on top of the ADK. The code is well-structured, follows modern Python and FastAPI best practices, and includes valuable features like hot-reloading and optimized SSE streaming. The documentation is thorough and very helpful. I've identified a few minor inconsistencies and potential points of confusion in the README file that could be improved to enhance the user experience. Additionally, I've suggested a small refactoring in the logging setup for better readability. Overall, this is a high-quality contribution that will be a great resource for developers.
…e and remove obsolete SSE optimization examples
PR: Example FastAPI Modular Server Usage
📖 Overview
This PR adds a reference implementation showcasing how to extend the newly modularized
adk_web_server.py
(introduced in v1.9.0) into a production-ready FastAPI server.🎯 Motivation
Release v1.9.0 introduced the following change:
This PR provides a concrete template that leverages those changes, making it easier for teams to:
📚 What’s Included
fastapi_modular_server/
) with routers, agents, config, and core utilities.MINIMAL
,BALANCED
,FULL_COMPAT
).📝 Notes
v1.9.0
.✅ Checklist
v1.14.0
📖 Proposal for Python Docs
We should extend the ADK Python documentation with a new section.
Suggested Doc Location:
docs/runtime/fastapi_server_extensions.md
Proposed Section Outline:
Why Modularization?
fast_api.py
refactor in v1.9.0Building a Custom Server
Overriding Built-in Routes
Optimizing Streaming (straightforward example)
SSEEventMapper
This way, the docs PR will complement this usage example, turning it into a reusable guide for the community.
🔗 Associated Issue
Closes #2953
🧪 Testing Plan
The server was tested locally by running it and issuing a streaming request via
fetch
in the browser console:✅ The SSE stream responded successfully with generated content.
📸 Screenshot of the running server:
📖 Proposal for Python Docs
We should extend the ADK Python documentation with a new section.
Suggested Doc Location:
docs/runtime/fastapi_server_extensions.md
Proposed Section Outline:
Why Modularization?
fast_api.py
refactor in v1.9.0Building a Custom Server
Overriding Built-in Routes
Optimizing Streaming (straightforward example)
SSEEventMapper
This way, the docs PR will complement this usage example, turning it into a reusable guide for the community.