@argentic-ai/client 0.6.0 → 0.8.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 CHANGED
@@ -30,7 +30,7 @@ To vendor it instead: clone this repo and copy `argentic.ts`, `ai-sdk.ts` and `m
30
30
  ```ts
31
31
  import { tool } from 'ai'
32
32
  import { z } from 'zod'
33
- import { Argentic, run } from '@argentic-ai/client'
33
+ import { Argentic, modelFromEnv, run } from '@argentic-ai/client'
34
34
  import { fromAiSdkTools } from '@argentic-ai/client/ai-sdk'
35
35
 
36
36
  const tools = { refund_order: tool({
@@ -46,12 +46,17 @@ 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: '...', prices: { in: 0.25, out: 2 } }
49
50
  })
50
51
  console.log(out.reply)
51
52
  ```
52
53
 
53
54
  `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)` re-renders a wake's prompts from the journal and compares them to what the model saw; it calls no model and spends nothing.
54
55
 
56
+ ## Your model
57
+
58
+ You always name the model; there is no default. `model` is `{ provider, id, prices }` with `provider` a named endpoint (`openai`, `anthropic`, `openrouter`, ...), or `{ base_url, id, prices }` with `base_url` any public https OpenAI-compatible endpoint on port 443 (give one of the two, not both). Prices are dollars per million tokens. `modelFromEnv()` reads `ARGENTIC_MODEL_ID`, `ARGENTIC_MODEL_PROVIDER` or `ARGENTIC_MODEL_BASE_URL`, `ARGENTIC_PRICE_IN` and `ARGENTIC_PRICE_OUT`, and throws if the model is not named. `ARGENTIC_BASE_URL` is Argentic's own API, not your model's.
59
+
55
60
  ## Once per operation (`once_per`, 0.1.7)
56
61
 
57
62
  A tool can declare `once_per`, a key such as `refund:{order_id}` filled in from the call's arguments. Argentic then refuses a second call with the same key, in this wake or any later one. Set it on a `Tool` directly, or pass `{ oncePer: { refund_order: 'refund:{order_id}' } }` as the second argument to `fromAiSdkTools` or `fromMastraTools`. The template is checked before the request is sent. See [TOOLS.md](TOOLS.md#declaring-a-tool-once_per). 0.1.6 and earlier dropped the field.
@@ -62,7 +67,7 @@ Declare an agent's tools once with `client.putTools(agent, tools)` and leave `to
62
67
 
63
68
  ```ts
64
69
  await client.putTools('support-bot', [{ name: 'book_slot', description: 'Book a slot.', parameters: { type: 'object', properties: { day: { type: 'string' } }, required: ['day'] } }])
65
- const out = await client.wake('support-bot', { message: 'Book Tuesday.', model: freeModel, context: 'Plan: pro' }, 'book-1')
70
+ const out = await client.wake('support-bot', { message: 'Book Tuesday.', model: modelFromEnv(), context: 'Plan: pro' }, 'book-1')
66
71
  ```
67
72
 
68
73
  ## Structured tool results (0.1.11)
@@ -2,7 +2,10 @@ export declare const defaultBaseUrl = "https://api.getargentic.com";
2
2
  /** A wake can run a long time, so a try waits five minutes, as Python's client does. */
3
3
  export declare const defaultTimeoutMs = 300000;
4
4
  export interface ModelSpec {
5
- provider: string;
5
+ /** A named endpoint (`openai`, `anthropic`, `openrouter`, `nvidia`, ...). Give this or `base_url`, not both. */
6
+ provider?: string;
7
+ /** Any public https OpenAI-compatible endpoint on port 443, for a provider with no preset. Give this or `provider`, not both. */
8
+ base_url?: string;
6
9
  id: string;
7
10
  /** Dollars per million tokens. `cache_hit` is what a cached input token costs, if your provider has a cache price. */
8
11
  prices: {
@@ -11,8 +14,12 @@ export interface ModelSpec {
11
14
  cache_hit?: number;
12
15
  };
13
16
  }
14
- /** The free default model. */
15
- export declare const freeModel: ModelSpec;
17
+ /**
18
+ * The model from `ARGENTIC_MODEL_ID` plus `ARGENTIC_MODEL_PROVIDER` (a named endpoint) or `ARGENTIC_MODEL_BASE_URL` (any public https
19
+ * OpenAI-compatible endpoint), and `ARGENTIC_PRICE_IN` / `ARGENTIC_PRICE_OUT` in dollars per million tokens. There is no default model:
20
+ * without `ARGENTIC_MODEL_ID` and one of the two it throws. `ARGENTIC_BASE_URL` is Argentic's own API, not the model's.
21
+ */
22
+ export declare function modelFromEnv(e?: Record<string, string | undefined>): ModelSpec;
16
23
  /** What Argentic is told about a tool. It is declared, never executed by Argentic. */
17
24
  export interface ToolDecl {
18
25
  name: string;
@@ -259,7 +266,8 @@ export interface RunOptions {
259
266
  * they are kept in memory for this call only (no file is written); then make your tools safe to repeat, with `ctx.idempotencyKey`.
260
267
  */
261
268
  ledgerPath?: string;
262
- model?: ModelSpec;
269
+ /** The model to run, named by you: `{ provider | base_url, id, prices }`. There is no default. */
270
+ model: ModelSpec;
263
271
  maxSteps?: number;
264
272
  limits?: WakeBody['limits'];
265
273
  /** Called just before each wake is sent, so a caller can say it is waiting on the model (the first answer can take several seconds). */
package/dist/argentic.js CHANGED
@@ -5,12 +5,21 @@ import { dirname } from 'node:path';
5
5
  export const defaultBaseUrl = 'https://api.getargentic.com';
6
6
  /** A wake can run a long time, so a try waits five minutes, as Python's client does. */
7
7
  export const defaultTimeoutMs = 300_000;
8
- /** The free default model. */
9
- export const freeModel = {
10
- provider: 'nvidia',
11
- id: 'nvidia/nemotron-3.5-lightning-30b-a3b',
12
- prices: { in: 0, out: 0 },
13
- };
8
+ /**
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:
11
+ * without `ARGENTIC_MODEL_ID` and one of the two it throws. `ARGENTIC_BASE_URL` is Argentic's own API, not the model's.
12
+ */
13
+ export function modelFromEnv(e = process.env) {
14
+ if (!e.ARGENTIC_MODEL_ID)
15
+ throw new Error('Set ARGENTIC_MODEL_ID to the model you want, with ARGENTIC_MODEL_PROVIDER or ARGENTIC_MODEL_BASE_URL.');
16
+ if (e.ARGENTIC_MODEL_PROVIDER && e.ARGENTIC_MODEL_BASE_URL)
17
+ throw new Error('Set ARGENTIC_MODEL_PROVIDER or ARGENTIC_MODEL_BASE_URL, not both.');
18
+ if (!e.ARGENTIC_MODEL_PROVIDER && !e.ARGENTIC_MODEL_BASE_URL)
19
+ throw new Error('Set ARGENTIC_MODEL_PROVIDER (a named endpoint) or ARGENTIC_MODEL_BASE_URL (a public https OpenAI-compatible endpoint).');
20
+ const where = e.ARGENTIC_MODEL_BASE_URL ? { base_url: e.ARGENTIC_MODEL_BASE_URL } : { provider: e.ARGENTIC_MODEL_PROVIDER };
21
+ return { ...where, id: e.ARGENTIC_MODEL_ID, prices: { in: Number(e.ARGENTIC_PRICE_IN ?? 0), out: Number(e.ARGENTIC_PRICE_OUT ?? 0) } };
22
+ }
14
23
  const propKeys = ['type', 'description', 'enum'];
15
24
  /** True when any top-level property is an object, or an array of objects (or of anything that is not a plain scalar). */
16
25
  function isNested(schema) {
@@ -118,11 +127,11 @@ export function hintFor(e) {
118
127
  if (e.status === 401)
119
128
  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
129
  if (code === 'model_key_rejected')
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-).';
130
+ return 'Your model provider refused MODEL_KEY. Check it is a key for the provider in the error.';
122
131
  if (code === 'bad_embed_key')
123
132
  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.';
124
133
  if (code === 'bad_model')
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.';
134
+ return 'Your provider does not know this model id. Set ARGENTIC_MODEL_ID to one it serves.';
126
135
  if (e.status === 402)
127
136
  return 'This account hit its usage limit. Argentic is free in beta, so there is nothing to buy: email hi@getargentic.com and we will raise it.';
128
137
  if (e.status === 429)
@@ -371,7 +380,7 @@ export async function run(opts) {
371
380
  throw new Error('run: pass `task` (the new event) or `fireDue: true`, not both and not neither');
372
381
  const log = opts.log ?? ((line) => console.log(line));
373
382
  const maxSteps = opts.maxSteps ?? 8;
374
- const model = opts.model ?? freeModel;
383
+ const model = opts.model;
375
384
  const ledger = new Ledger(opts.ledgerPath);
376
385
  const byName = new Map(tools.map((t) => [t.name, t]));
377
386
  const decls = tools.map(({ name, description, parameters, once_per }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argentic-ai/client",
3
- "version": "0.6.0",
3
+ "version": "0.8.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",