AWP

Go SDK

A Peer that listens, connects, sends and receives, built on the reference implementation's engine.

The Go SDK is github.com/agentwireprotocol/go-sdk, package awp. It is built on the engine of the reference implementation, so a Peer behaves exactly like the awp daemon: resume with an outbox on disk, acks, dedup by id, blobs in chunks, grants and introductions, ping/pong, reconnection with backoff, and tailcat as the transport that reaches anywhere.

go get github.com/agentwireprotocol/go-sdk

A peer in a few lines

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/agentwireprotocol/go-sdk/awp"
)

func main() {
	p, err := awp.New(awp.Options{
		Dir:    "/var/lib/mybot",    // identity, outbox, threads, blobs
		Name:   "mybot@builder",
		Listen: []string{"tailcat"}, // or "tcp:127.0.0.1:7000", "unix:/tmp/awp.sock"
	})
	if err != nil {
		log.Fatal(err)
	}
	defer p.Close()

	ctx := context.Background()
	key, err := p.Connect(ctx, "tc...") // an address shared out of band
	if err != nil {
		log.Fatal(err)
	}
	p.Send(awp.Draft{To: key, Subject: "Run the suite", Text: "Please run make test at a1b2c3."})

	for ev := range p.Events(ctx) {
		switch e := ev.(type) {
		case awp.Message:
			fmt.Printf("%s: %s\n", e.Peer, e.Text())
		case awp.StateChanged:
			fmt.Printf("%s is %s in %s\n", e.Peer, e.State, e.Thread)
		case awp.Blob:
			fmt.Printf("file %s at %s\n", e.Name, e.Path)
		}
	}
}

How it fits

New opens the state directory (or a temporary one), loads or creates the Ed25519 identity, and starts listening and reconnecting. Connect dials an address and returns the peer’s key once the handshake is done; the engine keeps the connection and reconnects with exponential backoff, capped at a minute, for as long as there are unacked messages or open threads. Send never fails because the peer is away: the message is on disk and goes out on the next resume, and Delivered waits for the ack. Events delivers what happens, in order, with nothing lost to a slow consumer.

The wire types, framing and cryptography are the reference implementation’s wire package, which is also what the JSON Schema is generated from. Peer.Node() exposes the engine for what the SDK does not cover, such as presence and conversation sharing.

Conformance

go test ./... in the SDK’s repository runs the protocol’s conformance suite against a Peer in-process, along with a two-peer conversation, queued delivery across a restart and blob transfer. Every line a Peer sends validates against the schema.