Project

a2a-ruby

0.0
The project is in a healthy, maintained state
Complete A2A Protocol implementation for Ruby applications, enabling agent-to-agent communication via JSON-RPC 2.0, gRPC, and HTTP+JSON transports
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 13.0
~> 3.12
~> 1.57
~> 0.22
~> 6.0
~> 3.18
~> 0.9

Runtime

>= 6.0, < 8.0
~> 2.0
~> 2.0
>= 5.0, < 7.0
>= 2.0, < 4.0
>= 4.0, < 6.0
 Project Readme

A2A Ruby SDK

Build Status Ruby Version License A2A Protocol

The A2A Ruby SDK provides a complete implementation of Google's Agent2Agent (A2A) Protocol for Ruby applications. It enables seamless agent-to-agent communication via JSON-RPC 2.0, gRPC, and HTTP+JSON transports.

Features

  • πŸš€ Complete A2A Protocol Support - Full implementation of the A2A specification
  • πŸ”„ Multiple Transports - JSON-RPC 2.0, gRPC, and HTTP+JSON support
  • πŸ“‘ Streaming & Events - Server-Sent Events for real-time communication
  • πŸ” Security First - OAuth 2.0, JWT, API Key, and mTLS authentication
  • πŸ“‹ Task Management - Complete task lifecycle with push notifications
  • 🎯 Agent Cards - Self-describing agent capabilities and discovery
  • πŸ›  Rails Integration - Seamless Rails engine integration
  • πŸ“Š Production Ready - Comprehensive logging, metrics, and error handling

Installation

Add this line to your application's Gemfile:

gem 'a2a-ruby'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install a2a-ruby

Quick Start

Client Usage

require 'a2a'

# Create a client
client = A2A::Client::HttpClient.new("https://agent.example.com/a2a")

# Send a message
message = A2A::Types::Message.new(
  message_id: SecureRandom.uuid,
  role: "user",
  parts: [
    A2A::Types::TextPart.new(text: "Hello, agent!")
  ]
)

# Get response (streaming or blocking)
client.send_message(message) do |response|
  case response
  when A2A::Types::Message
    puts "Agent replied: #{response.parts.first.text}"
  when A2A::Types::Task
    puts "Task created: #{response.id}"
  end
end

Server Usage

class MyAgentController < ApplicationController
  include A2A::Server::Agent
  
  # Define agent skills
  a2a_skill "greeting" do |skill|
    skill.description = "Greet users in different languages"
    skill.tags = ["greeting", "conversation", "multilingual"]
    skill.examples = ["Hello", "Say hi in Spanish"]
  end
  
  # Define A2A methods
  a2a_method "greet" do |params|
    language = params[:language] || "en"
    name = params[:name] || "there"
    
    greeting = case language
    when "es" then "Β‘Hola"
    when "fr" then "Bonjour"
    else "Hello"
    end
    
    {
      message: "#{greeting}, #{name}!",
      language: language
    }
  end
  
  # Handle streaming responses
  a2a_method "chat", streaming: true do |params|
    Enumerator.new do |yielder|
      # Yield task status updates
      yielder << A2A::Types::TaskStatusUpdateEvent.new(
        task_id: params[:task_id],
        context_id: params[:context_id],
        status: A2A::Types::TaskStatus.new(state: "working")
      )
      
      # Process and yield response
      response = process_chat(params[:message])
      yielder << A2A::Types::Message.new(
        message_id: SecureRandom.uuid,
        role: "agent",
        parts: [A2A::Types::TextPart.new(text: response)]
      )
    end
  end
end

Rails Integration

# config/routes.rb
Rails.application.routes.draw do
  mount A2A::Engine => "/a2a"
end

# The engine automatically provides:
# POST /a2a/rpc          - JSON-RPC endpoint
# GET  /a2a/agent-card   - Agent card discovery
# GET  /a2a/capabilities - Capabilities endpoint

Configuration

A2A.configure do |config|
  config.protocol_version = "0.3.0"
  config.default_transport = "JSONRPC"
  config.streaming_enabled = true
  config.push_notifications_enabled = true
  config.default_timeout = 30
  config.log_level = :info
end

Documentation

Essential Guides:

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/a2aproject/a2a-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the A2A Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.