Skip to content

aydin41k/a2a-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Agentic AI and A2A Showcase - The weatherman you didn't ask for

Agent-to-Agent (A2A) Protocol featuring an AI-powered weather agent with a unique Azerbaijani cultural personality, powered by Azure OpenAI and modern TypeScript tooling.

๐Ÿš€ What Makes This Special

This project showcases a production-ready implementation of agent-to-agent communication, combining multiple technologies into a cohesive, event-driven architecture. Demonstration of how AI agents can communicate using standardised protocols whilst having their own tools independently.

๐ŸŽฏ Key Features

๐Ÿ—๏ธ A2A Protocol Implementation

  • Protocol-Compliant Communication: Full implementation of the Agent-to-Agent protocol v0.3.0
  • Agent Card Discovery: Exposes agent capabilities via .well-known/agent-card.json endpoint
  • Multi-Part Message Handling: Sophisticated message parsing supporting multiple content types
  • Event-Driven Architecture: Uses ExecutionEventBus for asynchronous message processing

๐Ÿง  OpenAI Agents SDK Integration

  • Agentic Workflows: Leverages the @openai/agents SDK for autonomous decision-making
  • Tool Chaining: Dynamically chains multiple tools (weather fetching โ†’ personality transformation)
  • Azure OpenAI: Production-grade integration with Azure's OpenAI service
  • Zod Schema Validation: Type-safe parameter validation for all tool inputs

๐Ÿ› ๏ธ Custom Tool System

  1. Weather Tool: Real-time weather data from WeatherAPI.com
  2. Qedeshator Tool: Cultural personality injection using GPT-4, transforming responses into authentic Azerbaijani street slang

๐ŸŽญ Personality Engineering

The agent features a unique Azerbaijani qษ™deลŸ persona that:

  • Speaks in po-bratski style with authentic dialect
  • Uses culturally-specific phrases
  • Employs grammatical patterns specific to Yasamal street culture
  • Maintains character consistency through system prompt engineering

๐Ÿ›๏ธ Architecture Highlights

  • Client-Server Separation: Clean separation of concerns with dedicated client and server implementations
  • In-Memory Task Store: Efficient task tracking with InMemoryTaskStore
  • UUID-Based Message Tracking: Ensures message traceability and idempotency
  • Express 5.x Integration: Modern Express setup with type-safe routing via A2AExpressApp
  • TypeScript + ESM: Full TypeScript with ES modules for modern JavaScript features

๐Ÿ“‹ Tech Stack

Technology Purpose Why It's Cool
@a2a-js/sdk Agent-to-Agent protocol Standardised agent communication, future-proofing AI interoperability
@openai/agents Agentic AI framework Autonomous tool selection and execution
Azure OpenAI LLM inference Enterprise-grade AI with GPT-4
TypeScript Type safety Catch errors at compile-time, not runtime
Zod Schema validation Runtime type safety for API boundaries
Express 5.x Web server Latest Express with improved async/await support
WeatherAPI.com Weather data Real-time weather information
dotenv Configuration Secure environment variable management
tsx TypeScript execution Fast, modern TS execution without build steps

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Client    โ”‚โ”€โ”€โ”€โ”€โ”€ A2A โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚     Server  WeatherAgentExecutor    โ”‚
โ”‚  (client.ts)โ”‚    Protocol        โ”‚         (Express + A2A SDK)         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                  โ”‚
                                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                   โ”‚        Weather Agent            โ”‚
                                   โ”‚   (@openai/agents -- JS)        โ”‚
                                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                  โ”‚
                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                          โ”‚                                            โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Weather Tool โ”‚                          โ”‚  Qedeshator Tool  โ”‚
                  โ”‚(WeatherAPI)  โ”‚                          โ”‚  (Azure OpenAI)   โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿšฆ Getting Started

Prerequisites

  • Node.js 18+
  • Azure OpenAI API access
  • WeatherAPI.com API key (free tier works!)

Installation

npm install

Configuration

Create a .env file with your credentials:

AZURE_OPENAI_API_KEY=your_key_here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_VERSION=2024-08-01-preview
AZURE_OPENAI_DEPLOYMENT=gpt-4
WEATHER_API_KEY=your_weatherapi_key_here

Running the Server

npm start

For development with hot-reload:

npm run dev

The server will start on http://localhost:4000

Using the Client

npx tsx client.ts "What's the weather in Baku?"

Expected output (with personality!):

Agent response: Bakida hava indi 16.2ยฐC-dษ™di, gรผnษ™ลŸ dษ™ รงฤฑxฤฑbdฤฑ, can-cigษ™r. Belษ™ havada ลŸษ™hษ™rdษ™ fฤฑrlanmaq lazฤฑmdรผ, รถzรผnรผ gรถstษ™rmษ™k gษ™rษ™kdi. "Gรผnษ™ลŸ รงฤฑxanda, qษ™deลŸlษ™r ลŸษ™hษ™rdษ™di."

๐ŸŽจ Code Highlights

Event-Driven Message Processing

The executor uses an event bus pattern for non-blocking message handling:

const responseMessage: Message = {
  kind: 'message',
  messageId: uuidv4(),
  role: 'agent',
  parts,
  contextId: requestContext.contextId,
};

eventBus.publish(responseMessage);
eventBus.finished();

Tool Chaining Magic

The agent automatically chains tools based on context:

const weatherAgent = new Agent({
  instructions: `If the question is about weather, use the weather tool. 
    Before sending output, send it to qedeshator tool and output whatever text it gives back.`,
  tools: [weatherTool, qedeshatorTool],
});

Protocol-Compliant Agent Card

The server exposes its capabilities via standard A2A agent card:

const weatherAgentCard: AgentCard = {
  name: 'Weather Agent',
  description: 'An Azerbaijani qษ™deลŸ who tells you the weather with style',
  protocolVersion: '0.3.0',
  skills: [{ 
    id: 'weatherTool',
    name: 'Weather Tool', 
    description: 'Tells you the weather in a city', 
    tags: ['weather', 'city', 'temperature']
  }],
};

๐Ÿ”ฎ Future Enhancements

  • Streaming responses for real-time interaction
  • Push notifications for weather alerts
  • State transition history tracking
  • Multi-modal inputs (images, audio)
  • Agent-to-agent direct communication
  • Redis-backed task store for horizontal scaling
  • WebSocket support for bidirectional streaming

๐Ÿ“š Learning Resources

๐Ÿค Contributing

This project demonstrates advanced AI agent patterns. Feel free to fork and experiment!

๐Ÿ“ Licence

MIT


Builing the future with โ˜• and curiosity

About

Two AI agents talking via the A2A protocol

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published