-
Notifications
You must be signed in to change notification settings - Fork 806
Update contact lookup sample #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nan-yu
wants to merge
3
commits into
google:main
Choose a base branch
from
nan-yu:update-contact-lookup-sample
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src/a2ui/assets/**/*.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import os | ||
| import shutil | ||
| import sys | ||
| from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
|
||
|
|
||
| class PackSpecsBuildHook(BuildHookInterface): | ||
|
|
||
| def initialize(self, version, build_data): | ||
| project_root = self.root | ||
|
|
||
| # Add src to sys.path to import the constant | ||
| src_path = os.path.join(project_root, "src") | ||
| if src_path not in sys.path: | ||
| sys.path.insert(0, src_path) | ||
|
|
||
| from a2ui.inference.schema.manager import ( | ||
| SPEC_VERSION_MAP, | ||
| A2UI_ASSET_PACKAGE, | ||
| SPECIFICATION_DIR, | ||
| find_repo_root, | ||
| ) | ||
|
|
||
| # project root is in a2a_agents/python/a2ui_agent | ||
| # Dynamically find repo root by looking for SPECIFICATION_DIR | ||
| repo_root = find_repo_root(project_root) | ||
| if not repo_root: | ||
| # Check for PKG-INFO which implies a packaged state (sdist). | ||
| # If PKG-INFO is present, trust the bundled assets. | ||
| if os.path.exists(os.path.join(project_root, "PKG-INFO")): | ||
| print("Repository root not found, but PKG-INFO present (sdist). Skipping copy.") | ||
| return | ||
|
|
||
| raise RuntimeError( | ||
| f"Could not find repository root (looked for '{SPECIFICATION_DIR}'" | ||
| " directory)." | ||
| ) | ||
|
|
||
| # Target directory: src/a2ui/assets | ||
| target_base = os.path.join( | ||
| project_root, "src", A2UI_ASSET_PACKAGE.replace(".", os.sep) | ||
| ) | ||
|
|
||
| for ver, schema_map in SPEC_VERSION_MAP.items(): | ||
| target_dir = os.path.join(target_base, ver) | ||
| os.makedirs(target_dir, exist_ok=True) | ||
|
|
||
| for _schema_key, source_rel_path in schema_map.items(): | ||
| source_path = os.path.join(repo_root, source_rel_path) | ||
|
|
||
| if not os.path.exists(source_path): | ||
| print( | ||
| f"WARNING: Source schema file not found at {source_path}. Build might" | ||
| " produce incomplete wheel if not running from monorepo root." | ||
| ) | ||
| continue | ||
|
|
||
| filename = os.path.basename(source_path) | ||
| dst_file = os.path.join(target_dir, filename) | ||
|
|
||
| print(f"Copying {source_path} -> {dst_file}") | ||
| shutil.copy2(source_path, dst_file) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright 2026 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. | ||
|
|
||
| from typing import Any, Dict | ||
| import jsonschema | ||
|
|
||
|
|
||
| class A2uiValidator: | ||
| """ | ||
| Validates JSON instances against a bundled A2UI schema. | ||
| """ | ||
|
|
||
| def __init__(self, schema: Dict[str, Any]): | ||
| self._validator = jsonschema.validators.validator_for(schema)(schema) | ||
|
|
||
| def validate(self, instance: Any) -> None: | ||
| """ | ||
| Validates the given instance against the bundled schema. | ||
| Raises jsonschema.exceptions.ValidationError if validation fails. | ||
| """ | ||
| self._validator.validate(instance) |
13 changes: 13 additions & 0 deletions
13
a2a_agents/python/a2ui_agent/src/a2ui/inference/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2026 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. |
33 changes: 33 additions & 0 deletions
33
a2a_agents/python/a2ui_agent/src/a2ui/inference/inference_strategy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Copyright 2026 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. | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from typing import List | ||
|
|
||
|
|
||
| class InferenceStrategy(ABC): | ||
|
|
||
| @abstractmethod | ||
| def generate_system_prompt( | ||
| self, | ||
| role_description: str, | ||
| workflow_description: str = "", | ||
| ui_description: str = "", | ||
| selected_components: List[str] = [], | ||
| examples: str = "", | ||
| ) -> str: | ||
| """ | ||
| Abstract method to be implemented by subclasses. | ||
| """ | ||
| pass |
13 changes: 13 additions & 0 deletions
13
a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2026 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. |
69 changes: 69 additions & 0 deletions
69
a2a_agents/python/a2ui_agent/src/a2ui/inference/schema/loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Copyright 2026 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. | ||
|
|
||
| import json | ||
| import os | ||
| import importlib.resources | ||
| from typing import List, Dict, Any | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| ENCODING = "utf-8" | ||
|
|
||
|
|
||
| class A2uiSchemaLoader(ABC): | ||
| """Abstract base class for loading schema files.""" | ||
|
|
||
| @abstractmethod | ||
| def load(self, filename: str) -> Any: | ||
| """Loads a JSON file.""" | ||
| pass | ||
|
|
||
|
|
||
| class FileSystemLoader(A2uiSchemaLoader): | ||
| """Loads schema files from the local filesystem. | ||
|
|
||
| This loader assumes that all referenced schema files are located in the | ||
| same flat directory structure. | ||
| """ | ||
|
|
||
| def __init__(self, base_dir: str): | ||
| self.base_dir = base_dir | ||
|
|
||
| def load(self, filename: str) -> Any: | ||
| path = os.path.join(self.base_dir, filename) | ||
| with open(path, "r", encoding=ENCODING) as f: | ||
| return json.load(f) | ||
|
|
||
|
|
||
| class PackageLoader(A2uiSchemaLoader): | ||
| """Loads schema files from package resources. | ||
|
|
||
| This loader assumes that all referenced schema files are located in the | ||
| same flat package structure. | ||
| """ | ||
|
|
||
| def __init__(self, package_path: str): | ||
| self.package_path = package_path | ||
|
|
||
| def load(self, filename: str) -> Any: | ||
| try: | ||
| traversable = importlib.resources.files(self.package_path) | ||
| resource_path = traversable.joinpath(filename) | ||
| with resource_path.open("r", encoding=ENCODING) as f: | ||
| return json.load(f) | ||
| except Exception as e: | ||
| raise IOError( | ||
| f"Could not load package resource {filename} in {self.package_path}: {e}" | ||
| ) from e |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modifying
sys.pathdirectly, especially in a build script, is generally discouraged as it can lead to unpredictable behavior and make the build process fragile. A more robust approach would be to avoid this manipulation. Consider refactoring the shared constants (SPEC_VERSION_MAP, etc.) into a separate, simple configuration file (e.g., a JSON file or a simple Python file at the project root) that can be accessed by both the build hook and the runtime code without path manipulation.