Skip to content

Latest commit

 

History

History
97 lines (69 loc) · 2.62 KB

File metadata and controls

97 lines (69 loc) · 2.62 KB

langchain-js-basic-agent

Requirement Version
Agent Assembly Node.js SDK (@agent-assembly/sdk) 0.0.1-rc.6

Install:

pnpm add @agent-assembly/sdk@0.0.1-rc.6
# or
npm install @agent-assembly/sdk@0.0.1-rc.6
# or
yarn add @agent-assembly/sdk@0.0.1-rc.6

A LangChain.js-style agent example showing how to integrate the Agent Assembly Node.js SDK for tool governance.

What this example demonstrates

  • Wrapping tools with withAssembly() + a custom GatewayClient that enforces a local policy
  • Governing every tool call through a local policy before execution
  • One allowed tool call (get_weather) — executes and logs output
  • One denied tool call (delete_file) — blocked at the policy layer
  • A denied tool throws PolicyViolationError; runs fully offline (no gateway, no @langchain/core)

Prerequisites

  • Node.js >= 20 LTS
  • pnpm (npm install -g pnpm)

Install

pnpm install

Run

pnpm start

Expected output

=== LangChain.js-style Agent Assembly Example ===

Running allowed tool: get_weather
  [ALLOW] Weather in Taipei: 22°C, partly cloudy. [mock]

Running denied tool: delete_file
  [BLOCKED] Tool 'delete_file' blocked: Destructive filesystem operations require human approval.

Done. Tool calls governed by withAssembly + the local policy.

Test

pnpm test

Tests run in offline mode — no gateway or API keys required.

TypeScript type check

pnpm typecheck

Offline-only demo (no real-provider mode)

This example runs fully offline. Tool calls are governed in-process by a local fail-closed policy stub (createPolicyGatewayClient in src/policy.ts) — no gateway, no API key, and no network are involved. The example reads no environment variables: AAASM_GATEWAY_URL, OPENAI_API_KEY, and friends have no effect here, so there is no "real-provider" mode to switch into. Wiring these examples to a real gateway/LLM via the SDK's initAssembly is a possible future enhancement, tracked separately — not current behavior.

Troubleshooting

Problem Solution
Cannot find module '@agent-assembly/sdk' Run pnpm install
TypeScript errors Run pnpm typecheck and check Node.js version

Links