Testing flows
After importing a flow tool, you can test it using a main Python script before add it to an agent. The following steps guide you through testing a flow, including defining, compiling, and running the flow:
Create a test script
Flows are asynchronous, and so are the functions used to run them.
Start by creating a script that defines a function to invoke your flow. In the example below, the script hello_message_flow.py
contains a function build_hello_message_flow
, decorated with @flow
, which returns the Flow
object you want to test.
Compile the flow
Next, compile the flow. This step generates the flow model and deploys it to the engine. It returns a CompiledFlow
instance, which you can use to start a flow run. Use compile_deploy()
to compile and deploy the flow.
If you only want to generate the JSON model without deploying it, use compile()
instead.
Start a run
Flows are asynchronous, and the engine communicates with your client using events. You can start a run using methods on the CompiledFlow
object. Depending on your needs, you can choose from the following approaches: