a2a-java icon indicating copy to clipboard operation
a2a-java copied to clipboard

How to scale a A2A production deployment to 100 A2A Server Agents each exposing a different AgentCard?

Open mescaja opened this issue 6 months ago • 11 comments

Say i have an quarkus App that implemented A2A SDK with on AgentExecutor and one AgentCard and i would like to scale this deployment to support a higher number of Server Agents.

the one approach that would work would be to deploy one separate Quarkus app per Agent to kubernetes and proxy the connection with a reverse proxy software creating virtual hosts/ingresses to access the Server Agent endpoint (AgentCard and JSONRPC handler)

https://a2a-server-agent-1/.well-known/agent-card.json
https://a2a-server-agent-2/.well-known/agent-card.json
etc

I think that's a lot overhead running a separate quarkus app per agent

is there any best practices in terms of setting up just one single quarkus app supporting multiple AgentCards and JSONRPC Handler endpoints?

is there any reference architecture for a typical A2A production deployment?

mescaja avatar May 26 '26 15:05 mescaja

I provided a way to scale A2A Server Agents in a production system in the ticket https://github.com/a2aproject/a2a-java/issues/945

having a 1:1 Agent to kubernetes images is in m view too much overhead so that's my proposal for a multi agent platform production deployment.

it'd be nice if others can add their views into this topic. I think any organization will face this dilemma sooner or later as the need to deploy higher number of agents becomes a requirement.

mescaja avatar Jun 25 '26 11:06 mescaja

The "is there any best practices" part of this question now has an official answer that did not exist when it was filed: the spec added Multi-Tenancy and Multi-Agent Routing.

It sanctions three routing approaches (URL sub-path, authentication header, and the tenant field), is explicit that the tenant value may carry agent identifiers, and is equally explicit about discovery:

When multiple agents are deployed behind a shared domain, each agent SHOULD have its own Agent Card published at an appropriate location.

So the deployment pattern described here is the recommended one, not a workaround. The gap is on the SDK side, and it is narrower than it first looks. Checked against 1.2.0.Final:

Endpoint Tenant-aware?
REST: message:send, message:stream, tasks, tasks/{id}, :cancel, :subscribe, the four pushNotificationConfigs routes, extendedAgentCard yes, all eleven use ^\/(?<tenant>[^\/]*\/?)…
REST: /.well-known/agent-card.json no, plain router.get(...)
JSON-RPC: POST / and /.well-known/agent-card.json no, see #1034

The asymmetry inside REST is the striking part: every route carries a tenant group except the one used for discovery. An agent can already serve a per-tenant extended card while its public card, the one clients actually fetch first, is shared.

Two concrete things would unblock the documented pattern:

  1. Make the public Agent Card endpoint tenant-aware, exactly the way extendedAgentCard already is in the REST binding.
  2. Allow more than one @PublicAgentCard AgentCard, keyed by tenant. Today the handlers take it as a single-valued constructor parameter, so an application that declares two such beans has an ambiguous dependency between its own beans. Note this is not caused by the SDK's own producer: DefaultProducers.createDefaultAgentCard is @DefaultBean and correctly yields to the application's. A qualifier, a Map<String, AgentCard>, or an AgentCardResolver SPI would each work.

Happy to help with this. I am building an A2A server extension for Quarkus LangChain4j on top of the SDK, and multiple agents per application is the next thing it needs. If a maintainer indicates a preferred direction for (2), I can contribute a PR.

omatheusmesmo avatar Aug 10 '26 01:08 omatheusmesmo

@omatheusmesmo thanks for the above.

i managed to work around the issue slightly differently.

  1. created multiple agent card rest resources in the A2A Server quarkus app with the @PathParam("agent")

/{tenant}/{agent}/.well-known/agent-card.json

  1. Store the agent cards Json in the database table so the rest resource can access it

  2. passing the agent using A2AMessage metadata so the A2A Server agent is aware of which agent each call is referring to.

so essentially if i had 100 local agents (running the LangChain/LangGraphs stuff), i would still deploy only 1 A2A Server agent that is able to fetch all 100 Agent cards from the database.

Scaling the A2A Agent is done by

  • increasing replica in kubernetes deployment for the same tenant
  • each tenant deploy its own A2A Server agent in a separate kubernates namespace for isolation.

All working fine in a multi agent platform as far as i can see.

mescaja avatar Aug 10 '26 12:08 mescaja

@omatheusmesmo so basically you would want to 'map' a card to a tenant in some kind of registry. As far as I understood the public agent card doesn't have to live on the agent itself and our client should be able to target any URL to get the public agent card. Maybe this is what you should have as an 'extras' in the SDK to provide a registry of public agent card

ehsavoie avatar Aug 12 '26 08:08 ehsavoie

what you should have as an 'extras' in the SDK t

@ehsavoie that's correct, you can have a separate Quarkus app that servers all A2A public agent card. It does not even have to import the A2A java sdk at all if you use the database based approach i went for.

I guess, companies may end up centralizing all Agent Cards (corporate and third party one) in one single place. This becomes really handy when implementing semantic routing pattern for instance, a handoff agent can work out dynamically at runtime the best agent for the prompt by checking the skills across all agent cards and pick the most suitable one.

For me, i don't think we need to add anything to the A2A java SDK. Agent Card management should be done elsewhere and not necessarily using the SDK.

I raised this ticket a while a go when i started thinking about these scenarios. Having implemented pretty much all patterns now, i have a clear picture on how i would deploy A2A agents at scale.

mescaja avatar Aug 12 '26 09:08 mescaja

what you should have as an 'extras' in the SDK t

@ehsavoie that's correct, you can have a separate Quarkus app that servers all A2A public agent card. It does not even have to import the A2A java sdk at all if you use the database based approach i went for.

I guess, companies may end up centralizing all Agent Cards (corporate and third party one) in one single place. This becomes really handy when implementing semantic routing pattern for instance, a handoff agent can work out dynamically at runtime the best agent for the prompt by checking the skills across all agent cards and pick the most suitable one.

For me, i don't think we need to add anything to the A2A java SDK. Agent Card management should be done elsewhere and not necessarily using the SDK.

I raised this ticket a while ago when i started thinking about these scenarios. Having implemented pretty much all patterns now, i have a clear picture on how i would deploy A2A agents at scale and the SDK is fit for purpose as is

mescaja avatar Aug 12 '26 09:08 mescaja

Thanks @ehsavoie and @mescaja, both replies helped.

@ehsavoie you were right that the public card does not have to live on the agent. Section 8.2 lists Registries/Catalogs as one of the three discovery mechanisms, so an extras registry lines up with the spec.

@mescaja your database backed cards behind a path param are Direct Configuration from that same section. Good to see it holding up at that number of agents.

That also kills the point I raised earlier: .well-known/agent-card.json is origin scoped per RFC 8615, so a tenant prefixed variant is not a well-known URI at all. The public card route having no tenant is correct. I was wrong.

One thing a registry does not reach. The handlers decide whether an operation is allowed by reading the single resolved card:

if (!resolveAgentCard().capabilities().streaming()) { ... }
if (!resolveAgentCard().capabilities().pushNotifications()) { ... }
if (!resolveAgentCard().capabilities().extendedAgentCard()) { ... }

So N agents in one app share capabilities and protocol versions regardless of tenant. Intended, or worth its own issue?

omatheusmesmo avatar Aug 14 '26 20:08 omatheusmesmo

I've not totally been following this discussion, but it feels a bit like that it should be possible to have more than one AgentCard for these multi-agent cases?

Even if it comes from an external registry, we could provide some kind of producer that can load up the associated AgentCard instance from a configured remote URL.

Then the handler could use the proper AgentCard to validate the capabilities etc. of the actual AgentCard. I think @omatheusmesmo 's point is that at the moment the validation comes from the one AgentCard currently resolved?

This is at the 'notes on the back of a napkin' stage, so I don't know exactly how this would look :-) but we might be able to do something with Qualifiers in AgentCardValidator.resolveAndValidateOnce(). Or some other discriminator for non-CDI users.

Or alternatively we could figure out the AgentCard at the endpoint level, and pass it in to the transport/* handlers?

kabir avatar Aug 18 '26 13:08 kabir

@omatheusmesmo @mescaja I have merged the support for multi tenancy, enabling the support of multiple agents and agent cards on the same runtime. Please take a look

ehsavoie avatar Aug 25 '26 19:08 ehsavoie

https://a2aproject.github.io/a2a-java/dev/multi-tenancy/

ehsavoie avatar Aug 26 '26 19:08 ehsavoie

Closing since I think this is done now

kabir avatar Sep 14 '26 10:09 kabir