Golem durable streams go

From golemcloud/golem · View interactive version

Golem durable streams go is an AI agent skill from the GitHub repository golemcloud/golem. Exposes stream-bearing Go agent methods over HTTP through the Durable Streams protocol. Use for golem.DurableStreams, StreamRoute and StreamSlot options, session and slot URLs, external readers or writers appending to and tailing an invocation's streams, or reading and writing any Durable Stream fro

How to use this skill

Skill file

Durable Streams in Go

Durable Streams is the resumable HTTP protocol for the streams of one invocation. golem.AgentStream[T] declares the stream values of a method (see golem-streaming-agent-go); when that method is an HTTP endpoint, the platform gives each stream a stable URL that external clients append to, read, resume, cancel and fork.

Expose a Stream-Bearing Method

Every HTTP endpoint whose method takes or returns an AgentStream is served this way. golem.DurableStreams customizes the route:

package pipe

import "github.com/golemcloud/golem/sdks/go/golem"

type ID struct{ Name string }

type UppercaseIn struct {
	Input golem.AgentStream[string]
}

var Agent = golem.DefineAgent[ID](golem.Spec{
	Name: "Pipe",
	HTTP: &golem.Mount{Path: "/pipes/{name}"},
})

var Uppercase = Agent.Method[UppercaseIn, golem.AgentStream[string]]("uppercase",
	golem.HTTP(golem.POST("/uppercase", golem.DurableStreams(golem.StreamRoute{
		Slots: []golem.StreamSlot{
			{Input: "input", Name: "inbox"},
			{Result: true, Name: "outbox"},
		},
		MaxReadersPerStream: 8,
		MaxAppendsPerSecond: 25,
	}))))
agent.Handle(pipe.Uppercase, func(_ *golem.Context[state], in pipe.UppercaseIn) golem.AgentStream[string] {
	return golem.ProduceStream(func(w *golem.AgentStreamWriter[string]) error {
		for line := range in.Input.All() {
			if err := w.Write(strings.ToUpper(line)); err != nil {
				return nil
			}
		}
		return nil
	})
})

Add the agent to an httpApi deployment in golem.yaml (see golem-add-http-endpoint-go).

Mistakes in a StreamRoute are definition errors reported by golem build.

The Protocol

<base>                                                  PUT creates a generated session
<base>/invocations/<session>                            PUT / GET / HEAD / DELETE the session
<base>/invocations/<session>/streams/<slot>             PUT / GET / HEAD / POST / DELETE a slot
<base>/forks/<fork>/invocations/<session>/streams/<slot>

Create or ensure the session first when not every method argument comes from the path or query. Input slots accept POST only while external writes are allowed; output slots are read-only.

Writing

Reading

Control

Clients

External programs speak the protocol over plain HTTP. To call a streaming method from a Go program instead, use the generated external Go bridge (golem-call-from-external-go), which runs it over an invocation session rather than Durable Streams URLs.

From inside a Go agent, read and write any Durable Streams URL — this deployment's or an external one — with github.com/golemcloud/golem/sdks/go/golem/durablestreams. The host does the HTTP and authentication, and the reader's checkpoint and the writer's producer progress survive replay:

type Config struct{ ExternalAuth golem.Secret[string] } // bearer token, never revealed to the agent

r := durablestreams.ReadJSON[Event](url, durablestreams.ReadOptions{
	Auth: golem.Some(ctx.Config(Agent).ExternalAuth),
})
events, err := r.Collect() // or r.Next() item by item; r.AgentStream() to return it

w, err := durablestreams.NewWriter(url, "application/json", durablestreams.WriteOptions{
	ProducerID: golem.Some("orders-1"), // stable id: a repeated append is deduplicated
	Auth:       golem.Some(ctx.Config(Agent).ExternalAuth),
})
receipt, err := durablestreams.AppendJSON(w, []Event{ev}, false) // true closes the stream
golem build
golem deploy --yes

Related Skills

| Skill | When to Load |

|-------|--------------|

| golem-streaming-agent-go | Declaring, producing and consuming AgentStream values |

| golem-add-http-endpoint-go | Mounts, endpoints and the httpApi deployment |

| golem-configure-api-domain | Deploying the HTTP API |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.