Skip to content

Commit

Permalink
feat: update examples
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D committed Dec 19, 2024
1 parent 5e68aec commit b682c02
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions examples/flows/nesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Flow } from "bee-agent-framework/experimental/flows";
import { z } from "zod";

const schema = z.object({
threshold: z.number().min(0).max(1),
counter: z.number().default(0),
});

Expand All @@ -18,16 +19,13 @@ const subtractFlow = new Flow({
}));

const flow = new Flow({
schema: z.object({
threshold: z.number().min(0).max(1),
counter: z.number().default(0),
}),
schema,
})
.addStep("start", (state) => ({
next: Math.random() > state.threshold ? "addFlow" : "subtractFlow",
next: Math.random() > state.threshold ? "delegateAdd" : "delegateSubtract",
}))
.addStep("addFlow", addFlow.asStep({ next: Flow.END }))
.addStep("subtractFlow", subtractFlow);
.addStep("delegateAdd", addFlow.asStep({ next: Flow.END }))
.addStep("delegateSubtract", subtractFlow.asStep({ next: Flow.END }));

const response = await flow.run({ threshold: 0.5 }).observe((emitter) => {
emitter.on("start", (data, event) =>
Expand Down

0 comments on commit b682c02

Please sign in to comment.