Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TypeScript Component Agent

Build an Akshi agent in TypeScript using WIT bindings and jco.

Prerequisites

  • Node.js 20+
  • jco installed (npm install -g @bytecodealliance/jco)
  • componentize-js installed (npm install -g @bytecodealliance/componentize-js)
  • Akshi CLI installed

Create the project

akshi create agent my-ts-agent --lang typescript
cd my-ts-agent

Project structure

my-ts-agent/
  src/
    index.ts
  wit/
    deps/
    world.wit
  package.json
  tsconfig.json

Write agent logic

Edit src/index.ts:

import { Agent, Context } from "akshi-sdk";

export class MyTsAgent implements Agent {
  tick(ctx: Context): void {
    const response = ctx.infer("What are today's top headlines?");
    ctx.journalInsert("headlines", response);
  }
}

Build

Compile TypeScript to JavaScript, then componentize:

npm run build
jco componentize dist/index.js -d wit/world.wit -w agent -o my_ts_agent.wasm

Configure

[[agents]]
name = "my-ts-agent"
wasm_path = "my_ts_agent.wasm"
tick_interval_secs = 3600
fuel_limit = 2_000_000

[agents.capabilities]
inference = true
journal = true

Run

akshi run

Limitations

  • TypeScript components include the JavaScript engine (~4 MB).
  • Some Node.js APIs (filesystem, network) are not available; use host capabilities instead.

Next steps