anbaric 1.40.0 → 1.42.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.
@@ -3,7 +3,7 @@
3
3
  Who performs work, and how AI models plug in. Import from `anbaric`.
4
4
 
5
5
  ```ts
6
- import {Code, Human, SystemActor, Agent, OpenAIAgent, RemoteLLMAgenticAction} from "anbaric";
6
+ import {Code, Human, SystemActor, Agent, OpenAIAgent, AnthropicAgent, GeminiAgent, RemoteLLMAgenticAction} from "anbaric";
7
7
  import type {Actor, ActorType} from "anbaric";
8
8
  ```
9
9
 
@@ -155,6 +155,53 @@ const triager = new OpenAIAgent("triager", "support", {
155
155
  The optional `fetchFn` lets you inject a custom fetch (useful in tests). Requests
156
156
  that fail throw `The OpenAI request failed with status <n>`.
157
157
 
158
+ ### `AnthropicAgent`
159
+
160
+ An `Agent` backed by the Anthropic Messages API. The API has no JSON-schema
161
+ response format, so the output schema is offered as a single tool the model is
162
+ forced to call; its arguments are the structured output. System messages are
163
+ lifted out of the conversation into the API's own `system` field.
164
+
165
+ ```ts
166
+ class AnthropicAgent extends Agent
167
+ constructor(id : string, role : string, connection : AnthropicConnection, fetchFn? : FetchFn)
168
+
169
+ type AnthropicConnection = {
170
+ apiKey : string,
171
+ model : string,
172
+ baseUrl? : string, // default "https://api.anthropic.com/v1"
173
+ version? : string, // anthropic-version header, default "2023-06-01"
174
+ maxTokens? : number, // the Messages API requires a budget, default 4096
175
+ }
176
+ ```
177
+
178
+ Failures throw `The Anthropic request failed with status <n>`; a model that
179
+ answers with prose instead of calling the tool throws `The Anthropic response
180
+ carried no structured content`.
181
+
182
+ ### `GeminiAgent`
183
+
184
+ An `Agent` backed by the Gemini generative language API, asking for JSON against
185
+ the output schema. System messages become `systemInstruction`, assistant turns
186
+ are sent as the `model` role, and the API key travels as a header rather than a
187
+ query parameter.
188
+
189
+ ```ts
190
+ class GeminiAgent extends Agent
191
+ constructor(id : string, role : string, connection : GeminiConnection, fetchFn? : FetchFn)
192
+
193
+ type GeminiConnection = {
194
+ apiKey : string,
195
+ model : string,
196
+ baseUrl? : string, // default "https://generativelanguage.googleapis.com/v1beta"
197
+ }
198
+ ```
199
+
200
+ Gemini's `responseSchema` is an OpenAPI subset rather than JSON Schema, so the
201
+ schema you pass is converted: types are upper-cased and keywords it rejects
202
+ (`additionalProperties` among them) are dropped. Failures throw `The Gemini
203
+ request failed with status <n>`.
204
+
158
205
  ---
159
206
 
160
207
  ### See also
@@ -88,27 +88,27 @@ const key = await secrets.retrieve("stripe-key", actor);
88
88
 
89
89
  ## `PromptManager`
90
90
 
91
- Versioned prompts - instructions plus optional input and output schemas - owned
92
- by the calling app.
91
+ Versioned prompts - instructions plus an optional output schema - owned by the
92
+ calling app.
93
93
 
94
94
  ```ts
95
95
  PromptManagerFactory.instance() : PromptManager
96
96
 
97
97
  // methods:
98
- save(promptId : string, instructions : string, inputSchema? : JsonSchema, outputSchema? : JsonSchema) : Promise<Prompt>
98
+ save(promptId : string, instructions : string, outputSchema? : JsonSchema) : Promise<Prompt>
99
99
  retrieve(promptId : string, version? : number) : Promise<Prompt>
100
100
  list() : Promise<Array<Prompt>>
101
101
  history(promptId : string) : Promise<Array<Prompt>>
102
102
 
103
103
  type Prompt = {
104
104
  appId : string, promptId : string, version : number, instructions : string,
105
- inputSchema? : JsonSchema, outputSchema? : JsonSchema, createdAt : string,
105
+ outputSchema? : JsonSchema, createdAt : string,
106
106
  }
107
107
  ```
108
108
 
109
109
  ```ts
110
110
  const prompts = PromptManagerFactory.instance();
111
- await prompts.save("triage", "Decide the priority.", undefined, { type: "object", properties: { priority: { type: "string" } } });
111
+ await prompts.save("triage", "Decide the priority.", { type: "object", properties: { priority: { type: "string" } } });
112
112
  const latest = await prompts.retrieve("triage"); // highest version
113
113
  const specific = await prompts.retrieve("triage", 1);
114
114
  const all = await prompts.list(); // latest of each prompt
@@ -8,7 +8,7 @@ almost everything:
8
8
  import {
9
9
  StateMachine, State, Terminal, Action, Await, Transition,
10
10
  Job, PropertyDefinition,
11
- Code, Human, SystemActor, Agent, OpenAIAgent, RemoteLLMAgenticAction,
11
+ Code, Human, SystemActor, Agent, OpenAIAgent, AnthropicAgent, GeminiAgent, RemoteLLMAgenticAction,
12
12
  JsonStoreFactory, SecretStoreFactory, SqlStoreFactory, PromptManagerFactory,
13
13
  registerEntitlement, hasEntitlement,
14
14
  } from "anbaric";
@@ -26,7 +26,7 @@ An Anbaric app is a standard Node.js **ESM** program in TypeScript: set
26
26
  `Action`, `Await`, `WaitForInput`, `Transition`, `Job`, `PropertyDefinition`,
27
27
  `Actor`.
28
28
  - **[Actors and agents](actors-and-agents.md)** — `Code`, `Human`,
29
- `SystemActor`, `Agent`, `RemoteLLMAgenticAction`, `OpenAIAgent`.
29
+ `SystemActor`, `Agent`, `RemoteLLMAgenticAction`, `OpenAIAgent`, `AnthropicAgent`, `GeminiAgent`.
30
30
  - **[Stores](stores.md)** — `JsonStore`, `SecretStore`, `SqlStore`,
31
31
  `PromptManager` and their factories, plus `JsonSchema`.
32
32
  - **[Entitlements](../features/entitlements.md)** — `registerEntitlement`,
@@ -66,28 +66,47 @@ import {PromptManagerFactory} from "anbaric";
66
66
 
67
67
  const prompts = PromptManagerFactory.instance();
68
68
  await prompts.save("triage", "Decide the priority of the support ticket from its subject.",
69
- undefined, { type: "object", properties: { priority: { type: "string", enum: ["low", "high"] } } });
69
+ { type: "object", properties: { priority: { type: "string", enum: ["low", "high"] } } });
70
70
 
71
71
  const prompt = await prompts.retrieve("triage");
72
72
  const triage = new RemoteLLMAgenticAction("Triage the ticket", triager,
73
73
  [{ role: "system", content: prompt.instructions }], prompt.outputSchema!);
74
74
  ```
75
75
 
76
- ## Bring your own model
76
+ ## Choose a provider
77
77
 
78
- `OpenAIAgent` targets any OpenAI-compatible endpoint. Configure it with a
79
- connection object:
78
+ Three agents ship with the library. They take the same `(id, role, connection)`
79
+ shape, produce the same structured output against your schema, and are
80
+ interchangeable in an agentic action - only the connection differs:
80
81
 
81
82
  ```ts
83
+ import {AnthropicAgent, GeminiAgent, OpenAIAgent} from "anbaric";
84
+
82
85
  new OpenAIAgent("triager", "support", {
83
86
  apiKey: process.env.OPENAI_API_KEY!,
84
87
  model: "gpt-5.4-mini",
85
88
  baseUrl: "https://api.openai.com/v1", // optional; override for a compatible provider
86
89
  organization: "org_...", // optional
87
90
  });
91
+
92
+ new AnthropicAgent("triager", "support", {
93
+ apiKey: process.env.ANTHROPIC_API_KEY!,
94
+ model: "claude-opus-5",
95
+ maxTokens: 4096, // optional; the Messages API needs a budget
96
+ });
97
+
98
+ new GeminiAgent("triager", "support", {
99
+ apiKey: process.env.GEMINI_API_KEY!,
100
+ model: "gemini-3-pro",
101
+ });
88
102
  ```
89
103
 
90
- For a different provider entirely, implement an `Agent.Client` (a class with a
104
+ Each asks its provider for structured output the way that provider supports it -
105
+ OpenAI's JSON-schema response format, a forced tool call on Anthropic, Gemini's
106
+ JSON response schema - so your action only ever sees properties matching the
107
+ schema you gave it.
108
+
109
+ For a provider none of them covers, implement an `Agent.Client` (a class with a
91
110
  `generate(request)` method) and pass it to a plain `Agent`. See the [API
92
111
  reference](../api/actors-and-agents.md#agents-and-ai) for the client contract.
93
112
 
@@ -20,15 +20,14 @@ const prompts = PromptManagerFactory.instance();
20
20
  await prompts.save(
21
21
  "triage",
22
22
  "Decide the priority of the support ticket from its subject and body. Escalate anything mentioning an outage.",
23
- { type: "object", required: ["subject", "body"], properties: { subject: { type: "string" }, body: { type: "string" } } },
24
23
  { type: "object", required: ["priority"], properties: { priority: { type: "string", enum: ["low", "high"] } } },
25
24
  );
26
25
  ```
27
26
 
28
- A prompt has an **id**, its **instructions**, and optionally an **input
29
- schema** (the shape of what the model is given) and an **output schema** (what
30
- it must produce). Edit the instructions and redeploy: the next save stores
31
- version 2. There's no rollback and no tagging - an app always gets the latest.
27
+ A prompt has an **id**, its **instructions**, and optionally an **output
28
+ schema** - what the model must produce. Edit the instructions and redeploy: the
29
+ next save stores version 2. There's no rollback and no tagging - an app always
30
+ gets the latest.
32
31
 
33
32
  ## Use the latest where you call the model
34
33
 
@@ -56,7 +55,8 @@ const versions = await prompts.history("triage"); // every version, newest first
56
55
  ```
57
56
 
58
57
  The console's **Prompts** page shows the same for every app on the tenant: each
59
- prompt, its current instructions and schemas, and the full history to browse.
58
+ prompt, its current instructions and output schema, and the full history to
59
+ browse.
60
60
 
61
61
  ## Everything is scoped to your app
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anbaric",
3
- "version": "1.40.0",
3
+ "version": "1.42.0",
4
4
  "description": "Everything needed to write an Anbaric app: state machines, jobs, document and secret stores, local in-memory implementations and the Anbaric Cloud clients",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,9 +24,9 @@
24
24
  "prepublishOnly": "npm run build"
25
25
  },
26
26
  "dependencies": {
27
- "anbaric-impl-cloud": "^1.40.0",
28
- "anbaric-data-store": "^1.40.0",
29
- "anbaric-state-machine": "^1.40.0",
30
- "anbaric-tsapi": "^1.40.0"
27
+ "anbaric-impl-cloud": "^1.42.0",
28
+ "anbaric-data-store": "^1.42.0",
29
+ "anbaric-state-machine": "^1.42.0",
30
+ "anbaric-tsapi": "^1.42.0"
31
31
  }
32
32
  }