Skip to content

thinkovation/go-a2a

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-a2a: Golang Implementation of the A2A Protocol

This is a Golang implementation of the Agent-to-Agent (A2A) protocol, an open protocol enabling communication and interoperability between agentic applications.

Features

  • Complete implementation of the A2A JSON-RPC protocol
  • Task management with proper state transitions
  • Streaming support with Server-Sent Events (SSE)
  • Push notification capabilities
  • Support for agent discovery via agent cards
  • Both client and server implementations

Package Structure

  • pkg/types: Core type definitions matching the A2A JSON schema
  • pkg/rpc: JSON-RPC request/response handling
  • pkg/server: A2A server implementation
  • pkg/client: A2A client implementation
  • pkg/task: Task management
  • pkg/stream: Streaming capabilities
  • pkg/notification: Push notification system
  • pkg/discovery: Agent discovery (Agent Card handling)
  • examples: Example implementations

Getting Started

Prerequisites

  • Go 1.21 or higher

Installation

go get github.com/thinkovation/go-a2a

Running the Examples

To run the example server:

go run examples/simple_server.go

In another terminal, run the example client:

go run examples/simple_client.go

Usage

Creating a Server

package main

import (
	"github.com/thinkovation/go-a2a/pkg/discovery"
	"github.com/thinkovation/go-a2a/pkg/server"
	"github.com/thinkovation/go-a2a/pkg/types"
	"net/http"
)

// Implement the TaskHandler interface
type MyTaskHandler struct{}

func (h *MyTaskHandler) ProcessTask(task *types.Task, message types.Message) error {
	// Process the task and update its state
	// ...
	return nil
}

func main() {
	// Create a task handler
	taskHandler := &MyTaskHandler{}

	// Create agent skills
	skills := []types.AgentSkill{
		{
			ID:   "example-skill",
			Name: "Example Skill",
		},
	}

	// Create agent capabilities
	capabilities := types.AgentCapabilities{
		Streaming:            true,
		PushNotifications:    true,
		StateTransitionHistory: true,
	}

	// Create the agent card
	agentCard := discovery.GenerateAgentCard(
		"My Agent",
		"http://localhost:8080",
		"1.0.0",
		skills,
		capabilities,
	)

	// Create the server configuration
	config := server.ServerConfig{
		AgentCard:   *agentCard,
		TaskHandler: taskHandler,
		KeepHistory: true,
	}

	// Create and start the server
	server := server.New(config)
	http.ListenAndServe(":8080", server)
}

Using the Client

package main

import (
	"fmt"
	"github.com/thinkovation/go-a2a/pkg/client"
	"github.com/thinkovation/go-a2a/pkg/types"
)

func main() {
	// Create an A2A client
	a2aClient := client.New("http://localhost:8080")

	// Fetch the agent card
	agentCard, err := a2aClient.FetchAgentCard()
	if err != nil {
		fmt.Printf("Error fetching agent card: %v\n", err)
		return
	}

	// Create a message
	message := types.Message{
		Role: "user",
		Parts: []types.Part{
			{
				Type: types.PartTypeText,
				Text: new(string),
			},
		},
	}
	*message.Parts[0].Text = "Hello, agent!"

	// Send the message to the agent
	task, err := a2aClient.SendTask(message, nil, nil)
	if err != nil {
		fmt.Printf("Error sending message: %v\n", err)
		return
	}

	fmt.Printf("Task created with ID: %s\n", task.ID)
}

License

This project is licensed under the same license as the original A2A protocol specification.

Acknowledgments

This implementation is based on the A2A Protocol Specification.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages