Skip to content

Getting started (5 minutes) ​

This walks you from zero to your first running agent. Pick the model adapter that matches the API key you have on hand.

1. Install ​

bash
npm install @wasmagent/core @anthropic-ai/sdk
# or with Bun / pnpm
bun add @wasmagent/core @anthropic-ai/sdk

Using a Chinese model? Swap the install for one of the dedicated adapters: @wasmagent/model-doubao, @wasmagent/model-deepseek, @wasmagent/model-moonshot, @wasmagent/model-qwen, @wasmagent/model-zhipu, @wasmagent/model-minimax.

2. Set your key ​

bash
export ANTHROPIC_API_KEY=sk-ant-...   # or DOUBAO_API_KEY, DEEPSEEK_API_KEY, etc.

3. Write the agent ​

ts
// hello-agent.ts
import { CodeAgent, AnthropicModel, AnthropicModels } from "@wasmagent/core";

const agent = new CodeAgent({
  model: new AnthropicModel(AnthropicModels.SONNET_LATEST, {
    apiKey: process.env.ANTHROPIC_API_KEY!,
  }),
});

const result = await agent.run({ task: "What's 12 * 13?" });
console.log(result.finalAnswer); // → 156

4. Run it ​

bash
bun run hello-agent.ts
# or:  npx tsx hello-agent.ts

You should see the answer streamed back as the agent decides to compute (12 * 13) inside the default VmKernel.

5. Pick the right kernel for your environment ​

The default VmKernel uses node:vm and is fine for trusted local code. For everything else, swap in one of the WASM kernels:

Where you're runningUse
Cloudflare Workers / Vercel Edge / Deno Deploy@wasmagent/kernel-quickjs
Need real Python@wasmagent/kernel-pyodide
Strongest sandboxing without a microVM@wasmagent/kernel-wasmtime
Real shell / npm install / compilation@wasmagent/kernel-remote (E2B / CF Sandbox)
ts
import { CodeAgent } from "@wasmagent/core";
import { QuickJSKernel } from "@wasmagent/kernel-quickjs";

const agent = new CodeAgent({
  model: /* … */,
  kernel: new QuickJSKernel(),
});

What next? ​

6. Stream events and observe the run ​

Every agent emits structured AgentEvent objects. Iterate the run generator to see them:

ts
for await (const event of agent.run({ task: "List files in the sandbox" })) {
  if (event.event === "tool_call")   console.log("tool →", event.data.toolName);
  if (event.event === "final_answer") console.log("answer →", event.data.answer);
}

For OTel-compatible tracing (Jaeger, Honeycomb, Grafana), wrap with withOtel:

ts
import { withOtel, OtelBridge, InMemorySpanExporter } from "@wasmagent/core";

const exporter = new InMemorySpanExporter();
const bridge = new OtelBridge({ exporter });
for await (const event of withOtel(agent.run({ task: "…" }), bridge)) { /* … */ }
console.log(exporter.spans); // structured spans, compatible with OTLP export

7. Export a rollout JSONL for RLAIF ​

Run two branches and export a preference pair for downstream training:

ts
import { RolloutForkRunner } from "@wasmagent/core";

const runner = new RolloutForkRunner({ branches: 2, model, tools });
for await (const event of runner.run({ task: "Refactor this function" })) {
  if (event.event === "rollout_record") {
    // Each branch emits a rollout_record — write to JSONL for evomerge datafactory
    fs.appendFileSync("rollouts.jsonl", JSON.stringify(event.data) + "\n");
  }
}
// Then: python -m datafactory --input rollouts.jsonl --output-dpo dpo.jsonl

This is the "Runtime → Data Factory" loop that connects wasmagent-js to evomerge.

If anything blocks you, open an issue — friction in this guide is the bug we want to hear about.

8. Add policy to your MCP server (optional) ​

Install the guard packages and scan your tools for security risks:

bash
npm install @wasmagent/mcp-gateway @wasmagent/aep
bash
# Generate a policy config
wasmagent init --guard

# Scan your MCP server tools for injection/exfiltration risks
wasmagent scan-mcp ./tools.json

# Enforce policy before tool execution
wasmagent guard --config wasmagent.policy.yaml --upstream tools.json

# Export evidence after the run
wasmagent evidence export --input evidence.jsonl --format html --out report.html

Full guide: docs/guides/mcp-guard.md.

Released under the Apache-2.0 License.