Skip to content

[Feature]: Add production-oriented examples and starter applications (Examples 2.0) #251

Closed

Description

@MisterVVP

Proposal

Context

The repository already has a useful set of small, deterministic examples under examples/apps/:

  • hello_agent
  • simple_client
  • rest_server
  • json_rpc_server
  • grpc_server
  • streaming_client
  • streaming_server
  • push_notifications
  • auth_policy_server

These examples are valuable as focused SDK demonstrations and CI regression coverage. They should remain small and deterministic.

After the v0.5.0 release, the larger usability gap is different: a new user still has to translate these focused demonstrations into the structure of a real application.

The SDK should also provide a small number of production-oriented starter projects that demonstrate how an external C++ application would actually consume and use a2a-cpp:

  • separate client and server processes;
  • real localhost networking rather than only in-process calls;
  • public installed SDK APIs only;
  • Agent Card discovery;
  • normal configuration and error handling;
  • streaming and cancellation;
  • clean process lifecycle;
  • standalone downstream CMake consumption;
  • Linux containerization with Docker from the start.

The goal of "Examples 2.0" is therefore not to replace the current examples. It is to add a second, more realistic layer on top of them.

Containerization is part of the tutorial contract rather than a later deployment add-on. Each production-oriented tutorial should be runnable both directly on the host and in Linux containers.

Goal

Add production-oriented, copyable starter applications that demonstrate an idiomatic downstream a2a-cpp project while preserving the existing focused examples as fast CI/regression fixtures.

A developer should be able to copy a tutorial directory outside this repository, point it at an installed a2a-cpp package, build it with CMake, start the server in one terminal, and run the client in another terminal.

Proposed structure

Keep the current focused examples:

examples/
  apps/
    hello_agent/
    simple_client/
    rest_server/
    json_rpc_server/
    grpc_server/
    streaming_client/
    streaming_server/
    push_notifications/
    auth_policy_server/

Add a separate tutorial/starter layer:

examples/
  tutorials/
    networked_agent/
      CMakeLists.txt
      Dockerfile
      docker-compose.yml
      README.md
      server.cpp
      client.cpp

    streaming_agent/
      CMakeLists.txt
      Dockerfile
      docker-compose.yml
      README.md
      server.cpp
      client.cpp

The exact directory names may change if a clearer structure emerges during implementation, but focused regression examples and production-oriented tutorials should remain conceptually separate.

Scope

1. Preserve the existing focused examples

Do not rewrite the current examples/apps/* suite into large applications.

The existing examples should remain:

  • small;
  • deterministic;
  • fast;
  • independently understandable;
  • suitable for CI;
  • useful for demonstrating one SDK concept at a time.

Refactoring shared build infrastructure is acceptable when it clearly reduces duplication, but this task should not turn the existing examples into wrappers around a large common framework.

2. Add networked_agent

Add a minimal but realistic two-process A2A application.

The example should contain at least:

server.cpp
client.cpp
CMakeLists.txt
README.md

The server and client must run as separate operating-system processes and communicate over localhost using production SDK networking.

Example usage should look approximately like:

cmake -S examples/tutorials/networked_agent \
  -B build-networked-agent \
  -DCMAKE_PREFIX_PATH=<a2a-cpp-install-prefix>

cmake --build build-networked-agent --parallel

Terminal 1:

./build-networked-agent/a2a_networked_server

Terminal 2:

./build-networked-agent/a2a_networked_client http://127.0.0.1:8080

The exact executable names are not important.

Server requirements

The server should demonstrate:

  • construction of an Agent Card;
  • one supported production transport;
  • registration of an AgentExecutor;
  • normal task/message handling;
  • deterministic task completion;
  • real network listener setup;
  • useful startup and error messages;
  • graceful shutdown;
  • bounded/deterministic shutdown in CI.

Use a simple deterministic agent behavior such as echoing or transforming input locally. Do not require an LLM, API key, cloud service, database, or internet access.

Client requirements

The client should demonstrate:

  • discovery of the server's Agent Card from its URL;
  • creation/configuration of A2AClient using public SDK APIs;
  • sending a message;
  • handling the returned task/result;
  • structured error handling;
  • clean client shutdown.

The normal path should not manually construct private transport internals that ordinary SDK consumers do not need.

3. Add streaming_agent

Add a second two-process starter focused on streaming.

It may share small internal example-only utilities with networked_agent when that keeps the code clearer, but each tutorial should remain understandable by reading its own README and sources.

The streaming tutorial should demonstrate:

  • SendStreamingMessage;
  • StreamObserver;
  • receiving multiple events;
  • terminal completion;
  • StreamHandle lifetime;
  • cancellation;
  • clean shutdown.

Where practical, also demonstrate task resubscription through SubscribeTask, but do not make the example substantially more complex solely to cover every streaming feature.

The application must not use test-only stream requesters or private SDK hooks.

4. Use public SDK APIs only

The tutorials are intended to model downstream application code.

They must therefore:

  • include only installed/public headers;
  • link only exported public CMake targets such as a2a::client, a2a::server, and a2a::core;
  • avoid src/** includes;
  • avoid test helpers;
  • avoid private transport constructors when a public factory exists;
  • avoid depending on repository-internal implementation details.

A tutorial directory copied outside the repository should remain buildable against an installed SDK package.

5. Make the tutorials standalone downstream CMake projects

Each tutorial should have its own CMakeLists.txt.

Primary consumption should use:

find_package(a2a_cpp CONFIG REQUIRED)

and public imported targets.

CI should validate the tutorials against an SDK installed from the current repository build so the test exercises the same path as a real downstream consumer.

Do not rely only on building tutorial sources as part of the top-level SDK CMake project.

If a FetchContent variant is documented, keep it secondary and pin it to a release tag or reviewed commit rather than main.

6. Keep configuration simple and explicit

Do not introduce a large configuration framework or CLI dependency just for examples.

Use simple command-line options or arguments for values such as:

  • server URL;
  • host;
  • port;
  • selected transport when applicable.

Defaults should work for local development.

Avoid unnecessary abstraction. Example code should optimize for clarity while still demonstrating production-safe lifecycle and error handling.

7. Use deterministic readiness instead of sleeps

CI and example scripts must not rely on arbitrary sleeps such as:

sleep 2

to guess when the server is ready.

Use a deterministic readiness mechanism, for example:

  • wait until the listening socket accepts connections;
  • poll the Agent Card endpoint with a bounded deadline;
  • expose a small process-ready signal appropriate for the example runner.

All waits must be bounded.

8. Add tutorial smoke automation

Extend the example validation tooling or add a focused tutorial runner that can:

  1. install/build the current SDK;
  2. configure the standalone tutorial project;
  3. build it;
  4. start the server;
  5. wait deterministically for readiness;
  6. run the client;
  7. verify successful output/exit status;
  8. terminate the server cleanly;
  9. fail on timeout or unexpected process exit.

At minimum, automate the happy path for:

  • networked_agent;
  • streaming_agent.

The runner must clean up child processes even when the client/test fails.

9. Add Linux Docker support for each tutorial

Each production-oriented tutorial must include a Linux container workflow from the first version.

At minimum, provide:

Dockerfile
docker-compose.yml

or an equivalent Compose file name supported by current Docker Compose.

The containerized tutorial should preserve the same application behavior as the host-native tutorial rather than introducing a separate implementation.

Docker requirements

  • Use Linux containers only for this task.
  • Prefer a multi-stage build so compilers, CMake, and package-build dependencies are not required in the final runtime image unless they are genuinely needed.
  • Build against the public/installable SDK surface, not private repository source paths.
  • Keep the runtime image reasonably small and explicit.
  • Run the application as a non-root user unless there is a documented reason not to.
  • Do not bake credentials, tokens, or developer-specific paths into images.
  • Do not require privileged containers.
  • Do not mount the Docker socket.
  • Do not use host networking as the normal tutorial path.
  • Expose only the port(s) required by the tutorial.
  • Use service names / Compose networking for client-to-server communication inside the containerized flow.
  • Pin base-image major/minor versions rather than using an unbounded latest tag where practical.
  • Keep Dockerfiles readable and suitable for copying into a downstream project.

networked_agent container flow

The documented container path should be approximately:

docker compose up --build --abort-on-container-exit

or another simple, deterministic command.

The Compose topology should resemble:

client container
      |
      | A2A
      v
server container

The client must reach the server through the Compose network using the server service name rather than localhost.

The server should still expose its port to the host so users can inspect or call it manually.

streaming_agent container flow

The streaming tutorial must also work across separate Linux containers and demonstrate that streaming, completion, and cancellation work through container networking.

Do not replace real streaming with an in-process shortcut for the Docker path.

Container readiness and shutdown

Compose orchestration must not rely on arbitrary sleeps.

Prefer a health check or bounded readiness probe based on the Agent Card endpoint or another deterministic service-ready condition.

Container shutdown should exercise normal application termination rather than relying solely on force-killing the process.

10. Add Docker smoke validation

CI should validate at least the Linux container happy path for both tutorials.

The container smoke flow should:

  1. build the tutorial image(s);
  2. start the server container;
  3. wait for deterministic health/readiness;
  4. run the client container;
  5. verify the expected result/events;
  6. verify clean completion;
  7. tear down all containers/networks;
  8. fail if containers remain running or the flow times out.

Use bounded timeouts throughout.

Docker validation may be Linux-only even though the native examples continue to build on Linux, macOS, and Windows.

Do not make Windows container or macOS container-runtime behavior part of this issue.

11. Keep tutorial code suitable for copying

The tutorial applications should represent code that we would be comfortable seeing copied into a real downstream project.

In particular:

  • follow AGENTS.md, cpp_conventions.md, and the Google C++ Style Guide;
  • use clear ownership and RAII;
  • keep shutdown deterministic;
  • avoid detached threads;
  • avoid unbounded waits;
  • avoid unnecessary global state;
  • avoid magic strings/numbers where repository rules require named constants;
  • propagate/report errors instead of silently ignoring them;
  • keep helper functions and test code below the repository clang-tidy cognitive-complexity threshold.

Do not intentionally simplify lifecycle management in a way that teaches an unsafe pattern.

12. Improve example documentation/navigation

Update the example documentation so users can clearly distinguish between:

Focused examples

Small demonstrations intended to explain one SDK capability.

Tutorials / starter applications

Larger, standalone, copyable projects intended to show how a real application is structured.

Update as appropriate:

  • README.md;
  • examples/README.md;
  • examples/apps/README.md;
  • the getting-started quickstart;
  • relevant mdBook navigation/pages.

The top-level README should point new users to the production-oriented starter after the smallest hello_agent quickstart.

13. Document the progression for new users

The documentation should provide an obvious learning path, for example:

hello_agent
    ↓
networked_agent
    ↓
streaming_agent
    ↓
push/auth/storage-specific focused examples

A newcomer should not need to inspect the repository tree to determine what to run next.

Design guidance

Prefer one excellent reference path over broad duplication

Do not create separate production tutorials for REST, JSON-RPC, and gRPC just to demonstrate all transports.

The first version should choose one clear default transport for the main tutorial and keep transport-specific focused examples for the rest.

If switching transport can be added with a small, readable abstraction, that is acceptable. Do not turn the tutorial into a transport framework.

Keep external-service dependencies out

The starter applications must remain useful without:

  • OpenAI/LLM credentials;
  • cloud accounts;
  • PostgreSQL;
  • Redis;
  • third-party web APIs;
  • internet access at runtime.

Docker is intentionally supported, but it must remain an optional execution/deployment path rather than the only way to run the tutorials. The host-native CMake flow must continue to work independently.

Storage-backed or LLM-backed starter applications can be added later as separate examples.

Treat API friction as feedback

If implementing the tutorials exposes awkward public SDK ergonomics:

  1. document the issue;
  2. prefer a small follow-up issue for API changes;
  3. do not silently add substantial new public APIs merely to make the example prettier.

One purpose of this work is to exercise v0.5.x as a real SDK consumer before designing larger new public surfaces such as the asynchronous API.

Non-goals

This issue does not include:

  • replacing the existing focused examples;
  • adding the asynchronous API from [Enhancement]: Add opt-in async server streaming and gRPC callback support #169;
  • redesigning the current synchronous client/server APIs;
  • adding Redis or MongoDB stores;
  • requiring PostgreSQL;
  • adding real LLM integrations;
  • adding cloud deployment examples;
  • Kubernetes deployment;
  • Windows containers;
  • multi-architecture container publishing;
  • pushing tutorial images to a public container registry;
  • implementing an application framework on top of a2a-cpp;
  • duplicating the same tutorial for every transport;
  • changing A2A protocol behavior;
  • changing performance benchmark semantics.

Acceptance criteria

  • Existing examples/apps/* examples remain available and operational.
  • A new production-oriented tutorial/starter area exists separately from the focused examples.
  • networked_agent runs client and server as separate processes over real localhost networking.
  • networked_agent demonstrates Agent Card discovery through public APIs.
  • networked_agent demonstrates a complete message/task flow.
  • streaming_agent runs client and server as separate processes.
  • streaming_agent demonstrates production streaming with StreamObserver and StreamHandle.
  • Streaming completion and cancellation are demonstrated without unbounded waits.
  • Tutorial code uses only installed/public SDK headers and exported CMake targets.
  • Each tutorial is a standalone downstream CMake project using find_package(a2a_cpp CONFIG REQUIRED).
  • CI builds tutorials against an installed package produced from the current repository revision.
  • A tutorial directory can be copied outside the repository and built without repository-private source paths.
  • Tutorial smoke tests use deterministic bounded server readiness rather than arbitrary sleeps.
  • Tutorial smoke automation cleans up child processes reliably on success and failure.
  • Each production-oriented tutorial includes a Linux Dockerfile and Docker Compose workflow.
  • Docker builds use the public/installable SDK surface rather than private repository source paths.
  • Tutorial server and client communicate successfully as separate containers over a Compose network.
  • Docker readiness uses a deterministic bounded health/readiness mechanism rather than arbitrary sleeps.
  • Docker container shutdown is clean and bounded.
  • Docker runtime images do not require privileged mode or embedded credentials.
  • Linux CI validates the containerized happy path for both tutorials.
  • Host-native tutorial execution remains supported independently of Docker.
  • No tutorial requires credentials, external services, or internet access at runtime.
  • README/quickstart documentation clearly distinguishes focused examples from starter/tutorial applications.
  • The documented onboarding path leads from hello_agent to the networked and streaming tutorials.
  • Existing focused example CI remains green.
  • No intentional public SDK API changes are introduced as part of this issue unless separately justified and reviewed.

Validation

Follow all repository requirements in AGENTS.md.

At minimum:

./scripts/run_clang_format.sh

mapfile -t CPP_FILES < <(git ls-files '*.h' '*.hpp' '*.c' '*.cpp')
if [ "${#CPP_FILES[@]}" -gt 0 ]; then
  clang-format --dry-run --Werror "${CPP_FILES[@]}"
fi

./scripts/verify_changes.sh
./scripts/run_clang_tidy.sh build
mdbook build book

Run all existing examples:

./scripts/run_examples.sh

Run the new host-native tutorial smoke flow and verify:

  • server starts with a bounded readiness check;
  • client completes successfully;
  • streaming client receives expected events;
  • cancellation terminates promptly;
  • no child process is leaked;
  • all processes exit cleanly.

Run the Linux Docker tutorial smoke flow and verify:

docker compose build
docker compose up --abort-on-container-exit
docker compose down --volumes --remove-orphans

or the repository's equivalent wrapper.

Verify:

  • images build successfully;
  • readiness is deterministic and bounded;
  • client and server communicate over the Compose network;
  • the streaming tutorial receives the expected events;
  • containers exit cleanly;
  • cleanup leaves no tutorial containers or networks behind.

Run the mandatory A2A TCK flow required by AGENTS.md and confirm 100% compliance for executed mandatory requirements.

CI should remain green on supported Linux, macOS, and Windows configurations.

Expected outcome

After this work, a2a-cpp should provide two complementary example layers:

Focused examples
    ↓
small / deterministic / capability-specific / CI-friendly

Production-oriented tutorials
    ↓
networked / standalone / public-API-only / copyable / container-ready

A new user should be able to go from cloning or installing the SDK to running a real client/server A2A application without first reverse-engineering the test infrastructure or combining several small examples manually.

This also gives the project a realistic consumer workload that can expose public API ergonomics before larger API additions such as #169.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationenhancement

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions