# AZOWL AgentOps SDK

Use an agent's execution receipt to see which profile rule allowed or blocked a tool. The SDK supports tools embedded in your Node.js app, a direct connection to an installed AZWOL Agent, and tasks assigned through AZOWL Hub.

## Install the v1 alpha

Use Node.js 20 or later. The examples in this guide target `1.0.0-alpha.5`. The following command installs the version selected by npm’s `alpha` tag. Check the tag with `npm view @azowl/agentops-sdk dist-tags.alpha`.

```sh
npm install @azowl/agentops-sdk@alpha
```

To use `1.0.0-alpha.5` from source, run `npm pack` in the SDK checkout for that version. From your app directory, run `npm install /path/to/azowl-agentops-sdk-1.0.0-alpha.5.tgz` with the path to the generated file.

## Try a read-only profile

Run the bundled example from the same directory. It uses a sample document and runs offline without an account or API key.

```sh
node node_modules/@azowl/agentops-sdk/examples/document-policy.mjs
```

The example registers both tools, then runs each one under the `read-only` profile. It prints one JSON receipt per task.

| Tool | Decision and reason | Result |
| --- | --- | --- |
| `document.read` | `allow` · `in_allowlist` | Returns `Release checklist` |
| `document.update` | `deny` · `not_in_allowlist` | Blocks the call before the update handler runs |

## Use a tool from your application

```js
import { LocalAgent } from '@azowl/agentops-sdk/local';

const agent = new LocalAgent({
  profileId: 'read-only',
  allowedTools: ['document.read'],
  tools: { 'document.read': () => 'Release checklist' },
});
const task = await agent.run('document.read', {});
const receipt = agent.getReceipt(task.id);
console.log(receipt.policy.reason, receipt.result); // in_allowlist Release checklist
```

The receipt includes the tool, profile, rules digest, decision, reason and execution outcome. Each `LocalAgent` keeps running tasks and the last 100 terminal records in memory by default. Save the receipt in your app if you need it after the process exits.

## List tools available to an app

Use `listTools()` to show the tools available under the app’s active profile.

```js
import { LocalAgent } from '@azowl/agentops-sdk/local';

const documents = new Map([['checklist', 'Release checklist']]);
const agent = new LocalAgent({
  tools: {
    'document.read': (id) => {
      if (typeof id !== 'string') throw new TypeError('Expected a document ID');
      return documents.get(id) ?? null;
    },
    'document.count': () => documents.size,
  },
  allowedTools: ['document.read'],
  toolMetadata: {
    'document.read': { description: 'Read a document by ID', inputSchema: { type: 'string' } },
  },
});
console.log(agent.listTools().map(tool => tool.name)); // ['document.read']
```

The method returns a copy of each permitted tool's name and optional metadata in registration order. The schema describes the expected input. The handler validates the value it receives, and `start()` and `run()` check the profile's rules on every call.

## Let your model choose a tool

Run the inventory example bundled with `1.0.0-alpha.5` from your app directory.

```sh
node node_modules/@azowl/agentops-sdk/examples/inventory-agent.mjs
```

The example asks for the stock of product A. An offline adapter selects the inventory tool and uses the returned quantity of 7 to answer. To try local inference, start Ollama on port 11434 and pass the name of an installed, tool-capable model as the example's first argument.

To connect your own model, pass an adapter function to `agent.runWithModel(prompt, model)`. The SDK calls it with `{ messages, tools }`. Translate one model decision into `{ type: 'tool_call', name, input }` or `{ type: 'final', text }`. Your adapter owns the provider connection and credentials. The SDK checks each tool request against the agent's policy and returns its receipt in `receipts`. The optional third argument, `{ maxToolCalls }`, accepts 0 through 16 and defaults to 4.

## Connect to the AZWOL Agent on your PC

The `AgentClient` in SDK `1.0.0-alpha.5` connects to an installed agent that supports `serve`. In a separate terminal, start the agent with the sample team profile. [AZWOL Agent source and CLI](https://github.com/BlueteamK-kor/azwol-agent)

```sh
azwol-agent profile init team.json
azwol-agent serve --local-profile team.json
```

```js
import { AgentClient } from '@azowl/agentops-sdk';

const agent = new AgentClient({ baseUrl: 'http://localhost:43179' });
const order = { tool: 'order.total', input: { items: [{ unitPrice: 1250, quantity: 3 }] } };
const sale = await agent.tasks.create({ runnerId: 'desk', agentId: 'clerk', ...order });
console.log(sale.status, sale.result); // completed 3750
const review = await agent.tasks.create({ runnerId: 'review', agentId: 'reviewer', ...order });
console.log(review.status, review.policy.reason); // blocked explicitly_blocked
console.log((await agent.tasks.get(sale.id)).id); // same receipt ID
```

The installed agent loads its own tools and profile. On the same PC, the SDK reads the running agent's per-port token for your OS user. For another machine, set `baseUrl` to the agent's HTTPS address and supply its bearer via `AZWOL_AGENT_TOKEN` or the `token` option. A create returns a terminal receipt. If a connection drops while submitting, check the agent's history before submitting again to avoid duplicate execution.

## Run tasks in a local queue

With SDK `1.0.0-alpha.5` installed and the standalone `0.8.0-alpha.4` agent running as above, start the queue and worker adapter in separate terminals in your app directory.

```sh
npx azowl-queue start --worker desk/clerk
npx azowl-queue connect --runner desk --agent clerk
```

```js
import { randomUUID } from 'node:crypto';
import { LocalQueueClient } from '@azowl/agentops-sdk/queue';

const queue = new LocalQueueClient({ baseUrl: 'http://localhost:43180' });
const requestId = randomUUID(); // Retain this ID for retries.
const work = await queue.tasks.create({ requestId, runnerId: 'desk', agentId: 'clerk',
  tool: 'order.total', input: { items: [{ unitPrice: 1500, quantity: 2 }] } });
console.log(work.id, work.status); // queued immediately
const snapshot = await queue.tasks.get(work.id);
console.log(snapshot.status, snapshot.receipt?.result);
```

The adapter claims and renews the assignment's lease, calls the standalone agent on port 43179 and sends its original receipt to the queue. The queue task ID and the execution receipt ID identify different records. An expired lease leaves the task in `unknown`. Check the agent history before resubmitting. This loopback queue is for one trusted OS user. Producer and worker credentials rotate on server startup. Files are under the user configuration folder in `AZOWL/local-queue/43180`. Override with `--directory` and the matching client option. Enterprise Windows 0.6.58 validates its provisioned portal endpoint and device profile.

## Send work through AZOWL Hub

Import `AgentOpsClient` from `@azowl/agentops-sdk` to check the connected profile, submit a task to a registered PC, inspect its status, answer a follow-up question and retrieve the result. Connecting to Hub requires the organization's API address, ID and user token. [Developer guide](https://blueteamk.com/docs/agentops/developers/) · [Task handling](https://blueteamk.com/docs/agentops/sdk-tasks/)

In SDK `1.0.0-alpha.5`, import `AgentOpsClient` from `@azowl/agentops-sdk/hub` for the commercial Hub or `AgentClient` from `@azowl/agentops-sdk/agent` for a direct connection to an installed agent. Both clients remain available from the package root.

Choose a PC by its registered ID in `client.devices.list()` and use its expected profile hash when submitting a task. If the PC has a `profile_id`, `client.devices.getProfileConnection(profileId)` shows whether Hub has evidence that the PC applied the current manifest. Hub checks the organization's entitlement and the user's permissions on submission. Iterate over `client.tasks.watch(taskId)` to receive the first task snapshot and subsequent changes observed by polling. Intermediate changes between reads can be missed.

The standalone AZWOL Agent runs tasks on a PC or server and has its own release. [AZWOL Agent source and CLI](https://github.com/BlueteamK-kor/azwol-agent)

The SDK and its embedded local core are licensed under Apache-2.0. The package includes the license in `LICENSE` and attribution in `packages/local-core/NOTICE`.

한국어 사용법은 패키지의 `README.ko.md`에 있습니다.
