@agent-os-lab/agent-sdk 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -1
- package/USAGE.md +70 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -162,6 +162,7 @@ await client.createProfile({
|
|
|
162
162
|
await client.createAgent({
|
|
163
163
|
agentId: "support-agent",
|
|
164
164
|
displayName: "Support Agent",
|
|
165
|
+
billingSubjectId: "company-a/user-123",
|
|
165
166
|
systemPrompt: "You are a support assistant.",
|
|
166
167
|
model: "openai/gpt-5.2",
|
|
167
168
|
memoryProvider: "none",
|
|
@@ -199,6 +200,62 @@ for await (const event of client.streamMessage("support-agent", session.sessionI
|
|
|
199
200
|
}
|
|
200
201
|
```
|
|
201
202
|
|
|
203
|
+
## Billing Attribution And Export
|
|
204
|
+
|
|
205
|
+
Set `billingSubjectId` on Agents or Wikis when a tenant application needs cost attribution for one of its own business users, teams, or accounts. Per-request APIs that accept `billingSubjectId` can override the resource default for that request.
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
await client.createAgent({
|
|
209
|
+
agentId: "support-agent",
|
|
210
|
+
displayName: "Support Agent",
|
|
211
|
+
billingSubjectId: "company-a/user-123",
|
|
212
|
+
systemPrompt: "You are a support assistant.",
|
|
213
|
+
model: "openai/gpt-5.2",
|
|
214
|
+
memoryProvider: "none",
|
|
215
|
+
memoryScopeMode: "both",
|
|
216
|
+
compressionEnabled: false,
|
|
217
|
+
memoryReviewEnabled: false,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
for await (const event of client.streamMessage("support-agent", session.sessionId, {
|
|
221
|
+
profileId: "business-user-123",
|
|
222
|
+
message: "Help me understand my invoice.",
|
|
223
|
+
billingSubjectId: "company-a/user-456",
|
|
224
|
+
})) {
|
|
225
|
+
// ...
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Pull billing events from a trusted backend with `listBillingEvents`. The cursor is `afterSequence`; poll until `hasMore` is false, then store `nextSequence` for the next polling cycle.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
let afterSequence = loadLastBillingSequence();
|
|
233
|
+
|
|
234
|
+
while (true) {
|
|
235
|
+
const page = await client.listBillingEvents({
|
|
236
|
+
afterSequence,
|
|
237
|
+
limit: 1000,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
await saveBillingEvents(page.events);
|
|
241
|
+
afterSequence = page.nextSequence;
|
|
242
|
+
|
|
243
|
+
if (!page.hasMore) {
|
|
244
|
+
await saveLastBillingSequence(afterSequence);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Use `billingSubjectId` to fetch one subject's ledger:
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
const page = await client.listBillingEvents({
|
|
254
|
+
billingSubjectId: "company-a/user-123",
|
|
255
|
+
limit: 1000,
|
|
256
|
+
});
|
|
257
|
+
```
|
|
258
|
+
|
|
202
259
|
## Create A Bot-Owned Agent And Wiki
|
|
203
260
|
|
|
204
261
|
For tenant product setup flows, use `createBotBundle` to create a Bot with its own Agent, optional Wiki, and optional channel account in one call. The SDK creates the Wiki first, passes the generated `wikiId` into Agent creation, creates the Bot bound to that Agent, then creates the channel account bound to the Bot.
|
|
@@ -538,6 +595,6 @@ Delete operations archive or deactivate control-plane resources. `deleteAgent` a
|
|
|
538
595
|
|
|
539
596
|
## Coverage
|
|
540
597
|
|
|
541
|
-
The server SDK covers tenant-scoped agent registry, profile registry, sessions, streaming, async runs, memory, session search, lineage, and webhooks.
|
|
598
|
+
The server SDK covers tenant-scoped agent registry, profile registry, sessions, streaming, async runs, memory, session search, lineage, billing event export, and webhooks.
|
|
542
599
|
|
|
543
600
|
The browser SDK covers the current-user conversation surface: sessions, sync messages, streaming messages, async runs, run polling, cancellation, and run event replay.
|
package/USAGE.md
CHANGED
|
@@ -78,6 +78,7 @@ The browser client strips caller-provided `authorization` and `x-hermes-tenant-i
|
|
|
78
78
|
- Sessions and messages: create, list, get, send, stream, continue, lineage, search.
|
|
79
79
|
- Attachments: create upload, confirm upload, list, get, retry conversion.
|
|
80
80
|
- Async runs: create, get, cancel, replay events.
|
|
81
|
+
- Billing: assign `billingSubjectId` and pull billing events with cursor pagination.
|
|
81
82
|
- AG-UI: create an AG-UI chat facade, create an AG-UI HTTP agent, and inspect active runs for stream resume.
|
|
82
83
|
- Memory: read, create entry, delete entry.
|
|
83
84
|
- Tenant: get current tenant.
|
|
@@ -168,6 +169,7 @@ await client.createProfile({
|
|
|
168
169
|
await client.createAgent({
|
|
169
170
|
agentId: "support-agent",
|
|
170
171
|
displayName: "Support Agent",
|
|
172
|
+
billingSubjectId: "company-a/user-123",
|
|
171
173
|
systemPrompt: "You are a support assistant.",
|
|
172
174
|
model: "openai/gpt-5.2",
|
|
173
175
|
memoryProvider: "none",
|
|
@@ -177,6 +179,74 @@ await client.createAgent({
|
|
|
177
179
|
});
|
|
178
180
|
```
|
|
179
181
|
|
|
182
|
+
## Billing Attribution And Export
|
|
183
|
+
|
|
184
|
+
`billingSubjectId` is the tenant application's own attribution key. Store any stable string that your business system can resolve, such as `company-a/user-123` or `account-42/team-7`. AgentOS stores the string and returns it in billing records; it does not interpret hierarchy.
|
|
185
|
+
|
|
186
|
+
Resource defaults:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
await client.createAgent({
|
|
190
|
+
agentId: "support-agent",
|
|
191
|
+
displayName: "Support Agent",
|
|
192
|
+
billingSubjectId: "company-a/user-123",
|
|
193
|
+
systemPrompt: "You are a support assistant.",
|
|
194
|
+
model: "openai/gpt-5.2",
|
|
195
|
+
memoryProvider: "none",
|
|
196
|
+
memoryScopeMode: "both",
|
|
197
|
+
compressionEnabled: false,
|
|
198
|
+
memoryReviewEnabled: false,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
await client.createWiki({
|
|
202
|
+
wikiId: "support-knowledge",
|
|
203
|
+
displayName: "Support Knowledge",
|
|
204
|
+
billingSubjectId: "company-a",
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Per-request override:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
await client.sendMessage("support-agent", session.sessionId, {
|
|
212
|
+
profileId: "business-user-123",
|
|
213
|
+
message: "Explain my latest invoice.",
|
|
214
|
+
billingSubjectId: "company-a/user-456",
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Billing export is server-only. Use `listBillingEvents` from a trusted backend and persist the returned `nextSequence` as your cursor. A typical sync job can run every few minutes and keep pulling pages until `hasMore` is false.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
let afterSequence = await loadLastBillingSequence();
|
|
222
|
+
|
|
223
|
+
while (true) {
|
|
224
|
+
const page = await client.listBillingEvents({
|
|
225
|
+
afterSequence,
|
|
226
|
+
limit: 1000,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
await upsertBillingEvents(page.events);
|
|
230
|
+
afterSequence = page.nextSequence;
|
|
231
|
+
|
|
232
|
+
if (!page.hasMore) {
|
|
233
|
+
await saveLastBillingSequence(afterSequence);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Filter by one subject when reconciling a tenant user's bill:
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
const page = await client.listBillingEvents({
|
|
243
|
+
billingSubjectId: "company-a/user-123",
|
|
244
|
+
limit: 1000,
|
|
245
|
+
});
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Each event includes `sequence`, `billingSubjectId`, `source`, `sourceId`, resource ids such as `agentId`/`wikiId`/`runId`, `cost`, `currency`, `totalTokens`, and the raw `payload`.
|
|
249
|
+
|
|
180
250
|
## Creating A Bot Bundle
|
|
181
251
|
|
|
182
252
|
Use `createBotBundle` when a tenant application wants a productized setup flow for a Bot-owned Agent. The SDK creates the resources in order: Wiki, Agent, Bot, then Bot channel account. If `wiki` is present, the new Agent is created with `wikiId` already bound.
|