Skip to content

feat: Add HTTP caching headers to Agent Card endpoint#761

Open
kabir wants to merge 1 commit intoa2aproject:mainfrom
kabir:issue-749
Open

feat: Add HTTP caching headers to Agent Card endpoint#761
kabir wants to merge 1 commit intoa2aproject:mainfrom
kabir:issue-749

Conversation

@kabir
Copy link
Collaborator

@kabir kabir commented Mar 17, 2026

Implements A2A specification section 8.6 caching requirements:

  • Cache-Control header with configurable max-age
  • ETag header derived from Agent Card content hash
  • Last-Modified header with initialization timestamp

Implementation:

  • Created AgentCardCacheMetadata bean in server-common to compute and cache HTTP headers at initialization
  • Enhanced HTTPRestResponse to support additional headers via Map
  • Updated RestHandler and JSON-RPC A2AServerRoutes to include caching headers
  • Caching headers applied to both REST and JSON-RPC transports (gRPC out of scope per spec)

Configuration:

  • Max-age configurable via a2a.agent-card.cache.max-age (default: 3600 seconds)
  • ETag calculated as MD5 hash of serialized Agent Card JSON
  • Last-Modified set to bean initialization time in RFC 1123 format

Testing:

  • Added testAgentCardHeaders() to AbstractA2AServerTest
  • Validates all three caching headers are present and correctly formatted
  • gRPC test overrides to skip (HTTP-only requirement)

Fixes #749 🦕

@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 introduces HTTP caching mechanisms to the Agent Card endpoint, significantly improving performance and reducing server load by allowing clients and intermediaries to cache the Agent Card content. By implementing Cache-Control, ETag, and Last-Modified headers, the system now adheres to the A2A specification's caching requirements, providing a more efficient and compliant way to serve static agent information.

Highlights

  • HTTP Caching Headers: Implemented HTTP caching headers (Cache-Control, ETag, Last-Modified) for the Agent Card endpoint, aligning with A2A specification section 8.6.
  • New Caching Metadata Bean: Introduced a new AgentCardCacheMetadata bean to compute and store caching header values at application initialization.
  • HTTPRestResponse Enhancement: Enhanced the HTTPRestResponse class to support the inclusion of additional HTTP headers.
  • Broad Application of Caching: Applied caching headers to both REST and JSON-RPC transports for the Agent Card endpoint.
  • New Test Case: Added a new test case (testAgentCardHeaders) to validate the presence and correct formatting of the caching headers.
Changelog
  • reference/grpc/src/test/java/io/a2a/server/grpc/quarkus/QuarkusA2AGrpcTest.java
    • Overrode testAgentCardHeaders to skip execution, as gRPC does not utilize HTTP caching headers.
  • reference/jsonrpc/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java
    • Injected AgentCardCacheMetadata to retrieve caching header values.
    • Updated the Javadoc for getAgentCard to document the new caching headers.
    • Modified getAgentCard to add Cache-Control, ETag, and Last-Modified headers to the HTTP response.
  • reference/rest/src/main/java/io/a2a/server/rest/quarkus/A2AServerRoutes.java
    • Refactored sendResponse to iterate and add all custom headers provided by HTTPRestResponse to the Vert.x HTTP response.
  • server-common/src/main/java/io/a2a/server/AgentCardCacheMetadata.java
    • Added a new @ApplicationScoped bean AgentCardCacheMetadata responsible for calculating and holding the Cache-Control, ETag (MD5 hash of Agent Card JSON), and Last-Modified (initialization timestamp) header values.
  • tests/server-common/src/test/java/io/a2a/server/apps/common/AbstractA2AServerTest.java
    • Added testAgentCardHeaders to verify that the Agent Card endpoint correctly returns Cache-Control, ETag, and Last-Modified headers with appropriate formats.
  • transport/rest/src/main/java/io/a2a/transport/rest/handler/RestHandler.java
    • Injected AgentCardCacheMetadata into RestHandler.
    • Updated constructors for RestHandler to accept AgentCardCacheMetadata.
    • Modified getAgentCard to construct an HTTPRestResponse with the newly generated caching headers.
    • Extended HTTPRestResponse to include a headers map, along with new constructors and a getter for these headers.
  • transport/rest/src/test/java/io/a2a/transport/rest/handler/RestHandlerTest.java
    • Introduced helper methods createCacheMetadata() for AgentCardCacheMetadata instantiation.
    • Updated all RestHandler test instantiations to pass the AgentCardCacheMetadata dependency.
Activity
  • No human activity (comments, reviews, etc.) was found for this pull request.
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 effectively implements HTTP caching for the Agent Card endpoint by adding Cache-Control, ETag, and Last-Modified headers, as specified. The implementation is well-structured, introducing a dedicated AgentCardCacheMetadata bean to compute and cache these headers at startup. The changes are correctly propagated to both JSON-RPC and REST transports, and the new functionality is validated with a new test case.

I have one suggestion to improve the consistency of ETag generation across different environments. Otherwise, the changes look good.

@jmesnil
Copy link
Collaborator

jmesnil commented Mar 18, 2026

@kabir the CI failure looks genuine

@kabir
Copy link
Collaborator Author

kabir commented Mar 18, 2026

@jmesnil Yep, investigating

@kabir
Copy link
Collaborator Author

kabir commented Mar 18, 2026

/gemini review

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 effectively implements HTTP caching for the Agent Card endpoint as per the A2A specification. The changes are well-structured, introducing an AgentCardCacheMetadata bean to encapsulate the caching logic and cleanly integrating it into the REST and JSON-RPC layers. The tests are also comprehensive, including a new test for the caching headers and appropriate overrides for gRPC.

To improve robustness, I recommend failing fast during application startup in AgentCardCacheMetadata if required dependencies are missing, rather than causing a NullPointerException at runtime.

Overall, this is a great addition that improves performance and compliance with the specification.

Implements A2A specification section 8.6 caching requirements:
- Cache-Control header with configurable max-age (CARD-CACHE-001)
- ETag header derived from Agent Card content hash (CARD-CACHE-002)
- Last-Modified header with initialization timestamp (CARD-CACHE-003)

**Implementation:**
- Created AgentCardCacheMetadata bean in server-common to compute and cache HTTP headers at initialization
- Enhanced HTTPRestResponse to support additional headers via Map
- Updated RestHandler and JSON-RPC A2AServerRoutes to include caching headers
- Caching headers applied to both REST and JSON-RPC transports (gRPC out of scope per spec)

**Configuration:**
- Max-age configurable via `a2a.agent-card.cache.max-age` (default: 3600 seconds)
- ETag calculated as MD5 hash of serialized Agent Card JSON
- Last-Modified set to bean initialization time in RFC 1123 format

**Testing:**
- Added testAgentCardHeaders() to AbstractA2AServerTest
- Validates all three caching headers are present and correctly formatted
- gRPC test overrides to skip (HTTP-only requirement)

Fixes a2aproject#749

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@kabir
Copy link
Collaborator Author

kabir commented Mar 18, 2026

@jmesnil Should be fine now

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.

[Bug]: Agent Card response missing Cache-Control and ETag caching headers

2 participants