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…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- clients/dotnet/AGENTS.mdAGENTS.md
- clients/kotlin/AGENTS.mdAGENTS.md
- clients/swift/AGENTS.mdAGENTS.md
- docs/guide/agents.mdAGENTS.md
- channels-migrationSkill
- ahp-clientSkill
- session-metadata-migrationSkill
- groom-backlogSkill
- release-ahpSkill
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
- Very specific: line 92
Only optional pointer fields carry ,omitempty.
≈ “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.
Files
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/— asyncClient, reducers, and pluggableTransport. Sub- packageahp/hosts/carries the multi-host runtime.ahpws/— WebSocket transport built ongithub.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 --goGenerated 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)
| TypeScript | Go |
string | string |
number | int64 (TS contract: 64-bit ints) |
number w/ @format float | float64 |
boolean | bool |
unknown / object | json.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 enum | typed string + named constants |
| Bitset enum | typed uint32 + flag constants + Has/Or helpers |
| Interface struct | struct with JSON tags |
| Discriminated union | wrapper struct + marker interface + custom MarshalJSON/UnmarshalJSON |
URI | type URI = string |
StringOrMarkdown | struct w/ custom (un)marshal |
| Recursive struct | pointer field in the recursive position |
_meta field | Meta map[string]json.RawMessage + json:"_meta,omitempty" |
snake_case wire field | PascalCase 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— asyncClient, request correlation, subscription fan-out,dispatchActionwrite-ahead.ahp/transport.go—Transportinterface,TransportMessagevariants,BoxedTransportfor heterogeneous storage.ahp/reducers.go— pureApply*reducers ported fromtypes/channels-*/reducer.ts. Each acceptsstate *Stateand an action and returns aReduceOutcome.ahp/error.go—ClientError,TransportErrortypes implementing Go'serrorinterface; useerrors.Is/errors.Asto discriminate.ahp/hosts/—MultiHostClient,HostHandle,HostClientHandle,ReconnectPolicy,ClientIDStore, etc.ahpws/transport.go— WebSocket transport that wraps agithub.com/coder/websocketconnection.
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.
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
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.

