agentleFS
MicrosoftKnown publishermicrosoft/agent-host-protocol/clients/go/AGENTS.md

agent-host-protocol / go

AGENTS.md386 starsChanged 2 months agoMITView on GitHub

This directory contains the Go module for the Agent Host Protocol (AHP), published as github.com/microsoft/agent-host-protocol/clients/go. The module targets Go 1.22+ and is split into three packages that mirror the Rust client's three-crate split: - ahptypes/ — generated wire types only, no I/O. - ahp/ — async Client, reducers, and pluggable Transport. Sub- package ahp/hosts/ carries the multi-host runtime. - ahpws/ — WebSocket transport built on github.com/coder/websocket. The Go files under ahptypes/ (except common.go and discriminated_unions.go) are auto-generated from the TypeScript…

The file

We split this AGENTS.md into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Only optional pointer fields carry ,omitempty.

    line 92

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Go Client — Agent Guide

Overview

This directory contains the Go module for the Agent Host Protocol (AHP), published as github.com/microsoft/agent-host-protocol/clients/go.

The module targets Go 1.22+ and is split into three packages that mirror the Rust client's three-crate split:

  • ahptypes/ — generated wire types only, no I/O.
  • ahp/ — async Client, reducers, and pluggable Transport. Sub- package ahp/hosts/ carries the multi-host runtime.
  • ahpws/ — WebSocket transport built on github.com/coder/websocket.

Code Generation

The Go files under ahptypes/ (except common.go and discriminated_unions.go) are auto-generated from the TypeScript definitions in types/. Do not edit these files directly. Generated files are committed to source control so the package is consumable via the Go module proxy without a code-generation toolchain.

To regenerate after protocol changes:

npm run generate:go    # runs: tsx scripts/generate.ts --go

Generated files (all suffixed .generated.go): version, state, actions, commands, notifications, messages, errors. The generator runs gofmt -w on its output.

CI verifies the committed generated files match the output of npm run generate:go and fails on drift.

Type mapping (TS → Go)

TypeScriptGo
stringstring
numberint64 (TS contract: 64-bit ints)
number w/ @format floatfloat64
booleanbool
unknown / objectjson.RawMessage
T | null*T
optional field*T + json:"name,omitempty"
T[] / Array<T>[]T
Record<string, T>map[string]T
Partial<T>PartialT struct, every field a pointer
string enumtyped string + named constants
Bitset enumtyped uint32 + flag constants + Has/Or helpers
Interface structstruct with JSON tags
Discriminated unionwrapper struct + marker interface + custom MarshalJSON/UnmarshalJSON
URItype URI = string
StringOrMarkdownstruct w/ custom (un)marshal
Recursive structpointer field in the recursive position
_meta fieldMeta map[string]json.RawMessage + json:"_meta,omitempty"
snake_case wire fieldPascalCase Go field + json:"snake_case"

Discriminated unions

Each TS discriminated union is emitted as a concrete wrapper struct so that it can be used directly as a Go field type — []ResponsePart, StateAction, etc. — without consumers having to call a custom unmarshaler at every use site:

type ResponsePart struct {
    Value isResponsePart  // marker interface, one impl per variant
}

func (r *ResponsePart) UnmarshalJSON(b []byte) error { /* dispatch on kind */ }
func (r ResponsePart) MarshalJSON() ([]byte, error)  { return json.Marshal(r.Value) }

Unknown variants surface as a *VariantNameUnknown{ Raw json.RawMessage } so a future server can speak a not-yet-known kind without breaking existing clients. Reducers treat them as no-ops.

Bitset enums

SessionStatus is currently the only bitset enum. It's emitted as type SessionStatus uint32 with named flag constants plus (SessionStatus).Has(SessionStatus) bool and (SessionStatus).Or(SessionStatus) SessionStatus helpers. Unknown future bits round-trip naturally.

omitempty policy

Only optional pointer fields carry ,omitempty. Required fields (including required slices, maps, and scalars) MUST NOT carry omitempty — Go's omitempty omits empty slices, zero ints, and false, which would break wire parity (e.g. serverSeq: 0 on an ActionEnvelope, required empty responseParts: [] arrays).

Library structure

  • ahptypes/common.go — hand-written primitives (URI, StringOrMarkdown, JSONObject, marker interfaces).
  • ahptypes/*.generated.go — wire types from the protocol spec.
  • ahp/client.go — async Client, request correlation, subscription fan-out, dispatchAction write-ahead.
  • ahp/transport.go — Transport interface, TransportMessage variants, BoxedTransport for heterogeneous storage.
  • ahp/reducers.go — pure Apply* reducers ported from types/channels-*/reducer.ts. Each accepts state *State and an action and returns a ReduceOutcome.
  • ahp/error.go — ClientError, TransportError types implementing Go's error interface; use errors.Is / errors.As to discriminate.
  • ahp/hosts/ — MultiHostClient, HostHandle, HostClientHandle, ReconnectPolicy, ClientIDStore, etc.
  • ahpws/transport.go — WebSocket transport that wraps a github.com/coder/websocket connection.

Reducers

Reducers mutate *State in place to match the Rust client's apply_action_to_* semantics. The same fixtures from types/test-cases/reducers/*.json exercise the Go reducers via ahp/reducers_fixture_test.go so cross-language parity is enforced.

Tag namespace (release)

Go requires tags for sub-module releases to be prefixed with the sub-module's directory inside the repo. So the publish tag is clients/go/vX.Y.Z (not go/vX.Y.Z and not the bare vX.Y.Z reserved for Swift). The Go module proxy will pick the tag up automatically.

Out of scope (intentional)

The current Go module ships wire types, reducers, single- and multi- host client runtime, and a WebSocket transport. The following are deferred:

  • Example application beyond the small examples/ snippets.
  • Kotlin Multiplatform-style cross-target build.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.