Abstract
This report details the Agent2Agent (A2A) network built with Google Apps Script’s Web Apps. It facilitates communication between diverse AI agents, overcoming platform limitations. Key improvements include parallel task execution with asynchronous processes and enhanced security through secure access token handling and user-specific Web App availability, demonstrating a robust and secure A2A implementation.
Introduction
This report details an updated implementation of Agent2Agent (A2A), an open protocol designed to enable communication and collaboration between diverse AI agents. The goal of A2A is to overcome limitations of isolated platforms, allowing AI agents to work together on complex tasks while maintaining their internal structures. I recently published a report titled “Building Agent2Agent (A2A) Server with Google Apps Script”. Ref This updated report focuses on successfully creating an A2A network using Google Apps Script’s Web Apps functionality.
The new implementation leverages Google Apps Script to facilitate a decentralized and interoperable AI agent ecosystem. Key improvements include the use of the fetchAll method, which retrieves agent cards and executes tasks in parallel, reducing processing costs. Enhanced security is achieved through the ease of seamlessly obtaining and using access tokens in Google Apps Script, allowing secure access to agents in Web Apps. This resolves a previous issue where access tokens were temporarily placed in query parameters, like my previous report. Additionally, Web Apps can now be made available only to specific users, further improving security. This advancement demonstrates the practical application of Google Apps Script in building a robust and secure A2A network.
Advantages of Using A2A Server and Client with Google Apps Script
Here are the advantages of using an A2A (Agent-to-Agent) server and client with Google Apps Script:
- Integration with Google Workspace: It allows direct management of active Google Docs and Sheets when using the A2A client.
- Seamless Integration with Google Resources: Effortlessly connects with Google services like Google APIs, Docs, Sheets, Slides, Gmail, and Calendar, leveraging secure authorization scopes.
- Enhanced Security via Access Tokens: Simplifies access token acquisition for Web Apps, eliminating the need for temporary token inclusion in Python client queries for agent card retrieval.
- Improved User Restriction: Web Apps can be restricted to specific users, increasing security.
- Automated Script Execution: Supports automatic script execution via triggers, beneficial for client-side operations. This client can interact with various A2A servers (Google Apps Script, Python, Node.js, etc.).
- Easy Deployment: Web Apps can be readily deployed as A2A servers, accessible by various A2A clients (Google Apps Script, Python, Node.js, etc.).
- Decentralized Agent Communication: Enables direct communication between AI agents, fostering a decentralized AI ecosystem.
Repository
https://github.com/tanaikech/A2AApp
Usage
Here, the following sample is used for testing.
Please do the following steps.
1. Ger API key
In order to use the scripts in this report, please use your API key. Ref This API key is used to access the Gemini API.
2. Copy sample files
Here, an A2A client and 4 A2A servers are used. Those files can be copied by the following simple Google Apps Script. Please copy and paste the following script to the script editor of Google Apps Script, and run myFunction
. By this, the requirement files are copied to your Google Drive. The whole scripts can also be seen on this repository.
When dstFolder
is root
, the files are copied to the root folder. If you want to copy them to the specific folder, please set your folder ID.
function myFunction() {
const dstFolderId = "root"; // Please set your destination folder ID. The default is the root folder.
// These file IDs are the sample client and servers.
const fileIds = [
"1IcUv4yQtlzbiAqRXCEpIfilFRaY4_RS5idKEEdzNWgk", // A2A client,
"103RvSs0xWgblNHqEssVMo-ar7Ae8Fe-NyUsyL1m4k0u428hB7v7Jmnby", // A2A server 1_Google Sheets Manager Agent
"1z8bDFo8n4ssco8UeBXatLp3yMPUVkbqEofZE8y1-XYstEqYiGifvVSwf", // A2A server 2_Google Drive Manager Agent,
"1FltchXoOfbo731KAWJd0hGbrN75aZ_lg76og-ooldk5B-uAE142RppWa", // A2A server 3_Google Calendar Manager Agent,
"1k3-JwyKBJ2DsGeWeT0dTucdzm0DHSd_1XlaevFA4_pJhGL67vDRYD0ym", // A2A server 4_APIs Manager Agent,
];
const folder = DriveApp.getFolderById(dstFolderId);
const headers = {
authorization: "Bearer " + ScriptApp.getOAuthToken(),
"Content-Type": "application/json",
};
const reqs = fileIds.map((fileId) => ({
url: `https://www.googleapis.com/drive/v3/files/${fileId}/copy`,
headers,
payload: JSON.stringify({
parents: [dstFolderId],
name: DriveApp.getFileById(fileId).getName(),
}),
}));
UrlFetchApp.fetchAll(reqs).forEach((res) => {
const { id } = JSON.parse(res.getContentText());
DriveApp.getFileById(id).moveTo(folder);
});
// If an error is related to Drive API, please enable Drive API v3 at Advanced Google services.
}
When this function is run, the following files are copied.
- “A2A client”
- “A2A server 1_Google Sheets Manager Agent”
- “A2A server 2_Google Drive Manager Agent,”
- “A2A server 3_Google Calendar Manager Agent”
- “A2A server 4_APIs Manager Agent”
2. Setting
1. A2A servers
For 4 A2A servers, please follow the following steps.
1. Set API key
Open the script editors of “A2A server 1”, “A2A server 2”, “A2A server 3”, and “A2A server 4”. And, please set your API key for using the Gemini API to apiKey
in A2Aserver1.gs
, A2Aserver2.gs
, A2Aserver3.gs
, and A2Aserver4.gs
.
2. Deploy Web Apps
To allow access from the A2A client, the server side uses Web Apps built with Google Apps Script. Ref The A2A client can access the A2A server using a GET and POST HTTP request. Thus, the Web Apps can be used as the A2A server.
Detailed information can be found in the official documentation.
Please follow these steps to deploy the Web App in the script editors for 4 A2A servers.
- In the script editor, at the top right, click “Deploy” -> “New deployment”.
- Click “Select type” -> “Web App”.
- Enter the information about the Web App in the fields under “Deployment configuration”.
- Select “Me” for “Execute as”.
- Select “Anyone” for “Who has access to the app:”. In this sample, a simple approach allows requests without an access token. However, a custom API key is used for accessing the Web App.
- Click “Deploy”.
- On the script editor, at the top right, click “Deploy” -> “Test deployments”.
- Please run the function
getServerURL
with the script editor. By this, the URL likehttps://script.google.com/macros/s/###/dev?accessKey=sample
is retrieved. Please copy each Web Apps URL for 4 A2A servers.
It is important to note that when you modify the Google Apps Script for the Web App, you must modify the deployment as a new version. This ensures the modified script is reflected in the Web App. Please be careful about this. Also, you can find more details on this in my report “Redeploying Web Apps without Changing URL of Web Apps for new IDE”.
In this sample, after the client with Google Apps Script was tested, the servers will be tested by a Python script. So, Execute as: Me
and Who has access to the app: Anyone
are used.
2. A2A client
For the A2A client, please follow the following steps.
1. Set API key
Open the Google Spreadsheet of “A2A client”, and open the script editor of Google Apps Script. And, please set your API key for using Gemini API to apiKey
in main.gs
.
2. Set Web Apps URLs
Please set your Web Apps URLs for 4 A2A servers to agentCardUrls
. And, save the script. In this sample, 4 Web Apps URLs are set.
3. Testing
Please reopen the Google Spreadsheet of the A2A client. By this, you can see the custom menu Run
. Please run Open sidebar
. When you see the authorization dialog open, please authorize all scopes. By this, the sidebar is opened. When the above steps were correctly done, you can test it. The demonstration of this is as follows.
Sample 1
In the 1st sample, the active Spreadsheet is used.
First, the value of the active cell is retrieved.
Prompt: Get the active cells. Return the values from the active cells. Response: The active cell is B2 in Sheet1 of the spreadsheet with ID ###. The value of this cell is “sample text”
Next, the values are put into the active cell.
Prompt: Get the active cells. Put values ‘[[“a1”, “b1”],[“a2”, “b2”],[“a3”, “b3”]]’ to the active cell. Response: The active cell is A5 in Sheet1 of the spreadsheet with ID ###. The values ‘[["a1", "b1"],["a2", "b2"],["a3", "b3"]]’ have been successfully placed into cells A5:B7 of the same sheet and spreadsheet.
The information of the active cell is retrieved on the A2A client, and the information is used in the A2A server (Google Sheets Manager Agent). This result indicates the advantage of using the A2A client built by Google Apps Script.
Sample 2
In the 2nd sample, image data is retrieved from Google Drive.
Prompt: Show the image of CherryBlossom from Google Drive. Response: OK. I have downloaded the image "CherryBlossom.png" from Google Drive.
Sample 3
In the 3rd sample, multiple agents are used.
Prompt: Check tomorrow’s weather conditions at 12 PM around Shinagawa Station and exchange 100 US Dollars for Japanese Yen. Under this condition, will we enjoy eating lunch outside for 1 hour at the retrieved location and that day? Finally, create it as a schedule in Google Calendar.
Response: OK. Here’s a summary based on your question and the provided answers: The weather in Shinagawa Station at 12 PM on May 28, 2025, is predicted to be mainly clear, partly cloudy, and overcast. The exchange rate is 100 USD to approximately 14,290 JPY. A Google Calendar event titled ‘Lunch at Shinagawa Station’ has been created for May 28, 2025, from 12:00 to 13:00, including the weather conditions and JPY value in the description. To determine if eating lunch outside for an hour is suitable, factors like temperature, wind, and personal preferences should be considered along with the mainly clear, partly cloudy, and overcast conditions.
This process automatically creates an event in Google Calendar as follows.
In this case, this response was created using “create_schedule_to_Google_Calendar” of “Google Calendar Manager Agent” and “get_exchange_rate” and “get_current_weather” of “APIs Manager Agent” together with the A2A client. Also, an event was automatically created in Google Calendar. From this result, you can confirm that AI agents are working together.
Summary
The successful communication between the A2A client and A2A servers, both developed using Google Apps Script, demonstrates the viability of building such a system within the Google ecosystem. This setup leverages the power of active Google services like Google Sheets and Google Docs, enhancing their utility through the A2A client.
A key proposed enhancement for this system is the implementation of an exclusive server that would centralize and provide the URLs of all A2A servers to clients. This approach would enable more efficient management of A2A servers on a per-client basis. Furthermore, it suggests the potential for an A2A server designed to manage Gmail, facilitating automated tasks such as autoreplies and Google Calendar event creation by periodically reading incoming emails.
Additional Information: Testing A2A Client with Python Using A2A Servers Built by Google Apps Script
The 4 A2A servers built by Google Apps Script, shown in the image above, can also be used with Google’s Python demo UI, as shown in the following demo video. Ref
The detailed setting of the Python client can be seen at my repository.