Skip to content

fix: correct well-known URL construction for agent base with paths - #70

Closed
caio-henrique wants to merge 1 commit into
spring-ai-community:mainfrom
caio-henrique:fix/a2a-well-known-url-construction
Closed

caio-henrique wants to merge 1 commit into
spring-ai-community:mainfrom
caio-henrique:fix/a2a-well-known-url-construction

Conversation

@caio-henrique

Copy link
Copy Markdown
Contributor

Description

This PR fixes a bug in A2ASubagentResolver where the well‑known agent card URL was being constructed with duplicated path segments when the agent base URI already contained a path.

Problem

The previous implementation appended the base path twice, causing the agent’s sub‑path (e.g., /dominio) to appear duplicated in the final URL. This resulted in HTTP 404 errors for agents deployed with a context path.

Solution

The URL construction logic has been changed to:

  • Normalize the base URL to always end with a single slash (/).
  • Remove the leading slash from the configured agentCardPath to treat it as a relative path.
  • Concatenate both parts to produce the final URL.

This change eliminates the path duplication and handles the following cases:

  • Base URLs with and without trailing slashes
  • Base URLs with and without sub‑paths
  • Custom agentCardPath values (with and without leading /)
  • Both HTTP and HTTPS schemes

Testing

Parameterized tests have been added covering multiple scenarios. All tests pass.

Example Before After
http://localhost:8080/dominio http://localhost:8080/dominio/dominio/.well-known/agent-card.json http://localhost:8080/dominio/.well-known/agent-card.json
http://localhost:8080 http://localhost:8080/.well-known/agent-card.json http://localhost:8080/.well-known/agent-card.json (unchanged)

Checklist

  • Code compiles and tests pass
  • Unit tests added/updated
  • No breaking changes
  • Follows project conventions

@tzolov

tzolov commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks @caio-henrique for digging into this! I tested the change against a local HTTP server. With the SDK currently on main (io.github.a2asdk 0.3.3), the one-argument A2A.getAgentCard(url) resolves the default card path against the host root, so for http://host/dominio the request goes to /.well-known/agent-card.json and a custom agentCardPath is ignored. On 0.3.3, main currently requests /dominio/.well-known/agent-card.json correctly. The duplicated segment you describe appears with SDK 1.1.0 (#69), whose card resolver appends the path rather than resolving it. So I'd like to land the URL fix together with #69 and verify it end-to-end there. Also, a test that hits a real local HTTP server would catch this better than mocking A2A statically. I'll follow up on #69.

tzolov added a commit that referenced this pull request Oct 3, 2026
…ative card path

The SDK resolves the card path against the agent URL, so the resolver
prefixes the agent's own path. Normalise the join: a base URL ending in
"/" no longer produces "//" (or fails for "http://host/"), and a card
path without a leading "/" is no longer glued onto the agent path.
Adds A2ASubagentResolverTest, which checks the requested path against a
local HTTP server. Based on the analysis in #70 by @caio-henrique.
@tzolov

tzolov commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks again @caio-henrique — your report led to a real fix. On the current SDK (0.3.3) the default case worked, but a base URL with a trailing slash (including http://host:8080/, which failed outright) and card paths without a leading / produced broken URLs. Fixed in fc4c3ca with a test that checks the requested path against a real local HTTP server, crediting your analysis. The duplicated /dominio/dominio/ segment you saw comes from SDK 1.1.0, so I am tracking it with the migration in #69. Closing this one in favour of that, thanks!

@tzolov tzolov closed this Oct 3, 2026
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