Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Continuations #3

Open
cogk opened this issue Jan 23, 2024 · 2 comments
Open

feat: Continuations #3

cogk opened this issue Jan 23, 2024 · 2 comments

Comments

@cogk
Copy link
Owner

cogk commented Jan 23, 2024

Examples:

  • Prompt: Asking a value to the user is a continuation, because it is asynchronous
flowchart TB

subgraph flow1 [Subflow 1]
direction TB
Z1[Entrypoint]
-->A1(["A1. prompt (What is your name?)"])
-->|text| B1[\B1. Suspension/]
end

flow1 -.->|"Continuation data:<br>{'text': text, 'continuation_token': 'subflow-2'}"| flow2

subgraph flow2 [Subflow 2]
direction TB
Z2[Entrypoint]
-->A2[/A2. Continuation\]
-->|text| B2(["B2. send_email (Hello {{ text }})"])
--> C2...
end

Loading
@cogk
Copy link
Owner Author

cogk commented Jan 25, 2024

Storing data across execution contexts

  • susp Suspension: The act of stopping a flow with the intent of continuing the execution at a later time. Suspension is the main mechanism allowing asynchronous tasks such as user interaction, docevent listening, scheduling.
  • coda Continuation data: A flow being suspended can store data to retrieve it at a later time. Continuation data is serialized and is safely persisted on disk. Continuation data MAY include data from the suspended flow, but only primitive values that can be serialized. Continuation data MUST include the id of the flow that should continue the execution.
  • cont Continuation: The act of resuming the execution of a flow by using persisted Continuation data.

@cogk
Copy link
Owner Author

cogk commented Jan 25, 2024

How to store documents in Continuation Data?

It's not possible:

  1. because of the serialization constraints;
  2. because it does not make sense in an asynchronous context: the document might disappear or change before Continuation;

How to transfer complex data across execution contexts?

Let's say I have an interactive flow that mimics an authentication. It asks for the user's name and password, then the user's OTP code.

flowchart TB
subgraph main
    a[Entrypoint]
==>|init| b[Ask interactive: Username?]
-.->|ok\nasync| c[Ask interactive: Password?]
-.->|ok\nasync| z[Check user exists]
==>|ok| d[Ask interactive: OTP Code?]
-.->|ok\nasync| y[Check OTP]
==>|ok| e["Show result: Welcome {{ username }}!"]
end

subgraph context
%%subgraph coda1
bx([username]) --o b
%%subgraph coda2
cx([password]) --o c
%%subgraph coda3
dx([otp_code]) --o d
%%end
%%end
%%end
end

bx ~~~ cx ~~~ dx

bx --- z
cx --- z
bx --- y
dx --- y
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant