メインコンテンツにスキップ

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

A Google Apps Script implementation of the Agent2Agent protocol that turns GAS projects into both A2A servers and clients for secure, decentralized AI-agent communication inside Google Workspace.

Target Users

Intermediate-to-advanced Apps Script engineers who need to build internal Workspace automations that orchestrate multiple AI agents via the A2A protocol.

Problems Solved

Building a secure A2A network that can both serve and consume agent endpoints while handling Google authorization scopes and Web-Apps specifics is cumbersome without a dedicated toolkit.

Tags

Main Features

1
Unified server & client implementation

The A2AApp class exposes both `.server()` and `.client()` APIs, letting the same GAS code act as an A2A server (Web Apps) or client (Spreadsheet sidebar) with minimal setup.

2
Native Workspace access

Leverages existing OAuth scopes to let agents read/write Sheets, Docs, Drive, Calendar, and other services directly through A2A calls.

3
Simplified auth & deployment

Wraps Web-Apps token handling and redirects internally; access keys, user restrictions, and logging can be toggled via simple options.

4
Facilitates decentralized agent networks

Implements the HTTP/JSON A2A protocol, enabling cross-language AI agents (GAS, Python, Node.js, etc.) to interoperate in a decentralized fashion.

Usage Examples

Querying weather information from a single A2A server

/**
 * Prerequisite: the "A2AApp" library is added to this project by its script ID.
 * The server is another GAS Web App that exposes skills via new A2AApp().server().
 */
function sampleWeatherRequest() {
  // 1) Web App URL of the A2A server we want to talk to
  const agentCardUrls = [
    'https://script.google.com/macros/s/XXXXXXXXXXXXXXXX/dev' // server providing weather skill
  ];

  // 2) Create client instance
  const client = new A2AApp().client({ agentCardUrls });

  // 3) Call the skill "get_current_weather" exposed by the server
  const payload = { location: 'Tokyo', datetime: 'now' };
  const response = client.request('get_current_weather', payload);

  Logger.log(JSON.stringify(response)); // => { temperature: ..., condition: ... }
}

The snippet registers a Web App URL, instantiates the client and invokes the get_current_weather skill. All HTTP calls, token headers and JSON parsing are handled by the library, letting you focus on the business logic.