@argentic-ai/client 0.4.0 → 0.6.0
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 +2 -1
- package/dist/argentic.d.ts +17 -7
- package/dist/argentic.js +16 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,8 @@ const tools = { refund_order: tool({
|
|
|
39
39
|
execute: async (args, { toolCallId }) => refund(args, toolCallId),
|
|
40
40
|
}) }
|
|
41
41
|
|
|
42
|
-
// apiKey defaults to ARGENTIC_API_KEY and
|
|
42
|
+
// apiKey defaults to ARGENTIC_API_KEY, modelKey to MODEL_KEY, and embedKey to EMBED_KEY
|
|
43
|
+
// (optional: with it, the agent's recall also finds what was said in other words)
|
|
43
44
|
const client = new Argentic()
|
|
44
45
|
const out = await run({
|
|
45
46
|
client, agent: 'my-agent', runId: 'order-1182', ledgerPath: '.argentic-ledger.json',
|
package/dist/argentic.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare function checkOncePer(tool: string, template: unknown, parameters
|
|
|
45
45
|
/** Set `once_per` on tools by name (for the AI SDK and Mastra adapters, whose tools have nowhere to carry it). Throws on a name that is not a tool or a template the API would refuse. */
|
|
46
46
|
export declare function withOncePer<T extends ToolDecl>(tools: T[], oncePer?: Record<string, string>): T[];
|
|
47
47
|
export interface WakeBody {
|
|
48
|
-
/** Required unless `fire_due` is set; the API refuses
|
|
48
|
+
/** Required unless `fire_due` or `results` is set; the API refuses `message` with `fire_due`. */
|
|
49
49
|
message?: string;
|
|
50
50
|
/** Wake for the plans that have fallen due instead of with a message: send it at the `wake_at` an earlier answer gave. */
|
|
51
51
|
fire_due?: boolean;
|
|
@@ -69,10 +69,10 @@ export interface WakeBody {
|
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
71
|
* What your app's tools returned for the `actions` of the previous wake, as `{ seq, result }`: `seq` is the action's
|
|
72
|
-
* `seq` and `result` is exactly what the tool returned. The API journals each as the real result of that call
|
|
73
|
-
*
|
|
74
|
-
* not know the field yet refuses it, and `wake()` then sends the same wake again without it
|
|
75
|
-
* this client.
|
|
72
|
+
* `seq` and `result` is exactly what the tool returned. The API journals each as the real result of that call, and the
|
|
73
|
+
* agent reads it as that call's result, so no `message` is needed with it. Never with `fire_due`; at most 100 entries. A
|
|
74
|
+
* server that does not know the field yet refuses it, and `wake()` then sends the same wake again without it (with the
|
|
75
|
+
* results as the message text when there is no message) and stops sending it on this client.
|
|
76
76
|
*/
|
|
77
77
|
results?: {
|
|
78
78
|
seq: number;
|
|
@@ -133,6 +133,15 @@ export interface ClientOptions {
|
|
|
133
133
|
apiKey?: string;
|
|
134
134
|
/** Sent as X-Model-Key on wake. Defaults to the MODEL_KEY environment variable. */
|
|
135
135
|
modelKey?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Your embedding provider key, sent as X-Embed-Key on wake, so the agent's recall also finds what was said in other words. Defaults to the
|
|
138
|
+
* EMBED_KEY environment variable; without one, recall works by words. Never stored by Argentic; your provider bills you for it.
|
|
139
|
+
*/
|
|
140
|
+
embedKey?: string;
|
|
141
|
+
/** Sent as X-Embed-Provider: `cohere` (the default) or `bedrock`. Defaults to the EMBED_PROVIDER environment variable. */
|
|
142
|
+
embedProvider?: string;
|
|
143
|
+
/** Sent as X-Embed-Region, for `bedrock` (default `us-east-1`). Defaults to the EMBED_REGION environment variable. */
|
|
144
|
+
embedRegion?: string;
|
|
136
145
|
baseUrl?: string;
|
|
137
146
|
/** How long one request may take before that try counts as a network failure, in milliseconds. Default 300000; 0 means no limit. */
|
|
138
147
|
timeoutMs?: number;
|
|
@@ -146,6 +155,7 @@ export interface ClientOptions {
|
|
|
146
155
|
export declare class Argentic {
|
|
147
156
|
private readonly apiKey;
|
|
148
157
|
private readonly modelKey?;
|
|
158
|
+
private readonly embed;
|
|
149
159
|
private readonly baseUrl;
|
|
150
160
|
private readonly timeoutMs;
|
|
151
161
|
private readonly doFetch;
|
|
@@ -273,8 +283,8 @@ export interface RunOptions {
|
|
|
273
283
|
/** Kill this process hard after the Nth newly executed action (to try a crash). */
|
|
274
284
|
crashAfterActions?: number;
|
|
275
285
|
/**
|
|
276
|
-
* Send each follow-up wake's tool results as the structured `results` field
|
|
277
|
-
*
|
|
286
|
+
* Send each follow-up wake's tool results as the structured `results` field, so the API journals the real result of every
|
|
287
|
+
* call and the agent reads each as that call's result. Default true. Set false to send them as message text only.
|
|
278
288
|
*/
|
|
279
289
|
structuredResults?: boolean;
|
|
280
290
|
log?: (line: string) => void;
|
package/dist/argentic.js
CHANGED
|
@@ -119,6 +119,8 @@ export function hintFor(e) {
|
|
|
119
119
|
return 'Check ARGENTIC_API_KEY. A key only works on the API it was made for, so if you set ARGENTIC_BASE_URL, make the key in that dashboard.';
|
|
120
120
|
if (code === 'model_key_rejected')
|
|
121
121
|
return 'Your model provider refused MODEL_KEY. Check it is a key for the provider in the error (a free NVIDIA key starts with nvapi-).';
|
|
122
|
+
if (code === 'bad_embed_key')
|
|
123
|
+
return 'The API cannot use EMBED_KEY as sent: EMBED_PROVIDER is cohere (the default) or bedrock, EMBED_REGION goes with bedrock only, and the key has no spaces. Unset EMBED_KEY to recall by words alone.';
|
|
122
124
|
if (code === 'bad_model')
|
|
123
125
|
return 'Your provider does not know this model id. Set ARGENTIC_MODEL_ID to one it serves, or unset it for the free default.';
|
|
124
126
|
if (e.status === 402)
|
|
@@ -133,6 +135,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
133
135
|
export class Argentic {
|
|
134
136
|
apiKey;
|
|
135
137
|
modelKey;
|
|
138
|
+
embed;
|
|
136
139
|
baseUrl;
|
|
137
140
|
timeoutMs;
|
|
138
141
|
doFetch;
|
|
@@ -144,6 +147,12 @@ export class Argentic {
|
|
|
144
147
|
constructor(opts = {}) {
|
|
145
148
|
this.apiKey = opts.apiKey ?? process.env.ARGENTIC_API_KEY ?? '';
|
|
146
149
|
this.modelKey = opts.modelKey || process.env.MODEL_KEY || undefined;
|
|
150
|
+
const embedKey = opts.embedKey || process.env.EMBED_KEY || undefined;
|
|
151
|
+
const embedProvider = opts.embedProvider || process.env.EMBED_PROVIDER || undefined;
|
|
152
|
+
const embedRegion = opts.embedRegion || process.env.EMBED_REGION || undefined;
|
|
153
|
+
this.embed = embedKey
|
|
154
|
+
? { 'X-Embed-Key': embedKey, ...(embedProvider ? { 'X-Embed-Provider': embedProvider } : {}), ...(embedRegion ? { 'X-Embed-Region': embedRegion } : {}) }
|
|
155
|
+
: {};
|
|
147
156
|
this.timeoutMs = opts.timeoutMs ?? defaultTimeoutMs;
|
|
148
157
|
this.baseUrl = (opts.baseUrl ?? process.env.ARGENTIC_BASE_URL ?? defaultBaseUrl).replace(/\/+$/, '');
|
|
149
158
|
this.doFetch = opts.fetch ?? fetch;
|
|
@@ -166,8 +175,11 @@ export class Argentic {
|
|
|
166
175
|
};
|
|
167
176
|
if (this.modelKey)
|
|
168
177
|
headers['X-Model-Key'] = this.modelKey;
|
|
178
|
+
Object.assign(headers, this.embed);
|
|
169
179
|
const path = `/v1/agents/${encodeURIComponent(agent)}/wake`;
|
|
170
|
-
const { results, ...
|
|
180
|
+
const { results, ...rest } = body;
|
|
181
|
+
// Without `results` the API reads them only from the message: a wake that has none says them in its text.
|
|
182
|
+
const plain = results !== undefined && rest.message === undefined && !rest.fire_due ? { ...rest, message: 'Results of the tools you asked for:\n' + JSON.stringify(results) } : rest;
|
|
171
183
|
let res;
|
|
172
184
|
if (results === undefined || this.resultsRefused) {
|
|
173
185
|
res = await this.send(path, JSON.stringify(plain), headers);
|
|
@@ -380,11 +392,11 @@ export async function run(opts) {
|
|
|
380
392
|
let pending = [];
|
|
381
393
|
for (let step = 0; step < maxSteps; step++) {
|
|
382
394
|
const key = safeKey(`${opts.runId}.${step}`);
|
|
383
|
-
|
|
395
|
+
// A follow-up wake sends the results as `results` and nothing else: the agent reads each as its call's result, so the text would say it twice.
|
|
396
|
+
const answers = structured && step > 0 && pending.length > 0;
|
|
397
|
+
const body = step === 0 && opts.fireDue ? { fire_due: true, model, tools: decls } : answers ? { results: pending, model, tools: decls } : { message, model, tools: decls };
|
|
384
398
|
if (opts.schedule)
|
|
385
399
|
body.schedule = true;
|
|
386
|
-
if (structured && step > 0 && pending.length)
|
|
387
|
-
body.results = pending;
|
|
388
400
|
opts.onWakeStart?.({ step });
|
|
389
401
|
if (opts.system)
|
|
390
402
|
body.system = opts.system;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argentic-ai/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Argentic client for TypeScript. Argentic is an engine that keeps AI agents right for hours while prompt size is bounded. Adapters for the Vercel AI SDK and Mastra.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|