@argentic-ai/client 0.10.0 → 0.10.1
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 +10 -10
- package/dist/argentic.d.ts +12 -12
- package/dist/argentic.js +5 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Argentic runs the agent loop. Your Vercel AI SDK or Mastra tools and system prompt carry over; the framework's own loop (`generateText`, `Agent`, Mastra `Agent.generate`) is not used.
|
|
4
4
|
|
|
5
|
-
Argentic is an engine that keeps
|
|
5
|
+
Argentic is an engine that keeps long-running agents accurate for hours and days: accuracy holds flat across days, and older memories stay usable. On a 14-day simulated shift it scored 0.83 (day 1 0.82, day 14 0.90); see the [results and caveats](https://github.com/Argentic-AI/argentic-plugins#results-over-multi-day-shifts).
|
|
6
6
|
|
|
7
|
-
Each tool call the agent makes comes back to your code to carry out.
|
|
7
|
+
Each tool call the agent makes comes back to your code to carry out. A run you start again continues where it stopped and does not repeat a finished action.
|
|
8
8
|
|
|
9
9
|
## Try it
|
|
10
10
|
|
|
@@ -40,24 +40,24 @@ const tools = { refund_order: tool({
|
|
|
40
40
|
}) }
|
|
41
41
|
|
|
42
42
|
// apiKey defaults to ARGENTIC_API_KEY, modelKey to MODEL_KEY, and embedKey to EMBED_KEY
|
|
43
|
-
// (optional:
|
|
43
|
+
// (optional: your embedding provider's key, never stored by Argentic)
|
|
44
44
|
const client = new Argentic()
|
|
45
45
|
const out = await run({
|
|
46
46
|
client, agent: 'my-agent', runId: 'order-1182', ledgerPath: '.argentic-ledger.json',
|
|
47
47
|
task: 'Refund order 1182.', system: 'Call one tool per turn.',
|
|
48
48
|
tools: await fromAiSdkTools(tools),
|
|
49
|
-
model: modelFromEnv(), // or { provider: 'openai', id: '...'
|
|
49
|
+
model: modelFromEnv(), // or { provider: 'openai', id: '...' }
|
|
50
50
|
})
|
|
51
51
|
console.log(out.reply)
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
This example also uses the AI SDK and zod (`npm i ai zod`), and `refund` stands for your own billing code. Save it as a `.mjs` file. Before you run it, set `ARGENTIC_API_KEY`, `MODEL_KEY` and the model variables under [Your model](#your-model).
|
|
55
55
|
|
|
56
|
-
`task` is the new event: what happened since the agent last ran, never the earlier messages. Keep `agent` and `runId` the same when a run is retried (the id of the event that woke the agent is a good `runId`). `ledgerPath` is optional: with it, finished actions are written to that file so a killed process does not run them twice; without it they are kept in memory for the call, so make your tools safe to repeat with the `ctx.idempotencyKey` your `execute` receives. A request that takes longer than `timeoutMs` (default 300000, 0 for no limit) counts as a network failure and is retried with the same key. If the ledger file is not valid JSON, `run` warns on stderr, sets the file aside as `<path>.corrupt` and starts empty, so finished actions may run again. `client.replay(agent, wakeId)`
|
|
56
|
+
`task` is the new event: what happened since the agent last ran, never the earlier messages. Keep `agent` and `runId` the same when a run is retried (the id of the event that woke the agent is a good `runId`). `ledgerPath` is optional: with it, finished actions are written to that file so a killed process does not run them twice; without it they are kept in memory for the call, so make your tools safe to repeat with the `ctx.idempotencyKey` your `execute` receives. A request that takes longer than `timeoutMs` (default 300000, 0 for no limit) counts as a network failure and is retried with the same key. If the ledger file is not valid JSON, `run` warns on stderr, sets the file aside as `<path>.corrupt` and starts empty, so finished actions may run again. `client.replay(agent, wakeId)` runs the free proof check on a wake; it calls no model and spends nothing.
|
|
57
57
|
|
|
58
58
|
## Your model
|
|
59
59
|
|
|
60
|
-
You always name the model; there is no default. `model` is `{ provider, id
|
|
60
|
+
You always name the model; there is no default. `model` is `{ provider, id }` with `provider` a named endpoint (`openai`, `anthropic`, `openrouter`, ...), or `{ base_url, id }` with `base_url` any public https OpenAI-compatible endpoint on port 443 (give one of the two, not both). `prices` (dollars per million tokens) is optional: only a spend limit counts dollars. `modelFromEnv()` reads `ARGENTIC_MODEL_ID` and `ARGENTIC_MODEL_PROVIDER` or `ARGENTIC_MODEL_BASE_URL`, and, if set, `ARGENTIC_PRICE_IN` and `ARGENTIC_PRICE_OUT`, and throws if the model is not named. A price is never guessed. With neither price variable set, no `prices` are sent, which is right for a call with no limit; a call with `limits.max_usd` (or under a limit your organization set) needs them, or an Anthropic model on Anthropic's API, which the API prices from its list, and is otherwise refused with `prices_required`. One price without the other throws, and so does a price that is not a number. A free model sets both to `0`. This is new in 0.9.0: up to 0.8.0 an unset price counted as 0. `ARGENTIC_BASE_URL` is Argentic's own API, not your model's.
|
|
61
61
|
|
|
62
62
|
## Once per operation (`once_per`, 0.1.7)
|
|
63
63
|
|
|
@@ -65,7 +65,7 @@ A tool can declare `once_per`, a key such as `refund:{order_id}` filled in from
|
|
|
65
65
|
|
|
66
66
|
## Tools, state and deferred loading (0.1.10)
|
|
67
67
|
|
|
68
|
-
Declare an agent's tools once with `client.putTools(agent, tools)` and leave `tools` out of later wakes; `client.tools(agent)` reads them back. A wake can also carry `state` (keys and JSON values your app holds, such as the signed-in user's plan; a value the agent already has costs nothing to send again, a changed one
|
|
68
|
+
Declare an agent's tools once with `client.putTools(agent, tools)` and leave `tools` out of later wakes; `client.tools(agent)` reads them back. A wake can also carry `state` (keys and JSON values your app holds, such as the signed-in user's plan; a value the agent already has costs nothing to send again, a changed one replaces it, and `null` removes a key) and `tool_choice` (`'auto'`, `'required'` or `{ type: 'tool', name }`). On a tool, `defer_loading: true` keeps its schema out of the prompt until the agent looks it up, which pays off from about ten tools.
|
|
69
69
|
|
|
70
70
|
```ts
|
|
71
71
|
await client.putTools('support-bot', [{ name: 'book_slot', description: 'Book a slot.', parameters: { type: 'object', properties: { day: { type: 'string' } }, required: ['day'] } }])
|
|
@@ -74,11 +74,11 @@ const out = await client.wake('support-bot', { message: 'Book Tuesday.', model:
|
|
|
74
74
|
|
|
75
75
|
## `state` replaces `context` (0.10.0)
|
|
76
76
|
|
|
77
|
-
`context` is gone from `WakeBody`: the API now answers 400 and names `state` when a wake still sends it. Move what you sent as one string into keys (`context: 'Plan: pro'` becomes `state: { 'account.plan': 'Pro' }`) and send them on every wake, or only when they change; an unchanged key costs nothing. Unlike `context`, a value you send
|
|
77
|
+
`context` is gone from `WakeBody`: the API now answers 400 and names `state` when a wake still sends it. Move what you sent as one string into keys (`context: 'Plan: pro'` becomes `state: { 'account.plan': 'Pro' }`) and send them on every wake, or only when they change; an unchanged key costs nothing. Unlike `context`, a value you send stays with the agent on later wakes. Text that came from outside your app (a web page, an email) goes in `outside`, not `state`.
|
|
78
78
|
|
|
79
79
|
## Structured tool results (0.1.11)
|
|
80
80
|
|
|
81
|
-
`run` answers the tools an agent asked for with a text message the model reads, and now also sends the same results as the `results` field of the wake: `[{ seq, result }]`, where `seq` is the action's `seq` and `result` is exactly what the tool returned (or the `{ error }` object when it threw). The API
|
|
81
|
+
`run` answers the tools an agent asked for with a text message the model reads, and now also sends the same results as the `results` field of the wake: `[{ seq, result }]`, where `seq` is the action's `seq` and `result` is exactly what the tool returned (or the `{ error }` object when it threw). The API keeps each as the real result of that call. The first wake of a run has none, and a result the ledger already held is sent again like the others. Pass `structuredResults: false` to send the text only. If the API you talk to does not know the field yet, it answers 400 and names `results`; the client sends that wake again once without it, under the same key, and leaves it out from then on. Calling `client.wake()` yourself, add `results` to the body next to the `message`, never with `fire_due`, at most 100 entries.
|
|
82
82
|
|
|
83
83
|
## Waking the agent later
|
|
84
84
|
|
|
@@ -96,7 +96,7 @@ A `fireDue` wake with nothing due makes no model call and costs nothing. With `c
|
|
|
96
96
|
|
|
97
97
|
## What to know
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
Make your handlers safe to repeat: the AI SDK `toolCallId` your `execute` receives (`agent:seq`) is a key to pass on to the system you call.
|
|
100
100
|
|
|
101
101
|
Mastra tools get the same key as `context.agent.toolCallId`.
|
|
102
102
|
|
package/dist/argentic.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export interface ModelSpec {
|
|
|
8
8
|
base_url?: string;
|
|
9
9
|
id: string;
|
|
10
10
|
/**
|
|
11
|
-
* Dollars per million tokens
|
|
12
|
-
*
|
|
13
|
-
* `prices_required`
|
|
11
|
+
* Optional. Dollars per million tokens, `cache_hit` being what a cached input token costs if your provider has a cache price. Only a spend
|
|
12
|
+
* limit counts dollars: with `limits.max_usd` (or a limit your organization set) the call needs prices, yours or, for Anthropic's models on
|
|
13
|
+
* Anthropic's API, the list's, and is refused with `prices_required` without them. A call with no limit needs none. A free model declares `{ in: 0, out: 0 }`.
|
|
14
14
|
*/
|
|
15
15
|
prices?: {
|
|
16
16
|
in: number;
|
|
@@ -20,9 +20,9 @@ export interface ModelSpec {
|
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* The model from `ARGENTIC_MODEL_ID` plus `ARGENTIC_MODEL_PROVIDER` (a named endpoint) or `ARGENTIC_MODEL_BASE_URL` (any public https
|
|
23
|
-
* OpenAI-compatible endpoint), and `ARGENTIC_PRICE_IN` / `ARGENTIC_PRICE_OUT` in dollars per million tokens. There is no default model:
|
|
23
|
+
* OpenAI-compatible endpoint), and, optionally, `ARGENTIC_PRICE_IN` / `ARGENTIC_PRICE_OUT` in dollars per million tokens (only a spend limit needs them). There is no default model:
|
|
24
24
|
* without `ARGENTIC_MODEL_ID` and one of the two it throws. A price is never guessed either: with neither price set the model carries no
|
|
25
|
-
* `prices` (the API then uses its own price if it has one for that model and refuses the call if
|
|
25
|
+
* `prices` (the API then uses its own price if it has one for that model, and refuses the call only if a spend limit needs one), one price without the other
|
|
26
26
|
* throws, and so does a price that is not a number. A free model sets both to 0. `ARGENTIC_BASE_URL` is Argentic's own API, not the model's.
|
|
27
27
|
*/
|
|
28
28
|
export declare function modelFromEnv(e?: Record<string, string | undefined>): ModelSpec;
|
|
@@ -68,7 +68,7 @@ export interface WakeBody {
|
|
|
68
68
|
schedule?: boolean;
|
|
69
69
|
model: ModelSpec;
|
|
70
70
|
system?: string;
|
|
71
|
-
/** Keys and JSON values your app holds that the agent should know (the signed-in user's plan, what is in their cart), up to 64 keys a call, a key up to 120 characters on one line, a value up to 2,000 characters as JSON. A value the agent already has costs nothing to send again; a changed one
|
|
71
|
+
/** Keys and JSON values your app holds that the agent should know (the signed-in user's plan, what is in their cart), up to 64 keys a call, a key up to 120 characters on one line, a value up to 2,000 characters as JSON. A value the agent already has costs nothing to send again; a changed one replaces it and the agent keeps it. `null` removes a key; a key you leave out stays as it is. Replaces `context`, which the API no longer takes. */
|
|
72
72
|
state?: Record<string, unknown>;
|
|
73
73
|
tools?: ToolDecl[];
|
|
74
74
|
/** Whether this call must end with a call to one of your tools. `auto` (default), `required`, or `{ type: 'tool', name }`. */
|
|
@@ -82,7 +82,7 @@ export interface WakeBody {
|
|
|
82
82
|
};
|
|
83
83
|
/**
|
|
84
84
|
* What your app's tools returned for the `actions` of the previous wake, as `{ seq, result }`: `seq` is the action's
|
|
85
|
-
* `seq` and `result` is exactly what the tool returned. The API
|
|
85
|
+
* `seq` and `result` is exactly what the tool returned. The API treats each as the real result of that call, and the
|
|
86
86
|
* agent reads it as that call's result, so no `message` is needed with it. Never with `fire_due`; at most 100 entries. A
|
|
87
87
|
* server that does not know the field yet refuses it, and `wake()` then sends the same wake again without it (with the
|
|
88
88
|
* results as the message text when there is no message) and stops sending it on this client.
|
|
@@ -147,8 +147,8 @@ export interface ClientOptions {
|
|
|
147
147
|
/** Sent as X-Model-Key on wake. Defaults to the MODEL_KEY environment variable. */
|
|
148
148
|
modelKey?: string;
|
|
149
149
|
/**
|
|
150
|
-
* Your embedding provider key, sent as X-Embed-Key on wake
|
|
151
|
-
* EMBED_KEY environment variable
|
|
150
|
+
* Your embedding provider key, sent as X-Embed-Key on wake. Optional. Defaults to the
|
|
151
|
+
* EMBED_KEY environment variable. Never stored by Argentic; your provider bills you for it.
|
|
152
152
|
*/
|
|
153
153
|
embedKey?: string;
|
|
154
154
|
/** Sent as X-Embed-Provider: `cohere` (the default) or `bedrock`. Defaults to the EMBED_PROVIDER environment variable. */
|
|
@@ -186,7 +186,7 @@ export declare class Argentic {
|
|
|
186
186
|
* `results` out from then on.
|
|
187
187
|
*/
|
|
188
188
|
wake(agent: string, body: WakeBody, idempotencyKey: string): Promise<WakeResult>;
|
|
189
|
-
/**
|
|
189
|
+
/** Run the free proof check on a wake. Spends nothing. */
|
|
190
190
|
replay(agent: string, wakeId: string): Promise<ReplayResult>;
|
|
191
191
|
/** Plans of your agents whose wake_at has passed. Every wake answer already gives `wake_at`; this is for a scheduler that lost track. Read only; costs nothing. */
|
|
192
192
|
due(opts?: {
|
|
@@ -272,7 +272,7 @@ export interface RunOptions {
|
|
|
272
272
|
* they are kept in memory for this call only (no file is written); then make your tools safe to repeat, with `ctx.idempotencyKey`.
|
|
273
273
|
*/
|
|
274
274
|
ledgerPath?: string;
|
|
275
|
-
/** The model to run, named by you: `{ provider | base_url, id
|
|
275
|
+
/** The model to run, named by you: `{ provider | base_url, id }`, plus `prices` if a spend limit applies. There is no default. */
|
|
276
276
|
model: ModelSpec;
|
|
277
277
|
maxSteps?: number;
|
|
278
278
|
limits?: WakeBody['limits'];
|
|
@@ -297,7 +297,7 @@ export interface RunOptions {
|
|
|
297
297
|
/** Kill this process hard after the Nth newly executed action (to try a crash). */
|
|
298
298
|
crashAfterActions?: number;
|
|
299
299
|
/**
|
|
300
|
-
* Send each follow-up wake's tool results as the structured `results` field, so the API
|
|
300
|
+
* Send each follow-up wake's tool results as the structured `results` field, so the API has the real result of every
|
|
301
301
|
* call and the agent reads each as that call's result. Default true. Set false to send them as message text only.
|
|
302
302
|
*/
|
|
303
303
|
structuredResults?: boolean;
|
package/dist/argentic.js
CHANGED
|
@@ -7,9 +7,9 @@ export const defaultBaseUrl = 'https://api.getargentic.com';
|
|
|
7
7
|
export const defaultTimeoutMs = 300_000;
|
|
8
8
|
/**
|
|
9
9
|
* The model from `ARGENTIC_MODEL_ID` plus `ARGENTIC_MODEL_PROVIDER` (a named endpoint) or `ARGENTIC_MODEL_BASE_URL` (any public https
|
|
10
|
-
* OpenAI-compatible endpoint), and `ARGENTIC_PRICE_IN` / `ARGENTIC_PRICE_OUT` in dollars per million tokens. There is no default model:
|
|
10
|
+
* OpenAI-compatible endpoint), and, optionally, `ARGENTIC_PRICE_IN` / `ARGENTIC_PRICE_OUT` in dollars per million tokens (only a spend limit needs them). There is no default model:
|
|
11
11
|
* without `ARGENTIC_MODEL_ID` and one of the two it throws. A price is never guessed either: with neither price set the model carries no
|
|
12
|
-
* `prices` (the API then uses its own price if it has one for that model and refuses the call if
|
|
12
|
+
* `prices` (the API then uses its own price if it has one for that model, and refuses the call only if a spend limit needs one), one price without the other
|
|
13
13
|
* throws, and so does a price that is not a number. A free model sets both to 0. `ARGENTIC_BASE_URL` is Argentic's own API, not the model's.
|
|
14
14
|
*/
|
|
15
15
|
export function modelFromEnv(e = process.env) {
|
|
@@ -155,11 +155,11 @@ export function hintFor(e) {
|
|
|
155
155
|
if (code === 'model_key_rejected')
|
|
156
156
|
return 'Your model provider refused MODEL_KEY. Check it is a key for the provider in the error.';
|
|
157
157
|
if (code === 'bad_embed_key')
|
|
158
|
-
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
|
|
158
|
+
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 go without it.';
|
|
159
159
|
if (code === 'bad_model')
|
|
160
160
|
return 'The model was refused. Check the provider name and the model id you gave: ARGENTIC_MODEL_PROVIDER or ARGENTIC_MODEL_BASE_URL, and ARGENTIC_MODEL_ID.' + said;
|
|
161
161
|
if (code === 'prices_required')
|
|
162
|
-
return '
|
|
162
|
+
return 'A spend limit (limits.max_usd, or one your organization set) counts dollars, so Argentic needs this model\'s prices, and it does not guess them. Set ARGENTIC_PRICE_IN and ARGENTIC_PRICE_OUT to its prices in dollars per million tokens, or give prices in the model you pass (a free model is 0 and 0), or take the limit off: a call with no limit needs no prices.';
|
|
163
163
|
if (code === 'idempotency_key_reused')
|
|
164
164
|
return 'This run id (the idempotency key) was already used for a different request. To retry, send the same request again. For a new event, or after changing the request, use a new run id.';
|
|
165
165
|
if (code === 'history_resent')
|
|
@@ -241,7 +241,7 @@ export class Argentic {
|
|
|
241
241
|
const json = (await res.json());
|
|
242
242
|
return { ...json, idempotentReplay: res.headers.get('Idempotent-Replay') === 'true' };
|
|
243
243
|
}
|
|
244
|
-
/**
|
|
244
|
+
/** Run the free proof check on a wake. Spends nothing. */
|
|
245
245
|
async replay(agent, wakeId) {
|
|
246
246
|
const headers = { Authorization: `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' };
|
|
247
247
|
const res = await this.send(`/v1/agents/${encodeURIComponent(agent)}/replay`, JSON.stringify({ wake: wakeId }), headers);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argentic-ai/client",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"description": "Argentic client for TypeScript. Argentic is an engine that keeps
|
|
3
|
+
"version": "0.10.1",
|
|
4
|
+
"description": "Argentic client for TypeScript. Argentic is an engine that keeps long-running agents accurate for hours and days. Adapters for the Vercel AI SDK and Mastra.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": { "node": ">=22" },
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"directory": "adapters/typescript"
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://getargentic.com/docs",
|
|
39
|
-
"keywords": ["agents", "long-running", "context", "
|
|
39
|
+
"keywords": ["agents", "long-running", "context", "ai-sdk", "mastra", "argentic"],
|
|
40
40
|
"publishConfig": { "access": "public", "provenance": true }
|
|
41
41
|
}
|