Replies: 5 comments 7 replies
-
Now I'm really thinking whether we can switch to use xstate as low level code, so we can have
|
Beta Was this translation helpful? Give feedback.
-
@himself65 yes, i also had a couple of the issues you mentioned.
|
Beta Was this translation helpful? Give feedback.
-
For last days I read the source code and have some update: I still don't understand why we allow await In the Here're my solution for that examples code solution 1: use AsyncLocalStorage const uiAls = new AsyncLocalStorage();
workflow.addStep(SearchEvent, async () => {
const ui = uiAls.getStore()
ui.update('loading....')
// heavy search
llm.complete(...)
return StopEvent('stop!')
})
const ui = createStreamUI()
const result = await uiAls.run(ui, () => workflow.run('search'))
ui.done(result) solution 2: extend Context (need our support custom context) class MyContext extends Context {
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Second is that we should support recover event from any point, imaging there's a step that need user input first (like search), for now we cannot So im imaging the low level API should be // for the first run
const { input } = req.body()
const context = workflow.run('search ${input}')
for await (const event of context) {
if (event.requireUserInput) {
response.json({
snapshot: context.snapshot()
})
}
}
// in the second run
const { snapshot, input } = req.body()
const context = Context.recover(snapshot)
for await (const event of context) {
// ...
} |
Beta Was this translation helpful? Give feedback.
-
Most API is done in #1264, will close this discussion |
Beta Was this translation helpful? Give feedback.
-
I made some example code using next.js + LITS + vercel ai sdk. I feel it not good to use
Screen.Recording.2024-09-25.at.17.32.04.mov
Some feedback:
1.1 the event.data type workflow.handleEvent is
any
1.2
Workflow.prototype.run
can run multiple startEvent, butstreamEvents
only accept run in single context. It's hard to maintain for example you put this workflow into a server handler1.3 hard to add context data inside single context, I can only give
input: string
for a start event. What if there's more input data?And context.get/set seems useful, but since I cannot access it in the
streamEvents
. It's useless, I have to build another context layer on top of the workflow api1.4 StopEvent and StartEvent is kind of Redundant, I want customize my data type (maybe related to 1.1 or 1.3)
1.5
validate
will throw error, and it accepts no parameter. I don't know what it's used for at first glance. I think it's better to remove this function.1.6 return type of StepFunction accepct a new Event, in the meanwhile context allows
writeEventToStream
I think Workflow.prototype.run should retuns
Context
and user callawait context
could get a StopEventWorkflowEvent.prototype.toString
will leak data, imaging user have senstive input but you console.log(event) or result =${event}
other than that, I think this API is a subset of XState, Workflow is kind of Finite State Machine. I personaly would to use xstate instead of Workflow API because it more customzable (even it's hard to learn)
Beta Was this translation helpful? Give feedback.
All reactions