A2AApp
This is a library for implementing an Agent2Agent (A2A) server using Google Apps Script. This enables AI agent communication and secure service access for AI-powered workflows.
AI Summary
A2AApp
Enables secure A2A communication between AI agents using GAS.
Target Users
Intermediate GAS developers integrating AI agents securely in Google Workspace.
Problems Solved
Solves limitations of isolated AI platforms for secure decentralized agent communication in Google Workspace.
Script ID
- In GAS Editor: Click "Libraries +" → Paste into "Script ID" field → Click "Look up"
- "A2AApp" will appear in the search results
- Select the latest version (highest number) from "Version" dropdown
- Click "Add"
Tags
Main Features
1
Google Workspace Integration
Directly manage active Google Docs and Sheets via A2A client integration.
2
Enhanced Security
Secures access with Web App user restrictions and simplified access tokens.
3
Easy Deployment
Rapidly deploy GAS Web Apps as A2A servers for various clients.
Examples
Main Functions
| Function | Description |
|---|---|
| new A2AApp | Create A2A service instance |
| A2AApp.server | Run A2A server mode |
Examples
Deploy A2A Server
/**
* A2Aサーバー展開
* ・ライブラリキー追加: 1OuHIiA5Ge0MG_SpKdv1JLz8ZS3ouqhvrF5J6gRRr6xFiFPHxkRsgjMI6 をGASライブラリに追加
* ・オプション設定: new A2AApp({accessKey: "sample", log: true})
* ・サーバー実行: .server(e) でWeb Appリクエスト処理
*/
function doGet(e) {
return new A2AApp({accessKey: "sample"}).server(e);
}
function doPost(e) {
return new A2AApp({accessKey: "sample"}).server(e);
}Copy Sample Files
/**
* サンプルファイルコピー
* ・ファイルID配列: const fileIds = ["1IcUv4yQtlzbiAqRXCEpIfilFRaY4_RS5idKEEdzNWgk", ...]
* ・バッチコピー依頼: UrlFetchApp.fetchAll(reqs)
* ・ファイル移動: DriveApp.getFileById(id).moveTo(folder)
*/
function myFunction() {
const dstFolderId = "root";
const fileIds = [
"1IcUv4yQtlzbiAqRXCEpIfilFRaY4_RS5idKEEdzNWgk",
"103RvSs0xWgblNHqEssVMo-ar7Ae8Fe-NyUsyL1m4k0u428hB7v7Jmnby",
"1z8bDFo8n4ssco8UeBXatLp3yMPUVkbqEofZE8y1-XYstEqYiGifvVSwf",
"1FltchXoOfbo731KAWJd0hGbrN75aZ_lg76og-ooldk5B-uAE142RppWa",
"1k3-JwyKBJ2DsGeWeT0dTucdzm0DHSd_1XlaevFA4_pJhGL67vDRYD0ym",
];
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);
});
}Get AgentCard URL
/**
* AgentCard登録URL取得
* ・サービスURL取得: ScriptApp.getService().getUrl()
* ・OAuthトークン付与: ScriptApp.getOAuthToken()
* ・クエリ追加: ?access_token=...&accessKey=sample で構築
*/
function getRegisteringAgentCardURL() {
const registeringAgentCardURL = `${ScriptApp.getService().getUrl()}?access_token=${ScriptApp.getOAuthToken()}&accessKey=sample`;
console.log(registeringAgentCardURL);
}