Contents · The Flow Book

Start here

The Flow Book1. Your first run2. Let the outside answer3. Keep the original answer

Build the decision

4. Give the program an input5. Name the work6. Give values a shape

Build the workflow

7. Decide what failure means8. Put the decision in its own file9. Put the pieces together

Go further

10. Work on several things11. Leave room for an answer12. Take Flow into an application

Build an application

13. Investigate a real question14. Challenge: diagnose and extend
Language reference ↗

Let the outside answer

Our review workflow needs an amount from a service. Flow can multiply numbers, but the service's answer is an outside observation. We describe that boundary with a Tool.

Try it · A typed lookup
main.flow
use "./service"

pub flow main() -> Result<Int, ToolProblem<Text>> = service.lookup()
service.flow
@tool pub flow lookup() -> Result<Int, Text>
Expected result{"Ok":42}

Two files, two responsibilities

Open service.flow. Its declaration says that lookup takes no arguments and returns either an Int or a Text failure. It has no body: the application supplies the implementation behind it.

Open main.flow. The import use "./service" binds the module name service. The call service.lookup() reaches its public declaration.

Notice the two result types. The declaration names Result<Int, Text>. Calling it produces Result<Int, ToolProblem<Text>>, because the run must also account for a reply it cannot interpret or an invocation whose outcome is unknown. We will unpack those cases in the failure chapter. For now, returning the result intact keeps every outcome visible.

Choose an answer

Run with Reply Ok(42). The result is {"Ok":42}. Change the fixture to Declared failure and run again. You have changed what answers the call; you have not changed the program's type.

The fixture selector belongs to this browser application. A Tool declaration itself provides no credentials or permission to contact a service. The application that runs Flow owns that connection.

Predict before running

What happens with Wait for a reply? The run waits. No amount is available yet, so it cannot finish this expression. Reset the lesson and use the successful fixture for the next chapter.

Exact rules: Tools.