@kigathi/ai-agents 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/README.md +138 -82
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install openai
17
17
  ## Quick API shape
18
18
 
19
19
  ```js
20
- import { createClient } from '@kigathi/ai-agents';
20
+ import { createClient } from "@kigathi/ai-agents";
21
21
 
22
22
  const sdk = createClient(config);
23
23
  sdk.registerTool(tool);
@@ -25,6 +25,66 @@ sdk.createAgent(agent);
25
25
  const result = await sdk.run(params);
26
26
  ```
27
27
 
28
+ ## Modes
29
+
30
+ The SDK supports three setup patterns, and in normal usage you do not need to pass `mode` manually. The client infers it from the config you provide.
31
+
32
+ ### 1. Direct mode
33
+
34
+ Use this when your app should call OpenAI directly and you do not need backend persistence.
35
+
36
+ ```js
37
+ import { createClient } from "@kigathi/ai-agents";
38
+
39
+ const sdk = createClient({
40
+ apiKey: process.env.OPENAI_API_KEY,
41
+ });
42
+ ```
43
+
44
+ Required:
45
+
46
+ - `apiKey`
47
+
48
+ ### 2. Proxy mode
49
+
50
+ Use this when your app should call your backend, and your backend should perform the agent run.
51
+
52
+ ```js
53
+ import { createClient } from "@kigathi/ai-agents";
54
+
55
+ const sdk = createClient({
56
+ backendUrl: "https://api.example.com",
57
+ });
58
+ ```
59
+
60
+ Required:
61
+
62
+ - `backendUrl`
63
+
64
+ ### 3. Direct mode with backend persistence
65
+
66
+ Use this when your app should call OpenAI directly, but you still want your backend to persist messages, receive tool events, or trigger downstream workflows.
67
+
68
+ ```js
69
+ import { createClient } from "@kigathi/ai-agents";
70
+
71
+ const sdk = createClient({
72
+ apiKey: process.env.OPENAI_API_KEY,
73
+ backendUrl: "https://api.example.com",
74
+ });
75
+ ```
76
+
77
+ Required:
78
+
79
+ - `apiKey`
80
+ - `backendUrl`
81
+
82
+ Behavior summary:
83
+
84
+ - `apiKey` only: direct OpenAI execution
85
+ - `backendUrl` only: proxy mode, where your backend performs the run
86
+ - `apiKey` and `backendUrl` together: direct OpenAI execution plus backend persistence and event sync
87
+
28
88
  ## Minimal vs full examples
29
89
 
30
90
  The sections below show the smallest valid call for each API, followed by a more realistic production-style example.
@@ -34,7 +94,7 @@ The sections below show the smallest valid call for each API, followed by a more
34
94
  Minimal direct mode:
35
95
 
36
96
  ```js
37
- import { createClient } from '@kigathi/ai-agents';
97
+ import { createClient } from "@kigathi/ai-agents";
38
98
 
39
99
  const sdk = createClient({
40
100
  apiKey: process.env.OPENAI_API_KEY,
@@ -44,26 +104,25 @@ const sdk = createClient({
44
104
  Minimal proxy mode:
45
105
 
46
106
  ```js
47
- import { createClient } from '@kigathi/ai-agents';
107
+ import { createClient } from "@kigathi/ai-agents";
48
108
 
49
109
  const sdk = createClient({
50
- backendUrl: 'https://api.example.com',
110
+ backendUrl: "https://api.example.com",
51
111
  });
52
112
  ```
53
113
 
54
114
  Full example:
55
115
 
56
116
  ```js
57
- import { createClient } from '@kigathi/ai-agents';
117
+ import { createClient } from "@kigathi/ai-agents";
58
118
 
59
119
  const sdk = createClient({
60
120
  apiKey: process.env.OPENAI_API_KEY,
61
121
  orgId: process.env.OPENAI_ORG_ID,
62
122
  projectId: process.env.OPENAI_PROJECT_ID,
63
- backendUrl: 'https://api.example.com',
64
- mode: 'direct',
123
+ backendUrl: "https://api.example.com",
65
124
  pricing: {
66
- 'gpt-4.1-mini': {
125
+ "gpt-4.1-mini": {
67
126
  prompt_per_million: 0.4,
68
127
  completion_per_million: 1.6,
69
128
  },
@@ -90,12 +149,11 @@ You can also run the model directly with OpenAI while still sending conversation
90
149
  Use `apiKey` and `backendUrl` together:
91
150
 
92
151
  ```js
93
- import { createClient } from '@kigathi/ai-agents';
152
+ import { createClient } from "@kigathi/ai-agents";
94
153
 
95
154
  const sdk = createClient({
96
155
  apiKey: process.env.OPENAI_API_KEY,
97
- backendUrl: 'https://api.example.com',
98
- mode: 'direct',
156
+ backendUrl: "https://api.example.com",
99
157
  });
100
158
  ```
101
159
 
@@ -120,7 +178,7 @@ Minimal example:
120
178
 
121
179
  ```js
122
180
  sdk.registerTool({
123
- name: 'lookup_order',
181
+ name: "lookup_order",
124
182
  });
125
183
  ```
126
184
 
@@ -128,20 +186,20 @@ Full example:
128
186
 
129
187
  ```js
130
188
  sdk.registerTool({
131
- name: 'lookup_order',
132
- type: 'function',
133
- description: 'Find order details by order number.',
189
+ name: "lookup_order",
190
+ type: "function",
191
+ description: "Find order details by order number.",
134
192
  parameters_schema: {
135
- type: 'object',
193
+ type: "object",
136
194
  properties: {
137
- order_number: { type: 'string' },
195
+ order_number: { type: "string" },
138
196
  },
139
- required: ['order_number'],
197
+ required: ["order_number"],
140
198
  },
141
199
  handler: async ({ order_number }, context) => {
142
200
  return {
143
201
  order_number,
144
- status: 'processing',
202
+ status: "processing",
145
203
  requested_by: context.userId ?? null,
146
204
  };
147
205
  },
@@ -169,8 +227,8 @@ Minimal example:
169
227
 
170
228
  ```js
171
229
  sdk.createAgent({
172
- name: 'support-bot',
173
- model: 'gpt-4.1-mini',
230
+ name: "support-bot",
231
+ model: "gpt-4.1-mini",
174
232
  });
175
233
  ```
176
234
 
@@ -178,16 +236,16 @@ Full example:
178
236
 
179
237
  ```js
180
238
  sdk.createAgent({
181
- id: 'support-bot-v1',
182
- name: 'support-bot',
183
- model: 'gpt-4.1-mini',
184
- instructions: 'You are a concise support assistant. Use tools when needed.',
239
+ id: "support-bot-v1",
240
+ name: "support-bot",
241
+ model: "gpt-4.1-mini",
242
+ instructions: "You are a concise support assistant. Use tools when needed.",
185
243
  temperature: 0.3,
186
244
  max_output_tokens: 400,
187
- tools: ['lookup_order'],
245
+ tools: ["lookup_order"],
188
246
  metadata: {
189
- team: 'support',
190
- channel: 'web',
247
+ team: "support",
248
+ channel: "web",
191
249
  },
192
250
  });
193
251
  ```
@@ -212,8 +270,8 @@ Minimal example:
212
270
 
213
271
  ```js
214
272
  const result = await sdk.run({
215
- agent: 'support-bot',
216
- message: 'Where is order AX-4420?',
273
+ agent: "support-bot",
274
+ message: "Where is order AX-4420?",
217
275
  });
218
276
 
219
277
  console.log(result.output_text);
@@ -223,18 +281,18 @@ Full example:
223
281
 
224
282
  ```js
225
283
  const result = await sdk.run({
226
- agent: 'support-bot',
227
- message: 'Check order AX-4420 and summarize the current status.',
284
+ agent: "support-bot",
285
+ message: "Check order AX-4420 and summarize the current status.",
228
286
  conversation_id: 1234,
229
- conversation_key: 'support:customer-42',
287
+ conversation_key: "support:customer-42",
230
288
  user_id: 42,
231
289
  context: {
232
290
  userId: 42,
233
- accountId: 'acc_123',
291
+ accountId: "acc_123",
234
292
  },
235
293
  messages: [
236
- { role: 'user', content: 'Hi' },
237
- { role: 'assistant', content: 'How can I help?' },
294
+ { role: "user", content: "Hi" },
295
+ { role: "assistant", content: "How can I help?" },
238
296
  ],
239
297
  max_history_messages: 20,
240
298
  maxToolIterations: 8,
@@ -268,8 +326,8 @@ Minimal example:
268
326
 
269
327
  ```js
270
328
  for await (const delta of sdk.runStream({
271
- agent: 'support-bot',
272
- message: 'Give me a short update on order AX-4420.',
329
+ agent: "support-bot",
330
+ message: "Give me a short update on order AX-4420.",
273
331
  })) {
274
332
  process.stdout.write(delta);
275
333
  }
@@ -279,9 +337,9 @@ Full example:
279
337
 
280
338
  ```js
281
339
  for await (const delta of sdk.runStream({
282
- agent: 'support-bot',
283
- message: 'Summarize the latest ticket updates.',
284
- conversation_key: 'support:customer-42',
340
+ agent: "support-bot",
341
+ message: "Summarize the latest ticket updates.",
342
+ conversation_key: "support:customer-42",
285
343
  user_id: 42,
286
344
  })) {
287
345
  process.stdout.write(delta);
@@ -291,38 +349,38 @@ for await (const delta of sdk.runStream({
291
349
  ## Complete minimal working example
292
350
 
293
351
  ```js
294
- import { createClient } from '@kigathi/ai-agents';
352
+ import { createClient } from "@kigathi/ai-agents";
295
353
 
296
354
  const sdk = createClient({
297
355
  apiKey: process.env.OPENAI_API_KEY,
298
356
  });
299
357
 
300
358
  sdk.registerTool({
301
- name: 'lookup_order',
302
- description: 'Return a fake order status.',
359
+ name: "lookup_order",
360
+ description: "Return a fake order status.",
303
361
  parameters_schema: {
304
- type: 'object',
362
+ type: "object",
305
363
  properties: {
306
- order_number: { type: 'string' },
364
+ order_number: { type: "string" },
307
365
  },
308
- required: ['order_number'],
366
+ required: ["order_number"],
309
367
  },
310
368
  handler: async ({ order_number }) => ({
311
369
  order_number,
312
- status: 'processing',
370
+ status: "processing",
313
371
  }),
314
372
  });
315
373
 
316
374
  sdk.createAgent({
317
- name: 'support-bot',
318
- model: 'gpt-4.1-mini',
319
- instructions: 'You are a concise support assistant.',
320
- tools: ['lookup_order'],
375
+ name: "support-bot",
376
+ model: "gpt-4.1-mini",
377
+ instructions: "You are a concise support assistant.",
378
+ tools: ["lookup_order"],
321
379
  });
322
380
 
323
381
  const result = await sdk.run({
324
- agent: 'support-bot',
325
- message: 'Check order AX-4420',
382
+ agent: "support-bot",
383
+ message: "Check order AX-4420",
326
384
  });
327
385
 
328
386
  console.log(result.output_text);
@@ -331,16 +389,15 @@ console.log(result.output_text);
331
389
  ## Complete proxy example
332
390
 
333
391
  ```js
334
- import { createClient } from '@kigathi/ai-agents';
392
+ import { createClient } from "@kigathi/ai-agents";
335
393
 
336
394
  const sdk = createClient({
337
- backendUrl: 'https://api.example.com',
338
- mode: 'proxy',
395
+ backendUrl: "https://api.example.com",
339
396
  });
340
397
 
341
398
  const result = await sdk.run({
342
- agent: 'support-bot',
343
- message: 'Start claim #99',
399
+ agent: "support-bot",
400
+ message: "Start claim #99",
344
401
  conversation_id: 1234,
345
402
  });
346
403
 
@@ -350,46 +407,45 @@ console.log(result.output_text);
350
407
  ## Complete direct + backend persistence example
351
408
 
352
409
  ```js
353
- import { createClient } from '@kigathi/ai-agents';
410
+ import { createClient } from "@kigathi/ai-agents";
354
411
 
355
412
  const sdk = createClient({
356
413
  apiKey: process.env.OPENAI_API_KEY,
357
- backendUrl: 'https://api.example.com',
358
- mode: 'direct',
414
+ backendUrl: "https://api.example.com",
359
415
  });
360
416
 
361
417
  sdk.registerTool({
362
- name: 'lookup_order',
363
- description: 'Find order by order number.',
418
+ name: "lookup_order",
419
+ description: "Find order by order number.",
364
420
  parameters_schema: {
365
- type: 'object',
421
+ type: "object",
366
422
  properties: {
367
- order_number: { type: 'string' },
423
+ order_number: { type: "string" },
368
424
  },
369
- required: ['order_number'],
425
+ required: ["order_number"],
370
426
  },
371
427
  handler: async ({ order_number }) => ({
372
428
  order_number,
373
- status: 'processing',
429
+ status: "processing",
374
430
  }),
375
431
  });
376
432
 
377
433
  sdk.createAgent({
378
- name: 'support-bot',
379
- model: 'gpt-4.1-mini',
380
- instructions: 'You are a concise support assistant.',
381
- tools: ['lookup_order'],
434
+ name: "support-bot",
435
+ model: "gpt-4.1-mini",
436
+ instructions: "You are a concise support assistant.",
437
+ tools: ["lookup_order"],
382
438
  });
383
439
 
384
440
  const result = await sdk.run({
385
- agent: 'support-bot',
386
- message: 'Check order AX-4420',
441
+ agent: "support-bot",
442
+ message: "Check order AX-4420",
387
443
  conversation_id: 1234,
388
444
  user_id: 42,
389
- client_message_id: 'msg_123',
445
+ client_message_id: "msg_123",
390
446
  metadata: {
391
- source: 'dashboard',
392
- account_id: 'acc_123',
447
+ source: "dashboard",
448
+ account_id: "acc_123",
393
449
  },
394
450
  });
395
451
 
@@ -398,15 +454,15 @@ console.log(result.output_text);
398
454
 
399
455
  ## Full sample apps
400
456
 
401
- - `../examples/lyre-ai-agents-node/express-chat` - Express server + Tailwind widget UI
402
- - `../examples/lyre-ai-agents-node/nuxt-chat` - Nuxt 3 app + server API route + Tailwind
403
- - `../examples/lyre-ai-agents-node/sveltekit-chat` - SvelteKit app + server endpoint + Tailwind
457
+ - [express-chat](https://github.com/kigathi-chege/lyre-ai-agents-examples/tree/main/express-chat) - Express server + Tailwind widget UI
458
+ - [nuxt-chat](https://github.com/kigathi-chege/lyre-ai-agents-examples/tree/main/nuxt-chat) - Nuxt 3 app + server API route + Tailwind
459
+ - [sveltekit-chat](https://github.com/kigathi-chege/lyre-ai-agents-examples/tree/main/sveltekit-chat) - SvelteKit app + server endpoint + Tailwind
404
460
 
405
- All three use `@kigathi/ai-agents` in `proxy` mode against Axis backend so conversation, message, and cost metadata stay in Axis.
461
+ All three use `@kigathi/ai-agents` in direct mode with backend persistence so OpenAI handles model execution while Axis stores conversation, message, and related event metadata.
406
462
 
407
463
  ## Notes
408
464
 
409
- - `createClient()` auto-selects `proxy` mode when `backendUrl` is provided without `apiKey`. Otherwise it defaults to `direct`.
465
+ - `createClient()` auto-selects proxy mode when `backendUrl` is provided without `apiKey`. Otherwise it uses direct mode.
410
466
  - In direct mode, the consuming app must have the `openai` package installed.
411
467
  - In direct mode with `backendUrl`, the SDK still calls OpenAI directly, then asynchronously persists messages and tool events to your backend.
412
468
  - You can pass either an agent name/id or a full agent object to `run()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigathi/ai-agents",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Forward-only Agents/Bots SDK on top of OpenAI Responses API.",
5
5
  "type": "module",
6
6
  "sideEffects": false,