Skip to content

refactor(server)!: migrate from Application wrappers to Starlette route-based endpoints for rest#892

Merged
guglielmo-san merged 30 commits intoa2aproject:1.0-devfrom
guglielmo-san:guglielmoc/refactor_rest_server
Mar 24, 2026
Merged

refactor(server)!: migrate from Application wrappers to Starlette route-based endpoints for rest#892
guglielmo-san merged 30 commits intoa2aproject:1.0-devfrom
guglielmo-san:guglielmoc/refactor_rest_server

Conversation

@guglielmo-san
Copy link
Member

Description

This PR refactors the rest server implementation to expose Starlette Route components directly (via RestRoutes) instead of requiring full FastAPI or Starlette application wrappers.

Ref #797 🦕

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 REST server architecture by moving away from encapsulating REST endpoints within a dedicated FastAPI application wrapper. Instead, it introduces a new utility function, create_rest_routes, which directly generates Starlette Route components. This change allows for more flexible integration of REST endpoints into existing Starlette or FastAPI applications, promoting a more modular and less opinionated server setup. The update also includes minor adjustments to task state and part type handling in the Vertex AI task converter and general cleanup across samples and tests to align with the new routing approach.

Highlights

  • REST Server Refactoring: The REST server implementation has been refactored to directly expose Starlette Route components via a new create_rest_routes function, eliminating the need for full FastAPI or Starlette application wrappers.
  • Removed A2ARESTFastAPIApplication: The A2ARESTFastAPIApplication class and its related files have been removed, simplifying the application structure and reducing dependencies.
  • Updated Task Converter Logic: The vertex_task_converter.py file was updated to use vertexai.types.State instead of vertexai_types.A2aTaskState and vertexai.types.Part instead of google.genai.types.Part, streamlining type handling for task states and parts.
  • Standardized URL Paths: Trailing slashes were removed from several URL paths in samples/hello_world_agent.py for consistency.
  • JSON-RPC Route Enhancements: The create_jsonrpc_routes function now includes Middleware and Router type hints, imports DEFAULT_RPC_URL, and makes the rpc_url parameter optional with a default value.
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.

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.

@github-actions
Copy link

github-actions bot commented Mar 23, 2026

🧪 Code Coverage (vs 1.0-dev)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/request_handlers/rest_handler.py 93.75% 91.67% 🔴 -2.08%
src/a2a/server/routes/rest_routes.py (new) 77.11%
Total 91.43% 91.37% 🔴 -0.06%

Generated by coverage-comment.yml

@guglielmo-san guglielmo-san changed the title Guglielmoc/refactor rest server refactor(server)!: migrate from Application wrappers to Starlette route-based endpoints for rest Mar 23, 2026
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 refactors the REST application setup by removing the A2ARESTFastAPIApplication class and introducing a new create_rest_routes function. This change streamlines the creation of REST endpoints, including v0.3 compatibility, and integrates them directly with Starlette applications. The vertex_task_converter.py file was updated to align with vertexai.types for task states and parts, removing google.genai dependencies. Additionally, several test files were updated to reflect these changes. Review comments suggest simplifying the _handle_authenticated_agent_card logic in rest_routes.py and removing an unused Middleware import in test_jsonrpc_routes.py.

@guglielmo-san guglielmo-san marked this pull request as ready for review March 23, 2026 16:35
@guglielmo-san guglielmo-san requested a review from a team as a code owner March 23, 2026 16:35
@guglielmo-san guglielmo-san requested a review from ishymko March 23, 2026 16:35
@guglielmo-san guglielmo-san enabled auto-merge (squash) March 24, 2026 16:09
@guglielmo-san guglielmo-san merged commit 4be2064 into a2aproject:1.0-dev Mar 24, 2026
9 checks passed
@guglielmo-san guglielmo-san deleted the guglielmoc/refactor_rest_server branch March 24, 2026 16:11
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