Skip to Content
InvokeExternal Bridge Libraries

External Bridge Libraries

Bridge libraries let you invoke Golem agents from non-Golem applications in a type-safe way. Golem generates self-contained Rust crates, Node.js TypeScript and Effect TypeScript npm packages, Scala sbt projects, MoonBit modules, and Go modules that implement a fully typed client for specific agents.

Methods without streams use the existing REST invocation API and remain compatible with previously generated clients. A method whose input or output contains a stream instead opens the public streaming WebSocket endpoint described below.

Configuring Bridge Generation in golem.yaml

To generate bridge libraries, add a bridge section to your golem.yaml:

bridge: ts: external: agents: - InboxAgent - EscalationAgent effect: external: agents: WorkflowAgent rust: external: agents: AuditAgent scala: external: agents: BillingAgent moonbit: external: agents: ReportAgent go: external: agents: SyncAgent

This will generate TypeScript packages for InboxAgent and EscalationAgent, an Effect-native TypeScript package for WorkflowAgent, a Rust crate for AuditAgent, a Scala sbt project for BillingAgent, a MoonBit module for ReportAgent, and a Go module for SyncAgent.

Using Bridge Libraries

Once generated, you can use the bridge libraries like any other typed client. First configure the connection, then interact with agents:

import { CounterAgent, configure } from 'counter-agent-client/counter-agent-client.js' configure({ server: { type: 'local' }, application: 'bridgetest', environment: 'local' }) const c1 = await CounterAgent.get('c1') const value = await c1.increment()

Streaming Methods

Generated clients preserve streams wherever they occur in a method’s typed input or output, including nested values and multiple sibling streams. The examples below assume a MediaAgent with input-only upload, output-only transcribe, and mixed transform methods. The generated method names and parameter order follow the agent definition; there is no separate streaming method suffix.

import { agentStream } from '@golemcloud/golem-ts-bridge' import { MediaAgent, configure } from 'media-agent-client/media-agent-client.js' configure({ server: { type: 'local' }, application: 'media-app', environment: 'prod' }) const agent = await MediaAgent.get('studio-a') async function* samples() { yield 1 yield 2 } // Input-only. agentStream enforces a single call to Symbol.asyncIterator. await agent.upload(agentStream(samples())) // Output-only. for await (const word of await agent.transcribe()) console.log(word) // Mixed, with explicit whole-invocation cancellation. const controller = new AbortController() const output = await agent.transform.abortable(controller.signal, agentStream(samples())) for await (const item of output) { console.log(item) controller.abort() break // Returning from iteration drops and cancels this unread output stream. }

Streaming TypeScript bridges run on Node.js only. Browser WebSocket streaming is not supported. Non-streaming generated TypeScript methods can still use fetch in their existing supported environments.

Raw binary lanes

Direct stream<u8> and stream<binary> values use binary WebSocket frames rather than JSON/base64 for their item data. stream<u8> treats every byte as one logical item. stream<binary> treats each frame chunk as an AgentBinary item with bytes and an optional MIME type. Streams nested inside another value still retain their structural position, while their bytes travel on the corresponding binary lane.

For example, a video-processing client can stream a multi-megabyte recording without constructing one enormous JSON value:

import { createReadStream } from 'node:fs' import { agentStream, type AgentBinary } from '@golemcloud/golem-ts-bridge' async function* videoChunks(path: string): AsyncGenerator<AgentBinary> { for await (const chunk of createReadStream(path, { highWaterMark: 1024 * 1024 })) { yield { bytes: new Uint8Array(chunk), mimeType: 'video/mp4' } } } // A 250 MiB video is sent as 1 MiB binary items with normal stream back-pressure. const preview = await agent.makePreview(agentStream(videoChunks('recording.mp4'))) for await (const audioChunk of preview) { await audioSink.write(audioChunk.bytes) // e.g. AgentBinary with audio/aac }

Use a stream of structured records instead when each item needs additional application metadata.

The generated runtime manages the WebSocket connection and reconnects using in-memory session state. Applications do not need to open the socket directly. See the streaming protocol reference for transport and recovery details, or CLI streaming methods for command-line usage and persistent checkpoints.

Configuration Options

The TypeScript, Effect TypeScript, Rust, Scala, MoonBit and Go bridge libraries require three configuration parameters:

ParameterDescription
ServerLocal for the default local Golem server, Cloud for Golem Cloud, or a custom deployment URL and bearer token
Application nameThe app: key from your golem.yaml
EnvironmentThe target environment (e.g., local, staging, prod)

Type Safety

The generated libraries define all custom data types used in parameters and return types of agent methods. This means you get full compile-time type checking and IDE autocompletion when interacting with agents from external applications.

Bridge libraries follow the same conventions as agent-to-agent RPC, providing get, getPhantom, and newPhantom constructors for agent instances.