Skip to content

feat: Add configureRequest callback to A2A clients - #399

Open
OS-leonardoalmeida wants to merge 7 commits into
a2aproject:mainfrom
OS-leonardoalmeida:feat/add-request-callback
Open

feat: Add configureRequest callback to A2A clients#399
OS-leonardoalmeida wants to merge 7 commits into
a2aproject:mainfrom
OS-leonardoalmeida:feat/add-request-callback

Conversation

@OS-leonardoalmeida

@OS-leonardoalmeida OS-leonardoalmeida commented May 29, 2026

Copy link
Copy Markdown

Summary

  • Adds an optional Func<HttpRequestMessage, CancellationToken, Task>? configureRequest parameter to the A2AClient
    constructors in both A2A and A2A.V0_3. When provided, it is invoked for every outgoing HttpRequestMessage (unary
    and SSE/streaming) just before HttpClient.SendAsync, allowing callers to attach authentication headers or other per-request customizations asynchronously.
  • Removes the need to subclass A2AClient to inject per-request headers.

Tests

  • Adds unit tests covering: callback invocation + header propagation on unary requests, invocation + header
    propagation on streaming requests, and exception propagation (which prevents the request from being sent).

  • Refactors the V0_3 MockHttpMessageHandler capture delegate from Action<HttpRequestMessage>? to
    Action<HttpRequestMessage, string?>?. The handler now reads the request body once and passes both the request and the body string to the callback. This was needed because the V0_3 client now disposes HttpRequestMessage via using, which would otherwise dispose the content before tests could read it.

    Notes

    • The new parameter is optional with a null default, so existing callers are unaffected (source- and
      binary-compatible at the call-site level).
    • Callback runs after the library has set default headers (e.g. A2A-Version, Accept) so callers can override them
      if needed.

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

Copy link
Copy Markdown
Contributor

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 optional configureRequest callback to the A2AClient constructors in both the A2A and A2A.V0_3 clients, allowing callers to customize outgoing HTTP requests (e.g., for authentication). It also adds comprehensive unit tests to verify this behavior. The feedback suggests ensuring that the newly created HttpRequestMessage in SendAndReadResponseStreamAsync is properly disposed of to avoid potential resource leaks.

Comment thread src/A2A.V0_3/Client/A2AClient.cs Outdated
@darrelmiller

darrelmiller commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

I like the sound of this PR. I will review shortly once this backlog of pending PRs is cleaned up. Thank you for the contribution.

@darrelmiller darrelmiller changed the title Add configureRequest callback to A2A clients feat: Add configureRequest callback to A2A clients Jun 1, 2026
Comment thread src/A2A/Client/A2AClient.cs
@OS-leonardoalmeida

Copy link
Copy Markdown
Author

Hi @darrelmiller any news regarding this PR?

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.

3 participants