@opperai/agents 0.1.3 → 0.3.0-beta
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 +32 -0
- package/dist/index.cjs +901 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +330 -4
- package/dist/index.d.ts +330 -4
- package/dist/index.js +896 -28
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -155,6 +155,38 @@ agent.registerHook(HookEvents.AgentEnd, ({ context }) => {
|
|
|
155
155
|
});
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
## Streaming
|
|
159
|
+
|
|
160
|
+
Enable live token-by-token updates by setting `enableStreaming: true` on any agent. Both the think loop and the final result switch to the streaming API, emitting incremental events while still validating the final payload.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { Agent, HookEvents } from "@opperai/agents";
|
|
164
|
+
import { z } from "zod";
|
|
165
|
+
|
|
166
|
+
const agent = new Agent({
|
|
167
|
+
name: "StreamingAgent",
|
|
168
|
+
enableStreaming: true,
|
|
169
|
+
outputSchema: z.object({ answer: z.string() }),
|
|
170
|
+
onStreamStart: ({ callType }) => {
|
|
171
|
+
console.log(`[stream:start] ${callType}`);
|
|
172
|
+
},
|
|
173
|
+
onStreamChunk: ({ callType, accumulated }) => {
|
|
174
|
+
if (callType === "final_result") {
|
|
175
|
+
process.stdout.write(accumulated);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Need to subscribe later? You can still use hooks or the event emitter.
|
|
181
|
+
agent.on(HookEvents.StreamChunk, ({ callType, fieldBuffers }) => {
|
|
182
|
+
if (callType === "think") {
|
|
183
|
+
console.debug(fieldBuffers.reasoning);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
See [docs/streaming.md](./docs/streaming.md) for hook payloads, JSON-path buffering, and usage tracking details.
|
|
189
|
+
|
|
158
190
|
## Type Safety with Zod
|
|
159
191
|
|
|
160
192
|
- Provide `inputSchema`/`outputSchema` to validate at runtime and type the agent at compile time.
|