Golem call from external effect

From golemcloud/golem · View interactive version

Golem call from external effect is an AI agent skill from the GitHub repository golemcloud/golem. Calling Effect-based Golem agents from external Node.js applications with generated TypeScript bridge clients and Effect v4. Use for standalone Effect CLIs, servers, or scripts that invoke deployed agents from outside Golem.

How to use this skill

Skill file

Calling Effect Agents from External Applications

Use Golem's generated external TypeScript bridge for a standalone Effect/Node.js application.

An Effect component publishes TypeScript-shaped agent metadata, so its generated bridge classes,

agent id values, method names, values, and CLI references use TypeScript syntax.

The client attached to an @golemcloud/effect-golem agent spec is not an external network

client. It uses the Golem golem:agent/host RPC binding and works only inside a deployed Golem

component. Do not import that client, HostLive, or any other Effect Golem host service into a

standalone Node.js process.

Steps

  1. Ensure the Effect agent has the required TypeScript name and method contract, then build it.
  2. Configure a ts external bridge in golem.yaml for the Promise-based client used below. An

effect bridge target also exists, but has a different Effect-native API.

  1. Run golem build to regenerate the bridge from the built agent metadata.
  2. Deploy the built application so the external client can reach the current agent definition.
  3. Install and build the generated npm package.
  4. Add the generated package and the same Effect v4 version used by the component to a standalone

Node.js project.

  1. Configure the generated client, wrap its Promise operations with Effect.tryPromise, and run

the Effect program with Effect.runPromise.

Generate the TypeScript Bridge

Add or extend the top-level bridge section in golem.yaml:

bridge:
  ts:
    external:
      agents:
        - CounterAgent
      outputDir: ./bridge-sdk/ts

agents accepts "*" or a list containing agent type names and component names

(namespace:name). Preserve any existing bridge languages and selected agents.

For this Promise-based client:

Effect-native generated API;

golem-temp/bridge-sdk/ts/counter-agent-client/.

Generate the bridge as part of the normal build:

golem build

The build first compiles the Effect component, reads its final agent metadata, and then generates

the selected bridge packages. Re-run it whenever the constructor, methods, or schemas change.

Prefer this manifest-driven flow over the low-level golem generate-bridge command.

Deploy the same build before running an external client, especially after renaming an agent or

changing its contract:

golem deploy --yes

Build the generated package before consuming it:

cd bridge-sdk/ts/counter-agent-client
npm install
npm run build

The generated directory is a self-contained ESM package. For CounterAgent, its package name is

counter-agent-client, and its main module exports the CounterAgent class and configure

function. Inspect the generated .d.ts file when exact constructor or method types are needed;

do not guess them from the component source.

Set Up the Standalone Effect Application

Create the external application outside the Golem component source. Add the generated package as

a file dependency and install Effect v4. Keep the effect version exactly aligned with the root

Effect component's package.json (the current SDK uses 4.0.0):

{
  "name": "external-client",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "tsc",
    "start": "node dist/main.js"
  },
  "dependencies": {
    "counter-agent-client": "file:../bridge-sdk/ts/counter-agent-client",
    "effect": "4.0.0"
  },
  "devDependencies": {
    "@types/node": "^25",
    "typescript": "^5.9"
  }
}

Use an ESM TypeScript configuration such as:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "outDir": "dist",
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*.ts"]
}

Run npm install in the external application after the generated package has been built.

Invoke an Agent from Effect

Generated external bridge operations return native Promises. Effect.tryPromise is the boundary

adapter: its thunk defers the network operation until the Effect runs and turns synchronous throws

or Promise rejections into Effect failures.

import { Console, Effect } from "effect";
import { CounterAgent, configure } from "counter-agent-client";

configure({
  server: { type: "local" },
  application: "my-app",
  environment: "local",
});

const program = Effect.gen(function* () {
  // Generated bridge constructors and methods use positional TypeScript arguments.
  // `upsert` returns the client without contacting the server; the first invocation creates
  // the keyed agent when it is missing.
  const counter = CounterAgent.upsert("ext-test");

  // Keep stateful calls sequential by yielding each Promise boundary separately.
  yield* Effect.tryPromise(() => counter.increment());
  yield* Effect.tryPromise(() => counter.increment());
  const last = yield* Effect.tryPromise(() => counter.increment());

  yield* Console.log(last);
  return last;
});

await Effect.runPromise(program);

This external program imports Effect from effect, but it does not import

@golemcloud/effect-golem. The generated package uses @golemcloud/golem-ts-bridge transitively

to call Golem's REST API.

TypeScript Calling Conventions

Effect agent definitions use named records inside the component:

Counter.client.upsert({ name: "ext-test" });
remote.add({ by: 2 });

Do not copy that guest-side syntax into the generated external bridge. Generated bridge

constructors and methods are positional, in declaration order:

const externalCall = Effect.gen(function* () {
  const counter = CounterAgent.upsert("ext-test");
  return yield* Effect.tryPromise(() => counter.add(2));
});

Names retain TypeScript casing from the Effect metadata: for example, CounterAgent,

getCurrentValue, and repositoryName. The TypeScript bridge represents WIT u64 and s64

values as JavaScript bigint, including values nested inside records, lists, options, and results.

Pass bigint literals such as 1n; do not coerce 64-bit values to number. The bridge uses decimal

integer tokens on the JSON wire and converts responses back to bigint without routing them through

lossy JavaScript numbers.

This is a breaking change for clients generated by older Golem versions, which exposed these WIT

types as number. Regenerate and rebuild the bridge, then update callers to pass and consume

bigint. Other integer widths remain JavaScript number.

Server Configuration

Call the generated package's configure function once before constructing a client:

// Local server at http://localhost:9881
configure({
  server: { type: "local" },
  application: "my-app",
  environment: "local",
});

// Golem Cloud
configure({
  server: { type: "cloud", token: process.env.GOLEM_TOKEN! },
  application: "my-app",
  environment: "prod",
});

// Custom deployment
configure({
  server: {
    type: "custom",
    url: "https://my-golem.example.com",
    token: process.env.GOLEM_TOKEN!,
  },
  application: "my-app",
  environment: "prod",
});

Use configure, not globalConfig. Keep tokens out of source control and logs.

Keyed Agents, Agents Without a Key, and Agent IDs

For a durable agent, upsert addresses the keyed agent of its agent id values; the server creates

it on the first invocation when it is missing. upsert is synchronous:

const agent = MyAgent.upsert("my-instance");

Durable agents also have create and getById. Without keyed, create creates a new agent

without a key and with a new agent ID, even when other agents have the same agent id values.

agentId() returns the ID, and getById reconnects to an existing agent:

const createProgram = Effect.gen(function* () {
  const fresh = yield* Effect.tryPromise(() => MyAgent.create("shared-name"));
  const agentId = yield* Effect.tryPromise(() => fresh.agentId());
  const same = yield* Effect.tryPromise(() => MyAgent.getById(agentId));
  return { fresh, same };
});

getById never creates an agent: an unknown ID, or the ID of an agent of another type, rejects

with a GolemServiceError of status 404. create takes the options

{ keyed?, config?, env? } after the agent id values: keyed: true creates the keyed agent and

rejects with GolemConflictError (a GolemServiceError subclass with status 409) when it exists,

config sets local configuration values, and env adds

environment variables. upsert takes no configuration. Ephemeral agents have only upsert. Read

the generated declarations because configuration options reflect the agent's exact schema.

The bridge.ts.external Promise client used above rejects with that error from

@golemcloud/golem-ts-bridge. The shorthand Effect.tryPromise(() => ...) wraps the rejection in

UnknownError; inspect its cause for the original GolemConflictError, or use the object form

with an explicit catch mapper to preserve and type the conflict in the error channel.

For a client generated with bridge.effect.external, create instead returns

Effect.Effect<MyAgent, GolemConflictError | Error> and preserves the conflict directly in its

typed error channel. Do not wrap this Effect in Effect.tryPromise. Handle the conflict with

Effect.catchTag:

// MyAgent is imported from the generated Effect client, not the Promise client.
const createProgram = MyAgent.create("my-instance", { keyed: true }).pipe(
  Effect.catchTag("GolemConflictError", (error) =>
    Console.log("Keyed agent already exists:", error.status, error.body),
  ),
);

For the Promise client, generated remote methods are callable Promises for invoke-and-await and expose

abortable(signal, ...args). Durable non-streaming methods also expose trigger(...args) and

schedule(isoTimestamp, ...args), which return void. Ephemeral trigger/schedule operations return

Promise<InvocationReceipt>. Streaming methods do not expose trigger or schedule variants.

CLI Values for Effect Components

The Golem CLI also uses TypeScript names and values for Effect components:

golem agent invoke --no-stream 'CounterAgent("ext-test")' increment
golem agent invoke --no-stream 'CounterAgent("ext-test")' add 2

Use exact defineAgent and method names, including camelCase. CLI invocation is useful for manual

checks, but the external application should use the generated bridge for typed calls.

Key Constraints

external target also exists and exposes a different API.

invocation API directly.

Authoritative Effect SDK References

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.