AI agents autonomously perceive their environment, reason, and execute complex,
multi-step actions to achieve a defined goal. In this tutorial, you deploy a
basic AI agent that returns static profile information retrieved from a tool.
A2UI enables AI agents to generate adaptive, rich, interactive UIs that render
natively. You can then focus on the logic of the AI agents, not the UIs.
The A2UI agent responds to the user with a message with text and a card containing the profile name, image, and LinkedIn button.
Figure 1. The A2UI agent responds to the user with text and a card containing the name, image, and LinkedIn button.
The A2UI agent is updated to return the profile title as well.
Figure 2. The A2UI agent is updated to return the profile title as well.
The A2UI agent responds to the user with a message that displays the profile name in the card.
Figure 3. The A2UI agent responds to the user with a message that displays the profile name in the card.
The following diagram shows the architecture and messaging pattern:
Architecture of a Chat app implemented with an A2UI AI agent.
In the diagram, a user interacting with a
Chat app implemented with an A2UI agent has
the following flow of information:
A user sends a message to a Chat app, either in a
direct message or in a Chat space.
The Chat app logic that's implemented either in
Apps Script or as a web server with HTTP endpoints receives
and processes the message.
The A2UI agent hosted with Vertex AI Agent Engine receives and processes
the interaction.
Optionally, the Chat app or AI agent can integrate
with Google Workspace services, such as Calendar or
Sheets, or other Google services, such as Google Maps
or YouTube.
The Chat app generates and sends adaptive responses
asynchronously, using the Google Chat API to communicate the AI agent's
progress.
All apps using OAuth 2.0 require a consent screen configuration. Configuring
your app's OAuth consent screen defines what is displayed to users and app
reviewers, and registers your app so you can publish it later.
In the Google API Console, go to Menu menu>Google Auth platform>Branding.
If you have already configured the Google Auth platform, you can configure the following OAuth Consent Screen settings in Branding, Audience, and Data Access. If you see a message that says Google Auth platform not configured yet, click Get Started:
Under App Information, in App name, enter a name for the app.
In User support email, choose a support email address where users can contact you if they have questions about their consent.
Click Next.
Under Audience, select Internal.
Click Next.
Under Contact Information, enter an Email address where you can be notified about any changes to your project.
For now, you can skip adding scopes.
In the future, when you create an app for use outside of your
Google Workspace organization, you must change the User type to External. Then
add the authorization scopes that your app requires. To learn more, see the full
Configure OAuth consent guide.
Create a service account in Google Cloud console
Create a new service account with the role Vertex AI User by following
these steps:
The remaining steps appear in the Google Cloud Console.
Select a Google Cloud project.
Click the email address of the service account that you want to create a key for.
Click the Keys tab.
Click the Add key drop-down menu, then select Create new key.
Select JSON as the Key type and click Create.
Your new public/private key pair is generated and downloaded to your
machine as a service account key file. Save the downloaded JSON file as credentials.json
in your working directory. This file is the only copy of this key. After you
download the key file, you cannot download it again. For information about how to store
your key securely, see
Best practices for managing service account keys.
In your preferred local development environment, extract the downloaded
archive file and open the
add-ons-samples/apps-script/chat/a2ui-ai-agent/a2ui directory.
Click info_outlineOverview> The icon for making a copy Make a copy.
In your Apps Script project,
click The icon for project settings Project Settings>Edit script properties>Add script property
to add the following script properties:
REASONING_ENGINE_RESOURCE_NAME with the Vertex AI agent resource name
copied in previous steps.
SERVICE_ACCOUNT_KEY with the JSON key from the service account
downloaded in previous steps such as { ... }.
Click Save script properties.
In the Google API Console, go to Menu menu>IAM & Admin>Settings.
# 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## http://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."""A2UI agent."""fromgoogle.adk.agentsimportLlmAgentfromgoogle.adk.tools.tool_contextimportToolContextimportjson# The schema for any A2UI message. This never changes.from.a2ui_schemaimportA2UI_SCHEMAdefget_user_profile(tool_context:ToolContext)-> str:"""Call this tool to get the current user profile."""returnjson.dumps({"name":"Pierrick Voulet",# "title": "DevRel Engineer @ Google Workspace | Gen AI & AI Agents & Agentic AI | Automation & Digital Transformation","imageUrl":"https://io.google/2024/speakers/3ea87822-3160-4d54-89dd-57e185085f79_240.webp","linkedin":"https://www.linkedin.com/in/pierrick-voulet/"})AGENT_INSTRUCTION="""You are a user profile assistant. Your goal is to help users get their profile information using a rich UI.To achieve this, you MUST follow these steps to answer user requests:1. You MUST call the `get_user_profile` tool and extract all the user profile information from the result.2. You MUST generate a final a2ui UI JSON based on the user profile information extracted in the previous step."""A2UI_AND_AGENT_INSTRUCTION=AGENT_INSTRUCTION+f"""To generate a valid a2ui UI JSON, you MUST follow these rules:1. Your response MUST be in two parts, separated by the delimiter: `---a2ui_JSON---`.2. The first part is your conversational text response.3. The second part is a single, raw JSON object which is a list of A2UI messages.4. The JSON part MUST validate against the A2UI JSON SCHEMA provided below.To represent the user profile, you MUST use the following A2UI message types:1. Buttons MUST be used to represent links (e.g., LinkedIn profile link).2. Image MUST be used to represent the user's profile picture.---BEGIN A2UI JSON SCHEMA---{A2UI_SCHEMA}---END A2UI JSON SCHEMA---"""root_agent=LlmAgent(name="user_profile",model="gemini-2.5-flash",instruction=A2UI_AND_AGENT_INSTRUCTION,description="An agent that returns the current user profile.",tools=[get_user_profile])
Update the ADK previously deployed with the new version of the implementation.
When a Google Chat app or
card returns an error, the
Chat interface surfaces a message saying "Something went wrong."
or "Unable to process your request." Sometimes the Chat UI
doesn't display any error message, but the Chat app or
card produces an unexpected result; for example, a card message might not
appear.
Although an error message might not display in the Chat UI,
descriptive error messages and log data are available to help you fix errors
when error logging for Chat apps is turned on. For help viewing,
debugging, and fixing errors, see
Troubleshoot and fix Google Chat errors.
Clean up
To avoid incurring charges to your Google Cloud account for the
resources used in this tutorial, we recommend that you delete the
Cloud project.
In the Google API Console, go to the Manage resources page. Click
Menumenu>IAM & Admin>Manage Resources.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026年07月22日 UTC."],[],[]]