Skip to content

Initial C++ port of the python agent SDKs#1254

Merged
nan-yu merged 12 commits intogoogle:mainfrom
nan-yu:c++
Apr 23, 2026
Merged

Initial C++ port of the python agent SDKs#1254
nan-yu merged 12 commits intogoogle:mainfrom
nan-yu:c++

Conversation

@nan-yu
Copy link
Copy Markdown
Collaborator

@nan-yu nan-yu commented Apr 21, 2026

Description

Summary of Changes

This pull request introduces a C++ implementation of the agent SDK, enabling C++ applications to interact with A2UI-based agents. The implementation focuses on providing essential schema management, streaming response parsing, and payload validation, mirroring the functionality of the existing Python SDK while omitting packages with external Python dependencies. The changes include a complete build system setup, core library logic, and a suite of tests to ensure protocol conformance.

Highlights

  • C++ SDK Implementation: Introduced a new C++ port of the agent SDK, providing core schema management, parsing, and validation capabilities.

  • Streaming Parser: Added a robust streaming parser for A2UI messages, supporting both v0.8 and v0.9 protocols with built-in deduplication and topology validation.

  • Build System: Configured CMake with FetchContent for dependency management and added a Python script to automate the generation of embedded schemas.

  • Validation Logic: Implemented comprehensive validation for A2UI payloads, including structural integrity checks, recursion limits, and topology verification.

    Note: The C++ version of validator behaves the same way as the Python validator because both pass the same conformance tests. However, they don't have implementation parity. Python relies heavily on external schema definitions, while C++ relies on manual traversal and checks. I tried to use the widely adopted json-schema-validator in C++ to match Python's use of jsonschema. However, the C++ library failed to resolve references like /$defs/anyComponent because it only supports Draft 7 of JSON schema (Draft 2020-12 support: Draft 2020-12 conformance pboettch/json-schema-validator#373), while the A2UI v0.9 spec uses Draft 2020-12 features like $def.

    As of today (April 23, 2026), the only C++ library that specifically lists support for Draft 2020-12 is https://github.com/danielaparker/jsoncons. However, it is not available in the internal Google codebase. Therefore, we decided to stick to the current manual validation approach, which makes the C++ version more lenient on malformed payloads.

  • Exception: The a2a and adk packages are not ported due to external Python dependencies.

    • adk depends on google-adk, which doesn't support C++.
    • a2a depends on a2a-sdk, which provides types like Part, DataPart and TextPart for Agent-to-Agent messaging. There is no official standalone C++ SDK.

    Our downstream customers only require the validation part from the C++ SDK. Therefore, we skip the adk and a2a extension for now.

List which issues are fixed by this PR. For larger changes, raising an issue first helps reduce redundant work.

Pre-launch Checklist

If you need help, consider asking for advice on the discussion board.

Copy link
Copy Markdown
Contributor

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

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 the A2UI C++ SDK, featuring schema management, message validation, and streaming parsing, along with a CMake build system and Python-based schema embedding. Feedback highlights security risks and performance overhead from hardcoded temporary file logging, portability concerns in the CMake configuration, and performance bottlenecks caused by excessive deep copies of JSON structures. Additionally, it is recommended to strengthen validation by raising errors for malformed components.

Comment thread agent_sdks/cpp/src/parser/payload_fixer.cc
Comment thread agent_sdks/cpp/src/parser/streaming_impl.h Outdated
Comment thread agent_sdks/cpp/CMakeLists.txt Outdated
Comment thread agent_sdks/cpp/src/parser/streaming_impl.h Outdated
Comment thread agent_sdks/cpp/src/schema/catalog.cc
Comment thread agent_sdks/cpp/src/schema/validator.cc
@nan-yu
Copy link
Copy Markdown
Collaborator Author

nan-yu commented Apr 22, 2026

/gemini review

@google google deleted a comment from gemini-code-assist Bot Apr 22, 2026
Copy link
Copy Markdown
Contributor

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

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 the initial implementation of the A2UI C++ SDK, providing core functionality for schema management, message validation, and streaming parsing. The changes include a CMake build system, a Python script for embedding JSON schemas, and a comprehensive suite of unit and conformance tests. Review feedback highlights several performance optimization opportunities within the streaming parser, specifically regarding the frequent construction of regex objects and redundant JSON parsing. Additionally, the reviewer recommended using C++17 string_view for global constants and noted an unimplemented method in the template manager that requires attention.

Comment thread agent_sdks/cpp/src/parser/streaming_v08.h Outdated
Comment thread agent_sdks/cpp/src/parser/streaming_impl.h Outdated
Comment thread agent_sdks/cpp/include/a2ui/parser/constants.h Outdated
Comment thread agent_sdks/cpp/src/parser/parser.cc Outdated
Comment thread agent_sdks/cpp/src/parser/streaming.cc Outdated
Comment thread agent_sdks/cpp/src/template/manager.cc
@nan-yu
Copy link
Copy Markdown
Collaborator Author

nan-yu commented Apr 22, 2026

/gemini review

Copy link
Copy Markdown
Contributor

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

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 the C++ SDK for A2UI, featuring a CMake build system, schema management, validation logic, and a streaming parser supporting v0.8 and v0.9 specifications. Feedback focuses on improving code robustness and maintainability: specifically, handling plain text gracefully in the response parser, moving implementation details from headers to source files to optimize build times, using CMake's Python discovery instead of hardcoded commands, and replacing magic numbers and global string constants with more idiomatic C++ alternatives. Consolidating duplicate test helpers was also recommended.

Comment thread agent_sdks/cpp/src/parser/parser.cc
Comment thread agent_sdks/cpp/src/parser/streaming_impl.h
Comment thread agent_sdks/cpp/CMakeLists.txt Outdated
Comment thread agent_sdks/cpp/include/a2ui/basic_catalog/constants.h Outdated
Comment thread agent_sdks/cpp/src/schema/validator.cc Outdated
Comment thread agent_sdks/cpp/tests/schema/test_validator.cc Outdated
@nan-yu
Copy link
Copy Markdown
Collaborator Author

nan-yu commented Apr 22, 2026

CC: @wrenj

Copy link
Copy Markdown
Collaborator

@wrenj wrenj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi nan, i didn't look too closely but as a straight port of the python sdk this works for me. i assume test cases were all ported and cover everything?

@nan-yu
Copy link
Copy Markdown
Collaborator Author

nan-yu commented Apr 22, 2026

hi nan, i didn't look too closely but as a straight port of the python sdk this works for me. i assume test cases were all ported and cover everything?

Yes, most the heavy-lifting logic—specifically the validator and stream parser—has been converted into unified conformance tests for full coverage.

Regarding the schema_manager and catalog tests: they are currently only partially covered. I’m planning to convert these into the conformance test style next. This avoids the overhead of a straight port followed by an immediate refactor.

@nan-yu
Copy link
Copy Markdown
Collaborator Author

nan-yu commented Apr 23, 2026

#1266 covers the remaining tests. I'm going to merge this PR.

@nan-yu nan-yu merged commit b718153 into google:main Apr 23, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in A2UI Apr 23, 2026
@nan-yu nan-yu deleted the c++ branch April 23, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants