The Go SDK provides a clean interface for registering functions as tools for AI agents.

Installation

go get github.com/agentrpc/agentrpc/sdk-go

Basic Usage

package main

import (
	"os"
	"os/signal"
	"syscall"

	"github.com/agentrpc/agentrpc/sdk-go"
)

func main() {
	rpc, _ := agentrpc.New(agentrpc.Options{
		APISecret: os.Getenv("AGENTRPC_API_SECRET"),
	})

	rpc.Register(agentrpc.Tool{
		Name:        "getWeather",
		Description: "Return weather information at a given location",
		Handler: func(input struct{ Location string }) string {
			return "probably raining"
		},
	})

	go func() {
		rpc.Listen()
	}()

	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

	<-sigChan
	defer rpc.Unlisten()
}

For more details, visit the Go SDK GitHub repository.