Adding a new TypeScript agent to a Golem component. Use when the user asks to create, add, or define a new agent type, implement an agent class, or add agent methods in a TypeScript Golem project.
An agent is a durable, stateful unit of computation in Golem. Each agent type is a class decorated with @agent() that extends BaseAgent from @golemcloud/golem-ts-sdk.
src/<agent-name>.ts@agent(), extend BaseAgentmain.ts — add import './<agent-name>'; to src/main.tsgolem build to verifysrc/main.ts is the entrypoint module that must import each agent module for side effects. Agent classes do not need to be exported for discovery — importing the module is sufficient because registers the class.
@agent()import { BaseAgent, agent } from '@golemcloud/golem-ts-sdk';
@agent()
class CounterAgent extends BaseAgent {
private readonly name: string;
private value: number = 0;
constructor(name: string) {
super();
this.name = name;
}
async increment(): Promise<number> {
this.value += 1;
return this.value;
}
async getCount(): Promise<number> {
return this.value;
}
}
Use TypeScript type aliases or interfaces for parameters and return types. Use named types instead of anonymous inline object types for better interoperability. TypeScript enums are not supported — use string literal unions instead:
type Coordinates = { lat: number; lon: number };
type WeatherReport = { temperature: number; description: string };
type Priority = "low" | "medium" | "high";
@agent()
class WeatherAgent extends BaseAgent {
constructor(apiKey: string) {
super();
}
async getWeather(coords: Coordinates): Promise<WeatherReport> {
// ...
}
}
golem-js-runtime for details on the QuickJS runtime environment, available Web/Node.js APIs, and npm compatibilitygolem-file-io-ts for reading and writing files from agent codeBaseAgent and be decorated with @agent()golem-typegen for type metadata extraction; ensure experimentalDecorators and emitDecoratorMetadata are enabled in tsconfig.json