Creating agentic workflows
An agentic workflow defines a set of linked activities and controls that are designed to achieve a specific business purpose or goal.
Agentic workflows do not run unless an LLM model is available. If models are not configured, an administrator must add the necessary models before you run the agentic workflows. For more information, see Choosing a foundation model and Managing custom LLMs using AI gateway .
About this task
When you create an agentic workflow, you start with a start node and an end node. The start node is the entry point of the agentic workflow. It defines the inputs that are required to begin execution, such as values provided by a user or external system. It also initializes agentic workflow variables that are used as the agentic workflow progresses. The end node is the exit point of the agentic workflow. It defines the output that is returned when the agentic workflow completes execution.
The order in which you create your agentic workflow is up to you. If you know the types of activities that you want to include in your sequence, you can start by adding those activities.
Agentic workflows that are run asynchronously and can be long-running. When you run an agentic workflow tool in a chat, you provide the agentic workflow inputs, but any agentic workflow outputs might not be immediately available. Use the Get flow status utility tool that is provided to check the tool's status at any time and to retrieve the tool's outputs.
Create an agentic workflow
An agentic workflow can be created for a specific agent, or added directly to the system.
To create an agentic workflow in the system:
- From the menu
, navigate to Build.
- Navigate to All tools.
- Select an existing tool or click Create tool + to add a new tool.
- Select Agentic workflow.
To create an agentic workflow for an agent:
- From the menu
, navigate to Build.
- Navigate to All agents.
- Find and click your agent.
- From the agent's toolset in the Toolset section, click Add tool.
- Click Agentic workflow.
- Update the Name if necessary.
- Click Start build. This opens the flow editor, from here you can start creating your agentic workflow.
Edit agentic workflow details
To edit agentic workflow details:
- Click Edit details.
- In the Overview field, update the name.
- Enter a description for the tool.
- Click Parameters to configure inputs and outputs for the tool.
- Click Add inputs to define the input. For detailed instruction, see Adding inputs
- Click Add outputs to define the output. For the detailed instruction, see Adding outputs
- Click Done.
Example agentic workflows
You can download example agentic workflows from https://github.com/IBM/ibm-watsonx-orchestrate-adk/tree/main/examples/flow_builder. For information
about how to import workflows into your watsonx Orchestrate environment, see Building agentic workflows in the ADK documentation.
Configure flow settings
Flow settings allow you to automatically map chat history to node inputs and customize how data is summarized for large conversations.
To configure flow settings:
- Click
on the right side of the subheader. - The Auto-map chat history to inputs option is set to ON by default, which automatically maps the last five conversation turns from chat history as node inputs.
- If you choose to customize the summarization instructions, then click Edit next to Custom summarization instructions.
- Enter the Summarization instruction.
Specify guidance such as key details that must remain unchanged and content that can be safely omitted to reduce size. - Click Save.
- Enter the Summarization instruction.
Add tools
To add tools to the agentic workflow:
- Click the
icon, or directly on the connector line that connects the start and end nodes. - Click the Tools tab.
- Select a tool from your local instance.
Manage error handling
Error handling allows you to customize the error message that is shown to the user if the tool fails. You can also optionally configure the flow to retry the call the tool if it fails.
To define error handling for a tool:
-
Open the tool and click
next to Error handling. -
In the Error handling window, Modify the Error message if necessary.
-
If you want, you can configure the tool to retry on error. To configure:
- Enable Retry on error.
The following error codes are supported:
- 408 Request Timeout: The client took too long; retry may succeed.
- 409 Conflict: Often used for version conflicts; retry after resolving conflict.
- 425 Too Early: Request was sent too soon; retry later.
- 429 Too Many Requests: Throttling; retry after waiting for Retry-After header.
- 500 Internal Server Error: Generic server error; may be transient.
- 502 Bad Gateway: Temporary proxy/server issue; retry may succeed.
- 503 Service Unavailable: Server temporarily overloaded or down for maintenance.
- 504 Gateway Timeout: Upstream server didn’t respond in time; retry may succeed.
- Enter the Maximum number of retries (between 1 and 5).
- Adjust the Wait time between retries in milliseconds (between 1000 and 60000). The default value is 1000 ms.
Configure agentic workflow controls
Agentic workflow controls define the execution path of an agentic workflow. By configuring agentic workflow controls, you can set conditions, branches, and loops that determine how data moves between nodes.
Add a branch control
A branch controls the path that is followed in an agentic workflow. The path is defined based on specified conditions. You can define multiple paths and path conditions for the branch. If none of the conditions are met, the agentic workflow follows the default path.
To add a branch to the agentic workflow:
- To create a branch, either:
- Click the
icon. From the Create new tab, click and drag the Branch control onto the canvas. You can drop the control directly on a connector line or
anywhere on the canvas. - Select the connector line between the two nodes and click add
. Click Branch. A branch is automatically inserted onto the connector line.
- The branch is preconfigured with an if-else statement.
Add paths
To add a path to a branch:
- Click the branch.
- In the branch window, select Add path.
Add path conditions
To add a condition to a path:
- Click the branch.
- Find the path and select Edit condition. Choose one of the following options to define a condition:
-
To build a condition by using Condition builder:
- In the Condition builder
window, click
and select a variable from the Available variables drop-down list. - Click
and select an Operator from the drop-down list. - Click
and Enter a Value. - Press enter. To add more than one condition, select Add condition.
- In the Condition builder
-
To build a condition by using Expression editor:
- Select Expression editor
. - Click Enter expression and enter the Python expression.
- Select Expression editor
- Click back.
Edit or delete a condition
To edit the conditions of a path:
- Click the branch.
- Find the path and select Edit condition. Choose one of the following options to edit a condition:
-
To edit a condition by using Condition builder:
- Update the variable, operator, and value.
- Click enter.
-
To edit a condition by using Expression editor:
- Select expression editor
. - Click the expression to open the editor window and update the Python expression.
- Select expression editor
To delete the condition of a path:
- Click the branch.
- Find the path and select Edit condition.
- Click delete condition
.
Edit paths
You can manage the paths in your branch by changing the order, renaming a path, or deleting a path.
To change the order of the paths:
- Click the branch.
- Click more actions
. - Select Move up or Move down from the drop-down list to change the order.
You can also reorder the paths by clicking and dragging the
icon next to
the path.
To edit a path:
- Click the branch.
- Click more actions
. - Select Edit path name and enter the new name.
To delete a path:
- Click the branch.
- Click more actions
. - Select Delete.
Add a For each control
A For each control runs a series of actions for every item in a list. The iterator variable represents the current item in the list, and the index variable indicates its position, starting from zero. You can use them to access and process each item in the list.
To add a For each to the agentic workflow:
- To create a For each variable, either:
- Click the
icon. From the Create new tab, click and drag the For each control onto the canvas. You can drop the control directly on a connector line
or anywhere on the canvas. - Select the connector line between the two nodes and click add
. Click For each. A For each control is automatically inserted onto the connector line.
Select list
To select a list for the For each control:
-
Click the For each control.
-
Use one of the following options to select a list:
- By default, auto-map
is enabled, which select a list object form the agentic workflow input. However, you can change this default behavior and configure list object by choosing
variable or expression options. - To configure list object by using a variable, Select
and choose a variable from the Available variables list. - To configure list object by using an expression, Select
and click Enter expression under Select a list field to open the editor window
and update the Python expression.
- By default, auto-map
Once the list object is selected, the iterator and index variables are automatically provided.
Add local variables
Local variables are used only within a For each control and are not accessible outside of it. Each iteration of the For each can store intermediate results specific to that iteration. These values are stored within them and cannot be shared between different iterations.
To add local variables to the For each control:
- Click the For each control.
- Click
in the Local variables section. - Select Add in the Local variables window.
- Choose the variable type from the drop-down list.
- Enter the Name and Description.
- Select the List of {object type} checkbox if you want to store a list of values in the variable.
- Click Add.
To add more than one local variables, click Add.
Edit or delete local variable
To edit a local variable:
- Click the For each control.
- Click
in the Local variables section. - Hover over the variable and select
. - Update the name and description in the Update output window.
- Click Save.
To delete a local variable:
- Click the For each control.
- Click
in the Local variables section. - Hover over the variable and select
.
Configure activities
Activities define the actions that an agentic workflow can perform. You can configure different types of x on the task you want to accomplish.
User activities
You can use user activity to create chat-based interaction to collect input and display the result within an agentic workflow. For more information, see Adding user activities.
For an example video on how to add user activities, see Building an agentic workflow with user activities in watsonx Orchestrate in Videos.
Code blocks
You can use code block to add custom Python code directly within an agentic workflow. For more information, see Adding code blocks.
Generative prompts
You can use a generative prompt when you need help with tasks that involve natural language understanding. It works by using a large language model (LLM) to generate text or structured content. For generative prompts in agentic workflows, you can add new models through the AI Gateway. For more information, see Adding generative prompts.
For an example video on how to add generative prompts, see Building an agentic workflow with generative prompts in watsonx Orchestrate in Videos.
Document classifiers
You can add document classifiers to agentic workflows to automatically identify document types. For more information, see Adding document classifiers.
Document extractors
You can add document extractors to agentic workflows to extract fields or entities such as date, names, and others from documents. For more information, see Adding document extractors.
Text extractors
You can use a text extractor in an agentic workflow to extract text from a document. For more information, see Adding text extractors.
Inputs and outputs
Inputs are the external values that are passed into the agentic workflow at run time. They provide the initial information that is required for the agentic workflow to start its execution. Inputs can include user-provided values, system values, or data received from other process.
Outputs are the results that are produced when an agentic workflow finishes execution. They define the information returned from the agentic workflow, such as processed data or responses for upstream nodes. Outputs make the agentic workflow’s results available for reuse in other processes, tools, or workflows.
Adding inputs
To add agentic workflow inputs:
- Click start node.
- In the Inputs window, click Add.
- Select the input type from the list.
- Enter a Name and Description.
- If you want to store a list of values in the input, select the List of {data type} checkbox.
- Click Set default values to set the input with a default value.
- Enter a value and click
in the default value field.
- If you have selected the List of {object type} checkbox, you can add more than one default value in the List of default values field.
- The list of {object type} option is not available for file inputs, and the Set default value option is not available for file and object inputs.
- Click Add.
Adding outputs
To add agentic workflow outputs:
- Click the end node.
- In the Outputs window, click Add.
- Select the output type from the list.
- Select the List of {data type} checkbox to generate a list of values as output.
- The list of {object type} option is not available for file inputs
- Click Add.
Flow variables in an agentic workflow
Flow variables are used while an agentic workflow runs. You can select from available options or define custom variables. They allow data sharing between nodes, with intermediate values preserved and available across different steps. Flow variables are accessible throughout the entire agentic workflow and can be shared and updated between nodes.
Adding flow variables
To add flow variables:
- Click
icon on the left side of the agentic workflow window. - Click Add and select the variable type from the list.
- Enter a Name and Description.
- If you want to store a list of values in the variable, select the List of {data type} checkbox.
- Click Set default values to set the variable with a default value.
- Enter a value and click
in the default value field.
- If you have selected the List of {object type} checkbox, you can add more than one default value in the List of default values field. The Set default value option is not available for file, object and user variables.
- Click Add.
Mapping data
Nodes within an agentic workflow might require data as input. This data can come from the inputs into the agentic workflow, from the outputs of upstream nodes, and from chat session context.
When an agentic workflow completes, it might also produce data as output. The data that is produced by the agentic workflow might come from the agentic workflow inputs or from nodes within the agentic workflow.
By default, when a node requires data as input, the agentic workflow engine attempts to identify potential data sources. If the agentic workflow engine locates a source, it automatically maps that data into the node. However, you can override this default behavior and provide a mapping on nodes or the agentic workflow output. To override the mapping behavior for the agentic workflow output, select the End node of the agentic workflow.
To edit data mapping in an agentic worklow, select the node and then click Edit data mapping.
The following data-mapping options are available:
- Automapping: An agentic workflow automatically maps data between steps by connecting node inputs to other nodes' outputs or to the agentic workflow’s own inputs. If a required piece of data isn’t produced by any node within the agentic workflow, you can define an agentic workflow-level input with the same name and type. The agentic workflow engine then maps it automatically, which can ensure seamless data transfer throughout the agentic workflow.
Using the chat session context in automapping
Previously, agentic workflows did not automatically have access to the information entered into the chat prior to the workflow being triggered. To make the information available to the workflow, you had to define flow inputs and instruct the agent to populate them from the chat context. That process is no longer necessary and workflows can now easily be granted access to the most recent information in the chat context.
Enabling chat session context includes the last 5 conversation turns from a chat history. A conversation turn refers to a single exchange between a user and the agent in a chat.
Agentic workflows have this capability by default. If you want to turn it off, or want to check if it is enabled for your specific workflow:
- Open the agentic workflow.
- Click the Settings icon
. - Use the Auto-map chat history to inputs switch to turn the feature on or off.
If automapping is unsuccessful, you can prompt the user to provide the required input in a chat. To enable this behavior, set the Ask user for input if auto-mapping is unsuccessful switch to on when automapping data.
- Blank parameters: To leave a parameter blank, close the Auto-map option for the node parameter. If input parameters for a node in an agentic workflow are left empty or blank, then no value is passed to the input parameter throughout the agentic workflow.
- Python expressions: You can add Python expressions for node parameters in an agentic workflow.
- Variables: You can add variables for node parameters in an agentic workflow.
- Literal values: You can add a specific literal value for agentic workflow runtime, such as a number or a date, to node parameters in an agentic workflow. To add a literal value, close the Auto-map option for the node parameter. The option to set a default value is not available for parameters that are mapped to literal values.
- Default values: You can add a specific default value to node parameters in an agentic workflow. The option to set a default value is not available for parameters that are mapped to literal values.
Input, output, and variable types
The following table lists the available inputs, outputs, and variables types in an agentic workflow:
| Type | Description |
|---|---|
| Boolean | To define inputs, outputs or variables that require a true or false value |
| Date | To define a specific calendar date |
| Decimal | To define numeric values that include decimal points |
| File | To define a file that can be passed into or out of a flow. It can be used for uploading or downloading files, document processing, or passing files into or out of a tool within the flow. |
| Integer | To define whole number values |
| Object | To define input, output, or variable object properties by using JSON schema |
| String | To define text-based inputs, outputs, or variables |
| User | To define variables that store user related details |
- The User data type is available only for flow variables and is not currently supported for flow inputs or flow outputs.
Object data type
When you define an object, consider the following elements. An object includes a name, an optional description, and a set of properties defined using a simplified subset of the JSON Schema standard. For more information, see the JSON Schema documentation.
Properties can themselves be objects with their own nested properties. They can also be lists, defined using the JSON Schema array type.
Here is an example that shows the properties of an Employee object defined using JSON Schema
{
"id": {
"type": "integer",
"description": "Unique identifier for the employee"
},
"firstName": {
"type": "string",
"description": "Employee's first name"
},
"lastName": {
"type": "string",
"description": "Employee's last name"
},
"email": {
"type": "string",
"description": "Employee's email address"
},
"department": {
"type": "string",
"description": "Employee's department"
},
"salary": {
"type": "number",
"description": "Employee's salary"
},
"isActive": {
"type": "boolean",
"description": "Whether the employee is currently active"
},
"startDate": {
"type": "string",
"format": "date",
"description": "Employee's start date"
},
"badges": {
"type": "array",
"items": {
"type": "string"
},
"description": "Employee's badges"
},
"address": {
"type": "object",
"properties": {
"street": {
"type": "string"
},
"city": {
"type": "string"
},
"zipCode": {
"type": "string"
}
}
}
}
The employee object schema includes following properties:
id,email,salary,isActive, andstartDateare simple properties that hold integer, string, decimal, boolean, and date values.addressis an object property with nested properties: street, city, and zipCode.badgesis a list, expressed as a JSON Schema array of string values.
What to do next
Your agentic workflow is now created. You can use the Chat preview to test your agentic workflow.
-
A user activity consists of one or more chat-based interactions to collect input and display results within an agentic workflow.
-
A code blocks adds custom logic as Python code within your agentic workflow.
-
A generative prompt uses the capabilities of large language models (LLMs) for tasks.
-
A document classifier automatically identifies document types.
-
A document extractor gets fields and entities from documents.
-
A text extractor obtains text from a document.