Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions a2a_agents/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
46 changes: 46 additions & 0 deletions a2a_agents/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.14)
project(A2UI_CPP_Agent)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

include(FetchContent)

# nlohmann/json
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(nlohmann_json)

# pboettch/json-schema-validator
FetchContent_Declare(
nlohmann_json_schema_validator
GIT_REPOSITORY https://github.com/pboettch/json-schema-validator.git
GIT_TAG 2.3.0
)
FetchContent_MakeAvailable(nlohmann_json_schema_validator)

# GoogleTest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

# library: a2ui_validation
add_library(a2ui_validation src/validation.cpp)
target_include_directories(a2ui_validation PUBLIC include)
target_link_libraries(a2ui_validation PUBLIC nlohmann_json::nlohmann_json nlohmann_json_schema_validator)

# executable: test_validation
enable_testing()
add_executable(test_validation tests/test_validation.cpp)
target_link_libraries(test_validation PRIVATE a2ui_validation GTest::gtest_main GTest::gmock)

include(GoogleTest)
gtest_discover_tests(test_validation)
40 changes: 40 additions & 0 deletions a2a_agents/cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# A2UI C++ Agent implementation

The `a2a_agents/cpp/` directory contains the C++ implementation of the A2UI agent library.

## Components

The library provides validation logic for A2UI protocol messages:

* **`a2ui_validation`**: A library for validating A2UI JSON messages against the schema and semantic rules.
* Header: `include/a2ui/validation.hpp`
* Source: `src/validation.cpp`

## Running tests

The project uses CMake and GoogleTest.

1. Navigate to the C++ agent directory:
```bash
cd a2a_agents/cpp
```

2. Create a build directory and configure:
```bash
mkdir -p build
cd build
cmake ..
```

3. Build and run the tests:
```bash
make
./test_validation
```

## Dependencies

The following dependencies are automatically fetched via CMake `FetchContent`:
* [nlohmann/json](https://github.com/nlohmann/json): JSON for Modern C++
* [pboettch/json-schema-validator](https://github.com/pboettch/json-schema-validator): JSON Schema Validator for JSON for Modern C++
* [GoogleTest](https://github.com/google/googletest): Google Testing and Mocking Framework
53 changes: 53 additions & 0 deletions a2a_agents/cpp/include/a2ui/validation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <nlohmann/json.hpp>

namespace a2ui {

/**
* Validates the A2UI JSON payload against the provided schema and checks for integrity.
*
* The payload can be a single message object or an array of message objects.
*
* Note: Does not support streaming or partial messages.
* TODO: Support streaming.
*
* Checks performed:
* 1. **JSON Schema Validation**: Ensures payload adheres to the A2UI schema.
* 2. **Component Integrity**:
* - All component IDs are unique.
* - A 'root' component exists.
* - All unique component references point to valid IDs.
* 3. **Topology**:
* - No circular references (including self-references).
* - No orphaned components (all components must be reachable from 'root').
* 4. **Recursion Limits**:
* - Global recursion depth limit (50).
* - FunctionCall recursion depth limit (5).
* 5. **Path Syntax**:
* - Validates JSON Pointer syntax for data paths.
*
* @param a2ui_json The JSON payload to validate.
* @param a2ui_schema The schema to validate against.
*
* @throws std::invalid_argument If integrity, topology, or recursion checks fail, or if payload does not match schema.
*/
void validate_a2ui_json(const nlohmann::json& a2ui_json, const nlohmann::json& a2ui_schema);

} // namespace a2ui
Loading
Loading