@agentic-profile/a2a

0.6.2 • Public • Published

Typescript A2A SDK with Agentic Profile support

This SDK demonstrates use of the Agentic Profile A2A Client and Agentic Profile A2A Service which provide A2A TypeScript/Javascript implementations that are easy to integrate into existing client applications (browser and server) and cloud based servers.

Quick overview of this SDK

This SDK provides:

  • Demonstration of an A2A client and an A2A service
  • Example Node service using Express to host two A2A agents
  • Scripts to create agent cards and Agentic Profiles
  • Support for multi-tenancy, where one agent endpoint can represent many different accounts

This SDK uses the A2A client and service libraries that are enhanced with the Agentic Profile:

The SDK sourcecode has the following:

  • agents/
    • coder/ - An A2A programming assistant/agent
    • eliza/ - The classic Eliza therapist
  • storage/ - In Memory implementation of the storage interface
  • app - Demonstration multi-agent multi-tenant service
  • routes - Provides useful endpoints like /status and /storage for debugging

The root directory contains:

  • index.local.ts - A demonstration of an A2A server with globally unique user and business scoped agent ids, and universal authentication
  • index.js - An AWS Lambda ready server entry point. See the deploy.sh script for example usage

Quickstart

This demo is designed to run locally.

  1. Requirements - Make sure these are installed:

  2. From the shell, clone this repository and switch to the project directory.

    git clone git@github.com:agentic-profile/agentic-profile-a2a.git
    cd agentic-profile-a2a
  3. Download dependencies

    pnpm install
  4. Create agent cards and agentic profiles for the server agents:

    pnpm create-server-agent-cards-and-profiles

    Also create an agentic profile for yourself for testing:

    pnpm create-global-agentic-profile
  5. Start the local server

    pnpm dev

Finish Configuring the Node Server

  1. Copy the file example.env to .env

    cp example.env .env
  2. Edit the .env file.

    To enable admin features. Uncomment ADMIN_TOKEN and choose a password, for example:

    ADMIN_TOKEN=<yoursecret>
    

    Add your Gemini API key (required to use the coder A2A agent). Get a Gemini API key

    GEMINI_API_KEY=<your Gemini API key>
    
  3. Restart the server

    pnpm dev
  4. Make sure an admin feature works. From the command line try:

    curl -H "Authorization: Bearer <yoursecret>" http://localhost:4004/storage

    Or from the browser:

    http://localhost:4004/storage?auth=yoursecret

Test the different A2A agents

  1. Make sure the server is started:

    pnpm dev
  2. For each of the following examples, open a new terminal window. For examples with authentication skip to step #3

    Start the A2A client using the agent card, but still no authentication

    pnpm cli -p http://localhost:4004/agents/coder/

    Start the A2A client using the Agentic Profile, but still no authentication

    pnpm cli -p did:web:localhost%3A4004:agents:coder#a2a-coder
  3. In order to use authentication, you must create an agentic profile and keys to authenticate with.

    pnpm run create-global-agentic-profile

    The above script creates a new agentic profile on the test.agenticprofile.ai server, and also stores a copy in your filesystem at ~/.agentic/iam/a2a-sdk-demo-user

  4. Examples using Agentic Profile authentication

    Start the A2A client with the well-known Agentic Profile and authentication

    pnpm cli -i a2a-service-demo-user -p did:web:localhost%3A4004#a2a-coder -u #connect

    (The subsequent examples don't specify the "-i a2a-service-demo-user" because it is provided as a default to the A2A CLI)

    Start the A2A client with an Agentic Profile and authentication

    pnpm cli -p did:web:localhost%3A4004:users:2:coder#a2a-coder -u #connect

    Start the A2A client with the well-known agent and implicit authentication

    pnpm cli -p http://localhost:4004/ -u #connect

    Start the A2A client with the well-known agentic profile and authentication

    pnpm cli -p did:web:localhost%3A4004#a2a-coder -u #connect

    Start the A2A client with Eliza and authentication

    pnpm cli -p did:web:localhost%3A4004#a2a-eliza -u #connect

Testing with the live SDK example server

  1. For each of the following examples, open a new terminal window. For examples with authentication skip to step #3

    Start the A2A client using the agent card, but still no authentication

    pnpm cli -p https://example.p2pagentic.ai/agents/coder/

    Start the A2A client using the Agentic Profile, but still no authentication

    pnpm cli -p did:web:example.p2pagentic.ai:agents:coder#a2a-coder
  2. In order to use authentication, you must create an agentic profile and keys to authenticate with.

    pnpm run create-global-agentic-profile

    The above script creates a new agentic profile on the test.agenticprofile.ai server, and also stores a copy in your filesystem at ~/.agentic/iam/a2a-sdk-demo-user

  3. Examples using Agentic Profile authentication as https://example.p2pagentic.ai

    Start the A2A client with the well-known Agentic Profile and authentication

    pnpm cli -i a2a-service-demo-user -p did:web:example.p2pagentic.ai#a2a-coder -u #connect

    (The subsequent examples don't specify the "-i a2a-service-demo-user" because it is provided as a default to the A2A CLI)

    Start the A2A client with an Agentic Profile and authentication

    pnpm cli -p did:web:example.p2pagentic.ai:users:2:coder#a2a-coder -u #connect

    Start the A2A client with the well-known agent and implicit authentication

    pnpm cli -p https://example.p2pagentic.ai/ -u #connect

    Start the A2A client with the well-known agentic profile and authentication

    pnpm cli -p did:web:example.p2pagentic.ai#a2a-coder -u #connect

    Start the A2A client with Eliza and authentication

    pnpm cli -p did:web:example.p2pagentic.ai#a2a-eliza -u #connect

Basic Usage

import {
  A2AService,
  InMemoryTaskStore,
  TaskContext,
  TaskYieldUpdate,
} from "./index"; // Assuming imports from the server package

// 1. Define your agent's logic as a TaskHandler
async function* myAgentLogic(
  context: TaskContext
): AsyncGenerator<TaskYieldUpdate> {
  console.log(`Handling task: ${context.task.id}`);
  yield {
    state: "working",
    message: { role: "agent", parts: [{ text: "Processing..." }] },
  };

  // Simulate work...
  await new Promise((resolve) => setTimeout(resolve, 1000));

  if (context.isCancelled()) {
    console.log("Task cancelled!");
    yield { state: "canceled" };
    return;
  }

  // Yield an artifact
  yield {
    name: "result.txt",
    mimeType: "text/plain",
    parts: [{ text: `Task ${context.task.id} completed.` }],
  };

  // Yield final status
  yield {
    state: "completed",
    message: { role: "agent", parts: [{ text: "Done!" }] },
  };
}

Enhancing A2A with the Agentic Profile

The Agentic Profile is a thin layer over A2A, MCP, and other HTTP protocols, and provides:

  • Globally unique - user and business scoped - agent identity
  • Universal authentication

The A2A service, agent, and command line interface were derived from Googles code: https://github.com/google/A2A.git

For each DID document service/agent, we specify the "type" as "A2A" and use the serviceEndpoint to reference the agent.json file.

Why do we need user and business scoped agent identity?

Identity is essential for digital communication between parties because it establishes trust, accountability, and context — without which meaningful, secure interaction is nearly impossible.

Current agent protocols focus on individual agent identity, which while accomplishing the communications goal, does not establish trust and accountability which derive from clear relationships with the people or business the agent represents.

For example, you trust an employee of a bank because they are in the bank building, behind the counter, and wearing a company nametag.

How does the Agentic Profile solve this?

The Agentic Profile provides the digital equivalent of how we judge employees, by using a verifiable document provided by the person or business, and declaring all the agents that represent the person or business.

For example the business at the DNS domain matchwise.ai can have a "chat-agent", which combined becomes matchwise.ai#chat-agent. Concensys helped create the DID specification which has a URI format that results in did:web:matchwise.ai#chat-agent. DID documents (what you find using the did:web:matchwise.ai URI) provides a list of HTTP services, which are equivalent to agents. The Agentic Profile simply lists the agents in the DID document services.

With the Agentic Profile, the person or business is the first class citizen, and all the agents that represent them are clearly defined.

Why do we need universal authentication?

Most agent authentication is done using shared keys and HTTP Authorization headers. While this is easy to implement, it is very insecure.

Another popular option is OAuth, but that has another host of problems including dramatically increasing the attack surface and the challenges of making sure both agents agree on the same authentication service provider.

How does the Agentic Profile solve this?

Public key cryptography, which is used extensively for internet communication, is ideal for decentralized authentication. It is very easy to publish an agents public key via the Agentic Profile, and then the agent can use its secret key to authenticate. JSON Web Tokens + EdDSA are mature and widely used standards, and the ones Agentic Profile uses.

With great options like JWT+EdDSA, centralized authentication systems like OAuth are unecessary.

Readme

Keywords

none

Package Sidebar

Install

npm i @agentic-profile/a2a

Weekly Downloads

12

Version

0.6.2

License

Apache-2

Unpacked Size

105 kB

Total Files

30

Last publish

Collaborators

  • mikeprince