stratus-sdk 0.10.0 → 0.12.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 +13 -514
- package/azure.d.ts +1 -0
- package/azure.js +1 -0
- package/core.d.ts +1 -0
- package/core.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +14 -23
- package/LICENSE +0 -21
- package/dist/azure/chat-completions-model.d.ts +0 -23
- package/dist/azure/chat-completions-model.d.ts.map +0 -1
- package/dist/azure/chat-completions-model.js +0 -293
- package/dist/azure/chat-completions-model.js.map +0 -1
- package/dist/azure/endpoint.d.ts +0 -18
- package/dist/azure/endpoint.d.ts.map +0 -1
- package/dist/azure/endpoint.js +0 -57
- package/dist/azure/endpoint.js.map +0 -1
- package/dist/azure/index.d.ts +0 -5
- package/dist/azure/index.d.ts.map +0 -1
- package/dist/azure/index.js +0 -3
- package/dist/azure/index.js.map +0 -1
- package/dist/azure/responses-model.d.ts +0 -25
- package/dist/azure/responses-model.d.ts.map +0 -1
- package/dist/azure/responses-model.js +0 -557
- package/dist/azure/responses-model.js.map +0 -1
- package/dist/azure/sse-parser.d.ts +0 -2
- package/dist/azure/sse-parser.d.ts.map +0 -1
- package/dist/azure/sse-parser.js +0 -39
- package/dist/azure/sse-parser.js.map +0 -1
- package/dist/core/agent.d.ts +0 -47
- package/dist/core/agent.d.ts.map +0 -1
- package/dist/core/agent.js +0 -74
- package/dist/core/agent.js.map +0 -1
- package/dist/core/builtin-tools.d.ts +0 -41
- package/dist/core/builtin-tools.d.ts.map +0 -1
- package/dist/core/builtin-tools.js +0 -80
- package/dist/core/builtin-tools.js.map +0 -1
- package/dist/core/codemode/executor.d.ts +0 -38
- package/dist/core/codemode/executor.d.ts.map +0 -1
- package/dist/core/codemode/executor.js +0 -54
- package/dist/core/codemode/executor.js.map +0 -1
- package/dist/core/codemode/index.d.ts +0 -62
- package/dist/core/codemode/index.d.ts.map +0 -1
- package/dist/core/codemode/index.js +0 -104
- package/dist/core/codemode/index.js.map +0 -1
- package/dist/core/codemode/types.d.ts +0 -24
- package/dist/core/codemode/types.d.ts.map +0 -1
- package/dist/core/codemode/types.js +0 -405
- package/dist/core/codemode/types.js.map +0 -1
- package/dist/core/context.d.ts +0 -10
- package/dist/core/context.d.ts.map +0 -1
- package/dist/core/context.js +0 -32
- package/dist/core/context.js.map +0 -1
- package/dist/core/cost.d.ts +0 -9
- package/dist/core/cost.d.ts.map +0 -1
- package/dist/core/cost.js +0 -14
- package/dist/core/cost.js.map +0 -1
- package/dist/core/errors.d.ts +0 -48
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/errors.js +0 -85
- package/dist/core/errors.js.map +0 -1
- package/dist/core/guardrails.d.ts +0 -39
- package/dist/core/guardrails.d.ts.map +0 -1
- package/dist/core/guardrails.js +0 -40
- package/dist/core/guardrails.js.map +0 -1
- package/dist/core/handoff.d.ts +0 -35
- package/dist/core/handoff.d.ts.map +0 -1
- package/dist/core/handoff.js +0 -39
- package/dist/core/handoff.js.map +0 -1
- package/dist/core/hooks.d.ts +0 -154
- package/dist/core/hooks.d.ts.map +0 -1
- package/dist/core/hooks.js +0 -2
- package/dist/core/hooks.js.map +0 -1
- package/dist/core/hosted-tool.d.ts +0 -11
- package/dist/core/hosted-tool.d.ts.map +0 -1
- package/dist/core/hosted-tool.js +0 -7
- package/dist/core/hosted-tool.js.map +0 -1
- package/dist/core/index.d.ts +0 -35
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -18
- package/dist/core/index.js.map +0 -1
- package/dist/core/model.d.ts +0 -56
- package/dist/core/model.d.ts.map +0 -1
- package/dist/core/model.js +0 -2
- package/dist/core/model.js.map +0 -1
- package/dist/core/result.d.ts +0 -34
- package/dist/core/result.d.ts.map +0 -1
- package/dist/core/result.js +0 -31
- package/dist/core/result.js.map +0 -1
- package/dist/core/run.d.ts +0 -52
- package/dist/core/run.d.ts.map +0 -1
- package/dist/core/run.js +0 -972
- package/dist/core/run.js.map +0 -1
- package/dist/core/session.d.ts +0 -77
- package/dist/core/session.d.ts.map +0 -1
- package/dist/core/session.js +0 -160
- package/dist/core/session.js.map +0 -1
- package/dist/core/subagent.d.ts +0 -30
- package/dist/core/subagent.d.ts.map +0 -1
- package/dist/core/subagent.js +0 -52
- package/dist/core/subagent.js.map +0 -1
- package/dist/core/todo.d.ts +0 -56
- package/dist/core/todo.d.ts.map +0 -1
- package/dist/core/todo.js +0 -76
- package/dist/core/todo.js.map +0 -1
- package/dist/core/tool.d.ts +0 -26
- package/dist/core/tool.d.ts.map +0 -1
- package/dist/core/tool.js +0 -23
- package/dist/core/tool.js.map +0 -1
- package/dist/core/tracing.d.ts +0 -31
- package/dist/core/tracing.d.ts.map +0 -1
- package/dist/core/tracing.js +0 -62
- package/dist/core/tracing.js.map +0 -1
- package/dist/core/types.d.ts +0 -106
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -2
- package/dist/core/types.js.map +0 -1
- package/dist/core/utils/zod.d.ts +0 -5
- package/dist/core/utils/zod.d.ts.map +0 -1
- package/dist/core/utils/zod.js +0 -7
- package/dist/core/utils/zod.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,525 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset=".github/logo-dark.svg">
|
|
4
|
-
<source media="(prefers-color-scheme: light)" srcset=".github/logo.svg">
|
|
5
|
-
<img src=".github/logo.svg" alt="Stratus" width="80" height="80">
|
|
6
|
-
</picture>
|
|
7
|
-
</p>
|
|
1
|
+
# stratus-sdk
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
[usestratus.dev](https://usestratus.dev)
|
|
12
|
-
|
|
13
|
-
[](https://www.npmjs.com/package/stratus-sdk)
|
|
14
|
-
[](https://github.com/tylergibbs1/stratus/actions/workflows/ci.yml)
|
|
15
|
-
|
|
16
|
-
A better TypeScript agent SDK for Azure OpenAI. Build multi-agent systems with tools, handoffs, guardrails, streaming, structured output, and more.
|
|
17
|
-
|
|
18
|
-
- **Built for Azure, not bolted on** — auto-endpoint detection, Entra ID auth, content filter errors as typed exceptions, and built-in retry. No 404 config spirals, no "which SDK do I use" confusion.
|
|
19
|
-
- **Two API backends, one interface** — Chat Completions and Responses API through the same agent, tool, and session code. Start with one, switch with a single line.
|
|
20
|
-
- **Multi-agent orchestration** — handoffs, subagents, guardrails, and hooks compose through a single run loop. Hooks can deny or modify tool calls at runtime.
|
|
21
|
-
- **Client-side state you control** — save, resume, and fork conversations as portable JSON snapshots. No server-side threads, no opaque session IDs.
|
|
22
|
-
- **Type-safe from schema to output** — Zod schemas drive tool parameters, structured output, and validation. Context types flow through agents, hooks, and guardrails at compile time.
|
|
23
|
-
- **Zero dependencies** — only Zod as a peer dep. No transitive dependency sprawl, no framework lock-in.
|
|
24
|
-
|
|
25
|
-
`agents` `tools` `streaming` `structured output` `handoffs` `subagents` `guardrails` `hooks` `tracing` `sessions` `abort signals` `code mode` `todo tracking` `cost tracking`
|
|
26
|
-
|
|
27
|
-
## Install
|
|
3
|
+
> **This package has moved to [`@usestratus/sdk`](https://www.npmjs.com/package/@usestratus/sdk).**
|
|
28
4
|
|
|
29
5
|
```bash
|
|
30
|
-
bun add
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Stratus requires [Zod](https://zod.dev) as a peer dependency:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
bun add zod
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Quick Start
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { z } from "zod";
|
|
43
|
-
import { Agent, AzureResponsesModel, run, tool } from "stratus-sdk";
|
|
44
|
-
|
|
45
|
-
const model = new AzureResponsesModel({
|
|
46
|
-
endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
|
|
47
|
-
apiKey: process.env.AZURE_OPENAI_API_KEY!,
|
|
48
|
-
deployment: "gpt-5.2",
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const getWeather = tool({
|
|
52
|
-
name: "get_weather",
|
|
53
|
-
description: "Get the current weather for a city",
|
|
54
|
-
parameters: z.object({
|
|
55
|
-
city: z.string().describe("The city name"),
|
|
56
|
-
}),
|
|
57
|
-
execute: async (_ctx, { city }) => {
|
|
58
|
-
return `72°F and sunny in ${city}`;
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const agent = new Agent({
|
|
63
|
-
name: "weather-assistant",
|
|
64
|
-
instructions: "You are a helpful weather assistant.",
|
|
65
|
-
model,
|
|
66
|
-
tools: [getWeather],
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const result = await run(agent, "What's the weather in New York?");
|
|
70
|
-
console.log(result.output);
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Core Concepts
|
|
74
|
-
|
|
75
|
-
### Agents
|
|
76
|
-
|
|
77
|
-
Agents are the primary building block. Each agent has a name, instructions, a model, and optional tools, handoffs, guardrails, and hooks.
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
const agent = new Agent({
|
|
81
|
-
name: "my-agent",
|
|
82
|
-
instructions: "You are a helpful assistant.",
|
|
83
|
-
model,
|
|
84
|
-
tools: [myTool],
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Dynamic instructions based on context
|
|
88
|
-
const agent = new Agent({
|
|
89
|
-
name: "my-agent",
|
|
90
|
-
instructions: (ctx) => `You are helping ${ctx.userName}.`,
|
|
91
|
-
model,
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Tools
|
|
96
|
-
|
|
97
|
-
Define tools with Zod schemas for type-safe parameter validation:
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
const searchTool = tool({
|
|
101
|
-
name: "search",
|
|
102
|
-
description: "Search for information",
|
|
103
|
-
parameters: z.object({
|
|
104
|
-
query: z.string().describe("Search query"),
|
|
105
|
-
limit: z.number().optional().describe("Max results"),
|
|
106
|
-
}),
|
|
107
|
-
execute: async (context, { query, limit }) => {
|
|
108
|
-
// Tool logic here
|
|
109
|
-
return "search results";
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Streaming
|
|
115
|
-
|
|
116
|
-
Stream responses token-by-token:
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
const { stream: s, result } = stream(agent, "Tell me a story");
|
|
120
|
-
|
|
121
|
-
for await (const event of s) {
|
|
122
|
-
if (event.type === "content_delta") {
|
|
123
|
-
process.stdout.write(event.content);
|
|
124
|
-
} else if (event.type === "tool_call_start") {
|
|
125
|
-
console.log(`Calling: ${event.toolCall.name}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const finalResult = await result;
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Structured Output
|
|
133
|
-
|
|
134
|
-
Use Zod schemas to get typed, validated output:
|
|
135
|
-
|
|
136
|
-
```ts
|
|
137
|
-
const PersonSchema = z.object({
|
|
138
|
-
name: z.string(),
|
|
139
|
-
age: z.number(),
|
|
140
|
-
occupation: z.string(),
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
const agent = new Agent({
|
|
144
|
-
name: "extractor",
|
|
145
|
-
instructions: "Extract person information.",
|
|
146
|
-
model,
|
|
147
|
-
outputType: PersonSchema,
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const result = await run(agent, "Marie Curie was a 66-year-old physicist.");
|
|
151
|
-
console.log(result.finalOutput); // { name: "Marie Curie", age: 66, occupation: "physicist" }
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### Sessions
|
|
155
|
-
|
|
156
|
-
Sessions maintain conversation history across multiple interactions:
|
|
157
|
-
|
|
158
|
-
```ts
|
|
159
|
-
import { createSession } from "stratus-sdk";
|
|
160
|
-
|
|
161
|
-
const session = createSession({ model, tools: [myTool] });
|
|
162
|
-
|
|
163
|
-
session.send("Hello!");
|
|
164
|
-
for await (const event of session.stream()) {
|
|
165
|
-
// handle events
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
session.send("Follow-up question");
|
|
169
|
-
for await (const event of session.stream()) {
|
|
170
|
-
// handle events
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Save and resume sessions
|
|
174
|
-
const snapshot = session.save();
|
|
175
|
-
const resumed = resumeSession(snapshot, { model });
|
|
176
|
-
|
|
177
|
-
// Fork a session (new ID, same history)
|
|
178
|
-
const forked = forkSession(snapshot, { model });
|
|
179
|
-
|
|
180
|
-
// Cleanup
|
|
181
|
-
session.close();
|
|
182
|
-
// Or use Symbol.asyncDispose:
|
|
183
|
-
await using session = createSession({ model });
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Handoffs
|
|
187
|
-
|
|
188
|
-
Transfer control between specialized agents:
|
|
189
|
-
|
|
190
|
-
```ts
|
|
191
|
-
import { handoff } from "stratus-sdk";
|
|
192
|
-
|
|
193
|
-
const orderAgent = new Agent({
|
|
194
|
-
name: "order_specialist",
|
|
195
|
-
instructions: "Help with order inquiries.",
|
|
196
|
-
model,
|
|
197
|
-
tools: [lookupOrder],
|
|
198
|
-
handoffDescription: "Transfer for order questions",
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const triageAgent = new Agent({
|
|
202
|
-
name: "triage",
|
|
203
|
-
instructions: "Route to the right specialist.",
|
|
204
|
-
model,
|
|
205
|
-
handoffs: [
|
|
206
|
-
orderAgent, // shorthand
|
|
207
|
-
handoff({ // with options
|
|
208
|
-
agent: refundAgent,
|
|
209
|
-
onHandoff: () => console.log("Transferring..."),
|
|
210
|
-
}),
|
|
211
|
-
],
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const result = await run(triageAgent, "Where is my order?");
|
|
215
|
-
console.log(result.lastAgent.name); // "order_specialist"
|
|
6
|
+
bun add @usestratus/sdk
|
|
216
7
|
```
|
|
217
8
|
|
|
218
|
-
|
|
9
|
+
This package is a shim that re-exports everything from `@usestratus/sdk`. Existing code continues to work — but please update your imports:
|
|
219
10
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
import { subagent } from "stratus-sdk";
|
|
224
|
-
|
|
225
|
-
const researcher = new Agent({
|
|
226
|
-
name: "researcher",
|
|
227
|
-
instructions: "Research topics thoroughly.",
|
|
228
|
-
model,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
const parentAgent = new Agent({
|
|
232
|
-
name: "parent",
|
|
233
|
-
instructions: "Use the researcher for deep dives.",
|
|
234
|
-
model,
|
|
235
|
-
subagents: [
|
|
236
|
-
subagent({
|
|
237
|
-
agent: researcher,
|
|
238
|
-
inputSchema: z.object({ topic: z.string() }),
|
|
239
|
-
mapInput: ({ topic }) => `Research: ${topic}`,
|
|
240
|
-
}),
|
|
241
|
-
],
|
|
242
|
-
});
|
|
11
|
+
```diff
|
|
12
|
+
- import { Agent, run, tool } from "stratus-sdk";
|
|
13
|
+
+ import { Agent, run, tool } from "@usestratus/sdk";
|
|
243
14
|
```
|
|
244
15
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
Validate inputs and outputs with guardrails:
|
|
248
|
-
|
|
249
|
-
```ts
|
|
250
|
-
import type { InputGuardrail, OutputGuardrail } from "stratus-sdk";
|
|
251
|
-
|
|
252
|
-
const profanityFilter: InputGuardrail = {
|
|
253
|
-
name: "profanity_filter",
|
|
254
|
-
execute: (input) => ({
|
|
255
|
-
tripwireTriggered: containsProfanity(input),
|
|
256
|
-
outputInfo: "Blocked by profanity filter",
|
|
257
|
-
}),
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const piiFilter: OutputGuardrail = {
|
|
261
|
-
name: "pii_filter",
|
|
262
|
-
execute: (output) => ({
|
|
263
|
-
tripwireTriggered: /\d{3}-\d{2}-\d{4}/.test(output),
|
|
264
|
-
outputInfo: "Output contained PII",
|
|
265
|
-
}),
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
const agent = new Agent({
|
|
269
|
-
name: "guarded",
|
|
270
|
-
model,
|
|
271
|
-
inputGuardrails: [profanityFilter],
|
|
272
|
-
outputGuardrails: [piiFilter],
|
|
273
|
-
});
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
Guardrails run in parallel. When a tripwire is triggered, an `InputGuardrailTripwireTriggered` or `OutputGuardrailTripwireTriggered` error is thrown.
|
|
277
|
-
|
|
278
|
-
### Hooks
|
|
279
|
-
|
|
280
|
-
Lifecycle hooks for observability and control:
|
|
16
|
+
All subpaths work:
|
|
281
17
|
|
|
282
|
-
```
|
|
283
|
-
import
|
|
18
|
+
```diff
|
|
19
|
+
- import { Agent } from "stratus-sdk/core";
|
|
20
|
+
+ import { Agent } from "@usestratus/sdk/core";
|
|
284
21
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
afterRun: ({ agent, result }) => { /* ... */ },
|
|
288
|
-
|
|
289
|
-
// Return a decision to allow, deny, or modify tool calls
|
|
290
|
-
beforeToolCall: ({ toolCall }) => {
|
|
291
|
-
if (toolCall.function.name === "dangerous_tool") {
|
|
292
|
-
return { decision: "deny", reason: "Not allowed" };
|
|
293
|
-
}
|
|
294
|
-
return { decision: "allow" };
|
|
295
|
-
},
|
|
296
|
-
afterToolCall: ({ toolCall, result }) => { /* ... */ },
|
|
297
|
-
|
|
298
|
-
// Allow or deny handoffs
|
|
299
|
-
beforeHandoff: ({ fromAgent, toAgent }) => {
|
|
300
|
-
return { decision: "allow" };
|
|
301
|
-
},
|
|
302
|
-
};
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Tracing
|
|
306
|
-
|
|
307
|
-
Opt-in tracing with zero overhead when inactive:
|
|
308
|
-
|
|
309
|
-
```ts
|
|
310
|
-
import { withTrace } from "stratus-sdk";
|
|
311
|
-
|
|
312
|
-
const { result, trace } = await withTrace("my-workflow", () =>
|
|
313
|
-
run(agent, "Hello"),
|
|
314
|
-
);
|
|
315
|
-
|
|
316
|
-
console.log(trace.id);
|
|
317
|
-
console.log(trace.duration);
|
|
318
|
-
for (const span of trace.spans) {
|
|
319
|
-
console.log(`[${span.type}] ${span.name} (${span.duration}ms)`);
|
|
320
|
-
// span.type: "model_call" | "tool_execution" | "handoff" | "guardrail" | "subagent" | "custom"
|
|
321
|
-
}
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Abort Signals
|
|
325
|
-
|
|
326
|
-
Cancel runs with `AbortSignal`:
|
|
327
|
-
|
|
328
|
-
```ts
|
|
329
|
-
const controller = new AbortController();
|
|
330
|
-
|
|
331
|
-
setTimeout(() => controller.abort(), 5000);
|
|
332
|
-
|
|
333
|
-
try {
|
|
334
|
-
const result = await run(agent, "Long task...", {
|
|
335
|
-
signal: controller.signal,
|
|
336
|
-
});
|
|
337
|
-
} catch (error) {
|
|
338
|
-
if (error instanceof RunAbortedError) {
|
|
339
|
-
console.log("Run was cancelled");
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
### Todo Tracking
|
|
345
|
-
|
|
346
|
-
Track task progress during agent execution:
|
|
347
|
-
|
|
348
|
-
```ts
|
|
349
|
-
import { todoTool, TodoList } from "stratus-sdk";
|
|
350
|
-
|
|
351
|
-
const todos = new TodoList();
|
|
352
|
-
todos.onUpdate((items) => {
|
|
353
|
-
for (const item of items) {
|
|
354
|
-
const icon = item.status === "completed" ? "+" : item.status === "in_progress" ? ">" : "-";
|
|
355
|
-
console.log(`${icon} ${item.content}`);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const agent = new Agent({
|
|
360
|
-
name: "planner",
|
|
361
|
-
instructions: "Break tasks into steps and track progress with todo_write.",
|
|
362
|
-
model,
|
|
363
|
-
tools: [todoTool(todos)],
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
await run(agent, "Set up a new TypeScript project");
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### Usage & Cost Tracking
|
|
370
|
-
|
|
371
|
-
Track token usage and estimate costs:
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
import { createCostEstimator } from "stratus-sdk";
|
|
375
|
-
|
|
376
|
-
const estimator = createCostEstimator({
|
|
377
|
-
inputTokenCostPer1k: 0.01,
|
|
378
|
-
outputTokenCostPer1k: 0.03,
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const result = await run(agent, "Hello", { costEstimator: estimator });
|
|
382
|
-
console.log(result.usage.totalTokens); // token counts
|
|
383
|
-
console.log(result.totalCostUsd); // estimated cost
|
|
384
|
-
console.log(result.numTurns); // model call count
|
|
385
|
-
|
|
386
|
-
// Set budget limits
|
|
387
|
-
const result = await run(agent, "Hello", {
|
|
388
|
-
costEstimator: estimator,
|
|
389
|
-
maxBudgetUsd: 0.50, // throws MaxBudgetExceededError if exceeded
|
|
390
|
-
});
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
### Tool Choice & Tool Use Behavior
|
|
394
|
-
|
|
395
|
-
Control how the model uses tools:
|
|
396
|
-
|
|
397
|
-
```ts
|
|
398
|
-
const agent = new Agent({
|
|
399
|
-
name: "my-agent",
|
|
400
|
-
model,
|
|
401
|
-
tools: [myTool],
|
|
402
|
-
modelSettings: {
|
|
403
|
-
// "auto" | "none" | "required" | { type: "function", function: { name: "..." } }
|
|
404
|
-
toolChoice: "required",
|
|
405
|
-
},
|
|
406
|
-
// "run_llm_again" (default) | "stop_on_first_tool" | { stopAtToolNames: ["..."] }
|
|
407
|
-
toolUseBehavior: "stop_on_first_tool",
|
|
408
|
-
});
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
### Code Mode (Experimental)
|
|
412
|
-
|
|
413
|
-
Let LLMs write code that orchestrates multiple tools instead of calling them one at a time. Inspired by [Cloudflare's Code Mode](https://blog.cloudflare.com/code-mode-the-better-way-to-use-mcp) — LLMs are better at writing code than making individual tool calls.
|
|
414
|
-
|
|
415
|
-
```ts
|
|
416
|
-
import { createCodeModeTool, FunctionExecutor } from "stratus-sdk/core";
|
|
417
|
-
|
|
418
|
-
const executor = new FunctionExecutor({ timeout: 30_000 });
|
|
419
|
-
const codemode = createCodeModeTool({
|
|
420
|
-
tools: [getWeather, sendEmail, lookupOrder],
|
|
421
|
-
executor,
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
const agent = new Agent({
|
|
425
|
-
name: "assistant",
|
|
426
|
-
model,
|
|
427
|
-
tools: [codemode],
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
// The LLM writes code like:
|
|
431
|
-
// async () => {
|
|
432
|
-
// const weather = await codemode.get_weather({ location: "London" });
|
|
433
|
-
// if (weather.temp > 60) {
|
|
434
|
-
// await codemode.send_email({ to: "team@co.com", subject: "Nice day!", body: ... });
|
|
435
|
-
// }
|
|
436
|
-
// return { weather, notified: true };
|
|
437
|
-
// }
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
`createCodeModeTool` generates TypeScript types from your tools, presents the LLM with a single `execute_code` tool, and runs the generated code in an executor. All tool calls happen within one invocation — no round-trips through the model between calls. Implement the `Executor` interface for custom sandboxes (isolated-vm, containers, Cloudflare Workers).
|
|
441
|
-
|
|
442
|
-
## Imports
|
|
443
|
-
|
|
444
|
-
Stratus provides three export paths:
|
|
445
|
-
|
|
446
|
-
```ts
|
|
447
|
-
// Everything (core + Azure)
|
|
448
|
-
import { Agent, run, tool, AzureChatCompletionsModel, AzureResponsesModel } from "stratus-sdk";
|
|
449
|
-
|
|
450
|
-
// Core only (provider-agnostic)
|
|
451
|
-
import { Agent, run, tool } from "stratus-sdk/core";
|
|
452
|
-
|
|
453
|
-
// Azure provider only
|
|
454
|
-
import { AzureChatCompletionsModel, AzureResponsesModel } from "stratus-sdk/azure";
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
## Configuration
|
|
458
|
-
|
|
459
|
-
### Azure OpenAI
|
|
460
|
-
|
|
461
|
-
Stratus includes two interchangeable Azure model implementations:
|
|
462
|
-
|
|
463
|
-
```ts
|
|
464
|
-
// Chat Completions API
|
|
465
|
-
const model = new AzureChatCompletionsModel({
|
|
466
|
-
endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
|
|
467
|
-
apiKey: process.env.AZURE_OPENAI_API_KEY!,
|
|
468
|
-
deployment: "gpt-5.2",
|
|
469
|
-
apiVersion: "2025-03-01-preview", // optional, this is the default
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// Responses API
|
|
473
|
-
const model = new AzureResponsesModel({
|
|
474
|
-
endpoint: process.env.AZURE_OPENAI_ENDPOINT!,
|
|
475
|
-
apiKey: process.env.AZURE_OPENAI_API_KEY!,
|
|
476
|
-
deployment: "gpt-5.2",
|
|
477
|
-
apiVersion: "2025-04-01-preview", // optional, this is the default
|
|
478
|
-
});
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
Both implement the same `Model` interface — swap one for the other without changing any agent, tool, or session code.
|
|
482
|
-
|
|
483
|
-
### Environment Variables
|
|
484
|
-
|
|
485
|
-
```
|
|
486
|
-
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
|
|
487
|
-
AZURE_OPENAI_API_KEY=your-api-key
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
## Error Handling
|
|
491
|
-
|
|
492
|
-
All errors extend `StratusError`:
|
|
493
|
-
|
|
494
|
-
| Error | Description |
|
|
495
|
-
|---|---|
|
|
496
|
-
| `StratusError` | Base error class |
|
|
497
|
-
| `ModelError` | API call failures (includes `status` and `code`) |
|
|
498
|
-
| `ContentFilterError` | Content filtered by Azure's content management policy |
|
|
499
|
-
| `MaxTurnsExceededError` | Agent exceeded the `maxTurns` limit |
|
|
500
|
-
| `OutputParseError` | Structured output failed Zod validation |
|
|
501
|
-
| `RunAbortedError` | Run cancelled via `AbortSignal` |
|
|
502
|
-
| `InputGuardrailTripwireTriggered` | Input guardrail blocked the request |
|
|
503
|
-
| `OutputGuardrailTripwireTriggered` | Output guardrail blocked the response |
|
|
504
|
-
|
|
505
|
-
```ts
|
|
506
|
-
import { ModelError, MaxTurnsExceededError, RunAbortedError } from "stratus-sdk";
|
|
507
|
-
|
|
508
|
-
try {
|
|
509
|
-
await run(agent, input);
|
|
510
|
-
} catch (error) {
|
|
511
|
-
if (error instanceof MaxTurnsExceededError) {
|
|
512
|
-
// Agent ran too many turns
|
|
513
|
-
} else if (error instanceof ModelError) {
|
|
514
|
-
console.log(error.status, error.code);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
## Development
|
|
520
|
-
|
|
521
|
-
```bash
|
|
522
|
-
bun test # Run tests
|
|
523
|
-
bun run lint # Lint with Biome
|
|
524
|
-
bun run typecheck # TypeScript type checking
|
|
22
|
+
- import { AzureChatCompletionsModel } from "stratus-sdk/azure";
|
|
23
|
+
+ import { AzureChatCompletionsModel } from "@usestratus/sdk/azure";
|
|
525
24
|
```
|
package/azure.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk/azure";
|
package/azure.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk/azure";
|
package/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk/core";
|
package/core.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk/core";
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk";
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@usestratus/sdk";
|
package/package.json
CHANGED
|
@@ -1,39 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stratus-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
10
|
-
"import": "./
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"import": "./index.js"
|
|
11
11
|
},
|
|
12
12
|
"./core": {
|
|
13
|
-
"types": "./
|
|
14
|
-
"import": "./
|
|
13
|
+
"types": "./core.d.ts",
|
|
14
|
+
"import": "./core.js"
|
|
15
15
|
},
|
|
16
16
|
"./azure": {
|
|
17
|
-
"types": "./
|
|
18
|
-
"import": "./
|
|
17
|
+
"types": "./azure.d.ts",
|
|
18
|
+
"import": "./azure.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "tsc -p tsconfig.build.json",
|
|
25
|
-
"typecheck": "tsc --noEmit",
|
|
26
|
-
"lint": "biome check .",
|
|
27
|
-
"lint:fix": "biome check --write .",
|
|
28
|
-
"test": "bun test"
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@usestratus/sdk": "^0.12.0"
|
|
29
23
|
},
|
|
30
24
|
"peerDependencies": {
|
|
31
25
|
"zod": "^4.0.0"
|
|
32
26
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"typescript": "^5.6.0",
|
|
37
|
-
"zod": "^4.0.0"
|
|
38
|
-
}
|
|
27
|
+
"description": "This package has moved to @usestratus/sdk. This is a shim that re-exports everything.",
|
|
28
|
+
"keywords": ["azure", "openai", "agent", "ai", "llm", "typescript", "tools", "streaming"],
|
|
29
|
+
"files": ["*.js", "*.d.ts", "README.md"]
|
|
39
30
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Tyler Gibbs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Model, ModelRequest, ModelRequestOptions, ModelResponse, StreamEvent } from "../core/model";
|
|
2
|
-
export interface AzureChatCompletionsModelConfig {
|
|
3
|
-
endpoint: string;
|
|
4
|
-
apiKey?: string;
|
|
5
|
-
azureAdTokenProvider?: () => Promise<string>;
|
|
6
|
-
deployment: string;
|
|
7
|
-
apiVersion?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class AzureChatCompletionsModel implements Model {
|
|
10
|
-
private readonly url;
|
|
11
|
-
private readonly apiKey?;
|
|
12
|
-
private readonly tokenProvider?;
|
|
13
|
-
private readonly deployment;
|
|
14
|
-
constructor(config: AzureChatCompletionsModelConfig);
|
|
15
|
-
private getAuthHeaders;
|
|
16
|
-
getResponse(request: ModelRequest, options?: ModelRequestOptions): Promise<ModelResponse>;
|
|
17
|
-
getStreamedResponse(request: ModelRequest, options?: ModelRequestOptions): AsyncGenerator<StreamEvent>;
|
|
18
|
-
private buildRequestBody;
|
|
19
|
-
private doFetch;
|
|
20
|
-
private handleErrorResponse;
|
|
21
|
-
private parseResponse;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=chat-completions-model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat-completions-model.d.ts","sourceRoot":"","sources":["../../src/azure/chat-completions-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEX,KAAK,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,WAAW,EAEX,MAAM,eAAe,CAAC;AAKvB,MAAM,WAAW,+BAA+B;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAID,qBAAa,yBAA0B,YAAW,KAAK;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAwB;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,MAAM,EAAE,+BAA+B;YAiBrC,cAAc;IAQtB,WAAW,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAOxF,mBAAmB,CACzB,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,mBAAmB,GAC3B,cAAc,CAAC,WAAW,CAAC;IAiG9B,OAAO,CAAC,gBAAgB;YA4CV,OAAO;YAiCP,mBAAmB;IA2BjC,OAAO,CAAC,aAAa;CAyCrB"}
|