@rudderjs/ai 1.0.0 → 1.1.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 -2
- package/boost/guidelines.md +9 -3
- package/dist/agent.d.ts +21 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +770 -530
- package/dist/agent.js.map +1 -1
- package/dist/fake.d.ts +60 -2
- package/dist/fake.d.ts.map +1 -1
- package/dist/fake.js +80 -1
- package/dist/fake.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/observers.d.ts +24 -0
- package/dist/observers.d.ts.map +1 -1
- package/dist/observers.js.map +1 -1
- package/dist/providers/anthropic.js +2 -2
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.js +5 -0
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/openai.js +2 -2
- package/dist/providers/openai.js.map +1 -1
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
package/boost/guidelines.md
CHANGED
|
@@ -26,10 +26,12 @@ await agent('You are helpful.').prompt('Hello') // simplest form
|
|
|
26
26
|
|
|
27
27
|
### Using Providers (Anthropic, OpenAI, Google, etc.)
|
|
28
28
|
|
|
29
|
-
Configure providers in `config/ai.ts` and
|
|
29
|
+
Configure providers in `config/ai.ts`. The Node-only `AiProvider` lives at `@rudderjs/ai/server` (the main `@rudderjs/ai` entry is runtime-agnostic and has no provider class):
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
// config/ai.ts — providers: anthropic, openai, google, ollama, deepseek, xai, groq, mistral, azure
|
|
33
|
+
import type { AiConfig } from '@rudderjs/ai'
|
|
34
|
+
|
|
33
35
|
export default {
|
|
34
36
|
default: 'anthropic/claude-sonnet-4-5',
|
|
35
37
|
providers: {
|
|
@@ -40,9 +42,12 @@ export default {
|
|
|
40
42
|
} satisfies AiConfig
|
|
41
43
|
|
|
42
44
|
// bootstrap/providers.ts
|
|
43
|
-
|
|
45
|
+
import { AiProvider } from '@rudderjs/ai/server'
|
|
46
|
+
export default [AiProvider]
|
|
44
47
|
```
|
|
45
48
|
|
|
49
|
+
Provider auto-discovery (`defaultProviders()`) finds `AiProvider` automatically via the `rudderjs.providerSubpath` field in `@rudderjs/ai/package.json` — no manual subpath import needed when using auto-discovery.
|
|
50
|
+
|
|
46
51
|
Agents support failover: `failover() { return ['openai/gpt-4o'] }`
|
|
47
52
|
|
|
48
53
|
### Tools
|
|
@@ -132,13 +137,14 @@ const items = Output.array({ element: z.object({ title: z.string() }) })
|
|
|
132
137
|
- **Optional SDK deps**: Provider SDKs (`@anthropic-ai/sdk`, `openai`, `@google/genai`) are optional dependencies. Install the ones you need.
|
|
133
138
|
- **ConversationStore required for `.forUser()`/`.continue()`**: Call `setConversationStore()` or pass `conversations` in the AI config. Without it, conversation methods throw.
|
|
134
139
|
- **Tool loop limits**: `maxSteps()` defaults to 20. If the agent hits the limit it stops silently. Increase it for complex multi-tool workflows.
|
|
140
|
+
- **Parallel tool execution**: when the model emits multiple tool calls in a single step, their `execute()` functions run concurrently by default. Streamed chunks still emit in tool-call order. Opt out via `prompt(..., { parallelTools: false })` or override `parallelTools()` on the agent class for tools with non-idempotent shared state.
|
|
135
141
|
- **Streaming response access**: `await response` only resolves after the stream is fully consumed. Always iterate the stream first.
|
|
136
142
|
- **Embeddings**: Only providers that implement `createEmbedding()` support `AI.embed()`. Currently OpenAI-compatible providers.
|
|
137
143
|
|
|
138
144
|
## Key Imports
|
|
139
145
|
|
|
140
146
|
```ts
|
|
141
|
-
import {
|
|
147
|
+
import { AiProvider } from '@rudderjs/ai/server' // service provider (Node only)
|
|
142
148
|
import { Agent, agent, ConversableAgent } from '@rudderjs/ai' // agents
|
|
143
149
|
import { AI } from '@rudderjs/ai' // facade (AI.prompt, AI.agent, AI.embed)
|
|
144
150
|
import { toolDefinition } from '@rudderjs/ai' // tool builder
|
package/dist/agent.d.ts
CHANGED
|
@@ -25,6 +25,13 @@ export declare abstract class Agent {
|
|
|
25
25
|
temperature(): number | undefined;
|
|
26
26
|
/** Max tokens for response */
|
|
27
27
|
maxTokens(): number | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Default for `AgentPromptOptions.parallelTools`. When `true` (default),
|
|
30
|
+
* multiple tool calls within a single step run their `execute()` functions
|
|
31
|
+
* concurrently. Override on a subclass to flip the default for an agent
|
|
32
|
+
* whose tools share non-idempotent state. Per-call options still win.
|
|
33
|
+
*/
|
|
34
|
+
parallelTools(): boolean;
|
|
28
35
|
/** Run the agent with a prompt (non-streaming) */
|
|
29
36
|
prompt(input: string, options?: AgentPromptOptions): Promise<AgentResponse>;
|
|
30
37
|
/** Run the agent with a prompt (streaming) */
|
|
@@ -71,4 +78,18 @@ export declare function agent(instructionsOrOptions: string | {
|
|
|
71
78
|
}): Agent & HasTools & HasMiddleware;
|
|
72
79
|
/** Set the global conversation store (called by service provider or manually) */
|
|
73
80
|
export declare function setConversationStore(store: ConversationStore): void;
|
|
81
|
+
/**
|
|
82
|
+
* Structured error returned to the model when a tool call's arguments fail
|
|
83
|
+
* the tool's `inputSchema`. Surfaced both as the `result` on `AgentStep`
|
|
84
|
+
* and as the JSON-encoded `tool` message the next provider step receives,
|
|
85
|
+
* so the model can correct itself on the next turn.
|
|
86
|
+
*/
|
|
87
|
+
export interface InvalidToolArgumentsError {
|
|
88
|
+
error: 'invalid_arguments';
|
|
89
|
+
message: string;
|
|
90
|
+
issues: Array<{
|
|
91
|
+
path: string;
|
|
92
|
+
message: string;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
74
95
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAg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