-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(agent_sdk): add A2UIOutputMode enum for unified prompt generation #1466
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,8 +22,11 @@ | |||||||||||||||||||||||
| from .utils import load_from_bundled_resource | ||||||||||||||||||||||||
| from ..inference_strategy import InferenceStrategy | ||||||||||||||||||||||||
| from .constants import * | ||||||||||||||||||||||||
| from .output_mode import A2UIOutputMode | ||||||||||||||||||||||||
| from .catalog import CatalogConfig, A2uiCatalog | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| class A2uiSchemaManager(InferenceStrategy): | ||||||||||||||||||||||||
| """Manages A2UI schema levels and prompt injection.""" | ||||||||||||||||||||||||
|
|
@@ -209,11 +212,48 @@ def generate_system_prompt( | |||||||||||||||||||||||
| include_schema: bool = False, | ||||||||||||||||||||||||
| include_examples: bool = False, | ||||||||||||||||||||||||
| validate_examples: bool = False, | ||||||||||||||||||||||||
| output_mode: A2UIOutputMode = A2UIOutputMode.TEXT, | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of the |
||||||||||||||||||||||||
| ) -> str: | ||||||||||||||||||||||||
| """Assembles the final system instruction for the LLM.""" | ||||||||||||||||||||||||
| """Assembles the final system instruction for the LLM. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||
| role_description: A description of the agent's role. | ||||||||||||||||||||||||
| workflow_description: Additional workflow rules appended to the base | ||||||||||||||||||||||||
| rules. | ||||||||||||||||||||||||
| ui_description: A description of the UI the agent should generate. | ||||||||||||||||||||||||
| client_ui_capabilities: A dictionary of client UI capabilities, used | ||||||||||||||||||||||||
| for catalog selection. | ||||||||||||||||||||||||
| allowed_components: An optional list of component names to include in | ||||||||||||||||||||||||
| the prompt. If None, all components are included. | ||||||||||||||||||||||||
| allowed_messages: An optional list of message names to include in the | ||||||||||||||||||||||||
| prompt. If None, all messages are included. | ||||||||||||||||||||||||
| include_schema: Whether to include the JSON schema in the prompt. | ||||||||||||||||||||||||
| include_examples: Whether to include examples in the prompt. | ||||||||||||||||||||||||
| validate_examples: Whether to validate examples against the schema. | ||||||||||||||||||||||||
| output_mode: Controls how A2UI instructions are delivered. TEXT (default) | ||||||||||||||||||||||||
| injects the schema into the system prompt. TOOL skips schema and | ||||||||||||||||||||||||
| example injection (handled by SendA2uiToClientToolset) and uses | ||||||||||||||||||||||||
| tool-oriented workflow rules. | ||||||||||||||||||||||||
|
Comment on lines
+233
to
+236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring for
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||
| The assembled system prompt string. | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| parts = [role_description] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| workflow = DEFAULT_WORKFLOW_RULES | ||||||||||||||||||||||||
| if output_mode == A2UIOutputMode.TOOL: | ||||||||||||||||||||||||
| if include_schema or include_examples: | ||||||||||||||||||||||||
| logger.warning( | ||||||||||||||||||||||||
| "output_mode=TOOL overrides include_schema and include_examples " | ||||||||||||||||||||||||
| "to False. Schema and examples are injected by " | ||||||||||||||||||||||||
| "SendA2uiToClientToolset.process_llm_request() instead." | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
+245
to
+249
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This warning message explicitly references
Suggested change
|
||||||||||||||||||||||||
| include_schema = False | ||||||||||||||||||||||||
| include_examples = False | ||||||||||||||||||||||||
| base_rules = TOOL_WORKFLOW_RULES | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| base_rules = DEFAULT_WORKFLOW_RULES | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| workflow = base_rules | ||||||||||||||||||||||||
| if workflow_description: | ||||||||||||||||||||||||
| workflow += f"\n{workflow_description}" | ||||||||||||||||||||||||
| parts.append(f"## Workflow Description:\n{workflow}") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||
| # 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. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| """Output mode configuration for A2UI system prompt generation.""" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| from enum import Enum | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| class A2UIOutputMode(Enum): | ||||||||||||||||||||||
| """Controls how A2UI schema and instructions are delivered to the LLM. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Attributes: | ||||||||||||||||||||||
| TEXT: Schema is injected directly into the system prompt via | ||||||||||||||||||||||
| generate_system_prompt(). The LLM outputs A2UI JSON wrapped in | ||||||||||||||||||||||
| <a2ui-json> tags as part of its text response. This is the default. | ||||||||||||||||||||||
| TOOL: Schema is provided via SendA2uiToClientToolset's | ||||||||||||||||||||||
| process_llm_request(). The LLM calls the send_a2ui_json_to_client | ||||||||||||||||||||||
| tool to deliver A2UI JSON. When using this mode, | ||||||||||||||||||||||
| generate_system_prompt() automatically skips schema and example | ||||||||||||||||||||||
| injection to prevent double-injection. | ||||||||||||||||||||||
|
Comment on lines
+27
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring for
Suggested change
|
||||||||||||||||||||||
| """ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| TEXT = "text" | ||||||||||||||||||||||
| TOOL = "tool" | ||||||||||||||||||||||
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.
The tool name
send_a2ui_json_to_clientis hardcoded within the workflow rules string. Defining this as a constant improves maintainability and ensures consistency withDEFAULT_WORKFLOW_RULES, which already uses constants for its tags. This also makes it easier for other components to reference the tool name without re-typing the string.