buzzagent

package module
v0.0.0-...-5a9de2e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

README

buzz-agent-go

buzz-agent-go is the small Go adapter between a concrete agent and buzz-acp. It implements the Agent Client Protocol over stdin/stdout and leaves model frameworks, prompts, tools, network topology, and deployment to the consuming project.

Install

go get github.com/asmogo/buzz-agent-go@latest

Until the first release tag is created, pin the pseudo-version emitted by Go for a reviewed commit on main.

Use

package main

import (
	"context"
	"log"
	"os"

	buzzagent "github.com/asmogo/buzz-agent-go"
)

func main() {
	publisher, err := buzzagent.NewCLIPublisher("buzz")
	if err != nil {
		log.Fatal(err)
	}

	handler := buzzagent.HandlerFunc(func(ctx context.Context, turn buzzagent.Turn) (buzzagent.Response, error) {
		// Initialize and call Genkit, another model framework, or ordinary Go
		// application code here. turn.Text contains normalized user content;
		// turn.RawPrompt retains the authenticated Buzz envelope.
		return buzzagent.Response{
			Text:    "Handled: " + turn.Text,
			Publish: turn.Replyable,
		}, nil
	})

	if err := buzzagent.Serve(context.Background(), os.Stdin, os.Stdout, buzzagent.Options{
		Name:      "example-agent",
		Version:   "dev",
		Handler:   handler,
		Publisher: publisher,
	}); err != nil {
		log.Fatal(err)
	}
}

Build the program as a normal Go binary and configure buzz-acp to launch it as its ACP agent command. The consuming image must provide the buzz-acp and buzz executables when those integrations are used.

Publication is opt-in for every response. A response with Publish: true fails unless the incoming prompt contains a validated Buzz event and a Publisher was configured. Unknown reply IDs written inside untrusted message content are never accepted as targets.

MCP tools from session/new

When the ACP client (for example buzz-acp with BUZZ_ACP_MCP_COMMAND set) attaches stdio MCP servers to a session, the SDK spawns one client per server at session creation and exposes their tools on every turn:

handler := buzzagent.HandlerFunc(func(ctx context.Context, turn buzzagent.Turn) (buzzagent.Response, error) {
	for _, tool := range turn.Tools {
		// tool.Name is namespaced: "<serverName>_<toolName>"
		// tool.InputSchema is a JSON Schema object (map[string]any)
		// tool.Call(ctx, json.RawMessage(argsJSON)) invokes the MCP tool
	}
	...
})
  • Tools are namespaced as <serverName>_<toolName>; consumers decide which ones to expose to their model.
  • Startup is fail-soft: a server that does not start, initialize, or list tools within 30 s is skipped with a warning and never fails session/new.
  • Only stdio servers are supported; other transports are skipped.
  • MCP clients are disconnected on session/close and on agent shutdown.

Non-goals

This module does not include:

  • Genkit or another model SDK;
  • concrete agents, prompts, tools, or skills;
  • a direct Buzz relay client;
  • Docker or Kubernetes deployment support;
  • Tailscale or dashboard management.

Those concerns belong to the consuming application and its infrastructure.

Development

go test ./...
go test -race ./...
go vet ./...
test -z "$(gofmt -l .)"

License

Apache-2.0.

Documentation

Overview

Package buzzagent adapts Go handlers to the Agent Client Protocol used by buzz-acp. It deliberately has no relay, model-framework, or infrastructure dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(ctx context.Context, reader io.Reader, writer io.Writer, options Options) error

Serve binds Handler to an ACP connection over reader and writer. The function returns when the peer disconnects or ctx is canceled.

Types

type CLIPublisher

type CLIPublisher struct {
	// contains filtered or unexported fields
}

CLIPublisher publishes replies through the official Buzz command-line client. It does not implement or connect to the relay protocol itself.

func NewCLIPublisher

func NewCLIPublisher(command string) (*CLIPublisher, error)

NewCLIPublisher creates a Publisher that executes command.

func (*CLIPublisher) Publish

func (p *CLIPublisher) Publish(ctx context.Context, target ReplyTarget, content string) error

Publish sends content as a reply to target.

type Handler

type Handler interface {
	HandleTurn(context.Context, Turn) (Response, error)
}

Handler processes Buzz turns. Implementations own all model, tool, prompt, and application behavior.

type HandlerFunc

type HandlerFunc func(context.Context, Turn) (Response, error)

HandlerFunc adapts a function to Handler.

func (HandlerFunc) HandleTurn

func (f HandlerFunc) HandleTurn(ctx context.Context, turn Turn) (Response, error)

HandleTurn calls f(ctx, turn).

type Options

type Options struct {
	Name           string
	Version        string
	Handler        Handler
	WorkingMessage func(Turn) string
	Publisher      Publisher
	Logger         *slog.Logger
}

Options configures an ACP agent connection.

type Publisher

type Publisher interface {
	Publish(context.Context, ReplyTarget, string) error
}

Publisher sends a response to a validated Buzz reply target.

type ReplyTarget

type ReplyTarget struct {
	ChannelID string
	EventID   string
}

ReplyTarget identifies the channel event to which a response belongs.

type Response

type Response struct {
	Text    string
	Publish bool
}

Response is the result of handling a Turn. Publish must be set explicitly when Text should also be sent as a Buzz reply.

type Tool

type Tool struct {
	// Name is the namespaced tool name: "<serverName>_<toolName>".
	Name string
	// Description is the human-readable tool description from the MCP server.
	Description string
	// InputSchema is the JSON Schema object describing the tool's arguments.
	InputSchema map[string]any
	// Call invokes the tool with a JSON-encoded argument object and returns
	// the tool's text output. A tool-level error (isError) is returned as an
	// error with the tool's own message.
	Call func(ctx context.Context, input json.RawMessage) (string, error)
}

Tool is a framework-neutral handle to a tool exposed by an MCP server that the ACP client attached to a session via session/new.

type Turn

type Turn struct {
	SessionID string
	RawPrompt string
	Text      string
	Replyable bool
	// Tools are the namespaced MCP tools attached to this turn's session by the
	// ACP client (session/new mcpServers). Empty when the session has no MCP
	// servers. Consumers decide which tools to expose to their model.
	Tools []Tool
}

Turn is one normalized request delivered by buzz-acp.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL