Open source  /  Implementation guide

Open-source implementation · A2A Commerce

Build agent-to-agent commerce on open protocols

What this is. A build-it-yourself path to the same outcome, made from open-source parts you host. It does not publish 5 Kings’ internal method, client data, or any third party’s confidential information — and it says plainly where the open-source path is weaker than a specialist service.

In one paragraph

Agent-to-agent commerce means one software agent discovering and transacting with another. The protocol layer is open — A2A for agent-to-agent, MCP for tool access — and both have reference implementations. What is not open is your commercial policy, which is exactly the part you have to decide and publish.

What you end up with

  • A published Agent Card describing what your agent can do, at a stable URL
  • A task endpoint that accepts a request, reports progress and returns a verifiable result
  • A tool surface exposed over MCP with scopes, so an agent can act without holding a password
  • A policy document: what an agent may buy, at what price, with what approval

The reference stack

Every project below is open source and self-hostable. Licences are the ones the project publishes today; check them against your own distribution model before you ship, because a licence can change and an AGPL project has obligations a MIT project does not.

LayerOpen-source projectLicenceWhat it does for you
Agent-to-agent protocolA2A (Agent2Agent)Apache-2.0Agent Card discovery, task lifecycle, streaming updates and artefact return, across vendors.
Tool protocolModel Context Protocol (MCP)MITTyped, scoped tool calls with a standard server SDK, so an agent uses a capability rather than a credential.
Server runtimePython or TypeScript reference SDKsApache-2.0 / MITReference implementations of the task endpoint, card and streaming responses.
Gateway / routerLiteLLM (see the LLM operations guide)MITThe agent's model calls go through your gateway, so the agent's spend is budgeted like any other feature.
IdentityOIDC via KeycloakApache-2.0Agent and user identity with scoped tokens, so 'which agent did this' is answerable.
Trace + auditLangfuseMIT (core)Every task, tool call and model step recorded with the inputs that produced it.
Task queueNATS or Redis StreamsApache-2.0 / RSALv2Long-running tasks with progress events, so the endpoint is not blocked for minutes.

Build it

1. Publish an Agent Card that tells the truth

Skills, input and output modes, auth scheme, and the endpoint. Every capability you list is an interface you will be held to. Listing a capability you cannot complete reliably is worse than listing fewer.

# /.well-known/agent-card.json (shape, excerpt)
{ "name": "catalog-pricing",
  "description": "Returns live price and availability for a SKU",
  "url": "https://example.com/a2a",
  "capabilities": { "streaming": true },
  "skills": [ { "id": "price", "inputModes": ["application/json"],
                "outputModes": ["application/json"] } ] }

2. Make the task lifecycle explicit

Submitted, working, input-required, completed, failed, cancelled. Stream the intermediate states. An agent that waits 90 seconds with no signal is indistinguishable from a hung one, and the calling agent will retry — which is how you get duplicate orders.

3. Expose capabilities over MCP, not credentials

Each tool takes typed arguments and returns typed results, with a scope per tool. The agent never holds a database password or an admin token. This is the single most important security decision in the whole build.

4. Write the commercial policy before the first transaction

What may an agent do without a human: quote? reserve? pay up to what limit? refund? Ship the policy as a document plus an enforcement point in code. ‘The agent decided’ is not an acceptable answer to a finance question.

5. Make every action idempotent and auditable

Idempotency key per task, an append-only audit row per state change, and a trace id that links to the model calls. When an order appears twice, the audit row tells you whether the retry or the agent caused it.

6. Test with two real agents, not a mock

Register your agent as a client of itself and of a partner implementation. The protocol corners that break are almost always streaming, auth refresh and cancellation, none of which a mock exercises.

Acceptance checks

If you cannot verify a claim, it is not a finding. These are the checks that close the work; each one can be run by somebody who did not build it.

Acceptance checkHow to verify it
Agent Card is served and validatesFetch /.well-known/agent-card.json and validate against the A2A schema.
Every task has a terminal stateQuery tasks older than the timeout with no terminal state; must be zero.
Duplicate submission produces one effectPost the same idempotency key twice; assert one order, two audit rows.
Tool calls are scoped, never credentialedGrep the tool implementations for direct credential use; assert they use the scoped token.
Every task is traceable to model stepsTrace id present on 100% of tasks; sample ten traces end to end.
Policy limits are enforced in codeAttempt a transaction above the limit in staging; expect a refusal, not an approval.

Effort and cost

Estimate
Skill neededAdvanced: distributed systems, OAuth/OIDC, and LLM tool calling
Build time3–5 days for a minimal compliant server, 2 weeks for something safe to expose commercially
Running costModel tokens plus infrastructure; the audit and trace store grows with task volume
What you must hostOne 8 GB host for the server + Keycloak + Langfuse; add NATS for long tasks.

What open source does not give you

The honest half of the comparison. Each of these is a reason somebody buys the service instead of building it, and pretending otherwise would make the rest of this page worthless.

  • The protocols are young and still moving. Both A2A and MCP have changed shape during their first year; pin versions and expect migration work.
  • There is no open implementation of the ‘counterparty’ — your agent can talk to another agent, but whether any real merchant’s agent accepts it is a commercial question, not a technical one.
  • Payment rails for agent-initiated transactions are still settling. Card networks, PSPs and banks each treat agent-initiated payments differently, and none of them is fully open source.
  • Autonomy is a risk allocation problem. The code can enforce a limit; deciding the limit is a board decision.
  • Consumer-protection and disclosure rules for automated purchasing vary by jurisdiction and are being written now.

Scope only, stated so you can compare it with the build above.

  • The commercial policy and the autonomy limits, agreed with finance and legal
  • A production-grade task endpoint with idempotency, audit and trace, reviewed against the protocol
  • Integration with your catalogue and pricing so the agent answers with real availability

Sources and further reading

What this page does not include. This guide documents an open-source implementation of the same outcome. It deliberately leaves out 5 Kings’ internal playbooks, client data, vendor terms and unpublished method: we publish what any competent team can reproduce, and we do not publish what belongs to a client or to a contract. Where a step depends on a decision only your business can make, the guide says so instead of guessing.

Take it with you

Build agent-to-agent commerce on open protocols

The full guide as an A4 PDF: the reference stack with licences, the build steps, the acceptance checks and the honest limits — in one file you can hand to an engineer or print for a planning session.

PDF · A4 · no email required · free to redistribute with attribution

Open-source Guides & PDFs