1
Create a test script
Agentic workflow are asynchronous, and so are the functions used to run them.Start by creating a script that defines a function to invoke your agentic workflow. 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.Python
2
Compile the agentic workflow
Next, compile the agentic workflow. This step generates the agentic workflow model and deploys it to the engine. It returns a If you only want to generate the JSON model without deploying it, use
CompiledFlow instance, which you can use to start a agentic workflow run. Use compile_deploy() to compile and deploy the agentic workflow.Python
compile() instead.3
Start a run
Agentic workflows 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:A simple client
A simple client
The simplest way to run a agentic workflows is to invoke it and wait for the result. Use To monitor the agentic workflow and retrieve the output:
CompiledFlow.invoke() to start the agentic workflow. You can optionally pass input data.Python
Python
Note: Always use asynchronous waits to avoid blocking the event loop.
Using event handlers
Using event handlers
You can provide custom event handlers to
invoke() for more control over agentic workflow completion and error handling.Python
Processing raw events
Processing raw events
To handle all emitted events, use You can listen for task and agentic workflow events, as defined by
invoke_events(), which returns an asynchronous iterator yielding (FlowEvent, FlowRun) tuples.Python
FlowEventType and TaskEventType in ibm_watsonx_orchestrate.experimental.flow_builder.types.
