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 Launch icon.

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.

Note: If you added an agentic workflow input and want to help ensure that the agent prompts for that input, mark the input as required. If you have nested input types, mark the input as required for the nested properties that you want the agent to prompt for. If an input or property has a default value, the agent might use the default value instead of prompting the user for a value.

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:

  1. From the menu Menu, navigate to Build.
  2. Navigate to All tools.
  3. Select an existing tool or click Create tool + to add a new tool.
  4. Select Agentic workflow.

To create an agentic workflow for an agent:

  1. From the menu Menu, navigate to Build.
  2. Navigate to All agents.
  3. Find and click your agent.
  4. From the agent's toolset in the Toolset section, click Add tool.
  5. Click Agentic workflow.
  6. Update the Name if necessary.
  7. 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:

  1. Click Edit details.
  2. In the Overview field, update the name.
  3. Enter a description for the tool.
  4. Click Parameters to configure inputs and outputs for the tool.
  5. Click Add inputs to define the input. For detailed instruction, see Adding inputs
  6. Click Add outputs to define the output. For the detailed instruction, see Adding outputs
  7. 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 workflowsLaunch icon 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:

  1. Click settings on the right side of the subheader.
  2. 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.
  3. If you choose to customize the summarization instructions, then click Edit next to Custom summarization instructions.
    1. Enter the Summarization instruction.
      Specify guidance such as key details that must remain unchanged and content that can be safely omitted to reduce size.
    2. Click Save.

Add tools

To add tools to the agentic workflow:

  1. Click the add icon icon, or directly on the connector line that connects the start and end nodes.
  2. Click the Tools tab.
  3. 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:

  1. Open the tool and click edit next to Error handling.

  2. In the Error handling window, Modify the Error message if necessary.

  3. If you want, you can configure the tool to retry on error. To configure:

    1. 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.
    1. Enter the Maximum number of retries (between 1 and 5).
    2. 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:

  1. To create a branch, either:
  • Click the add icon 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 add icon. Click Branch. A branch is automatically inserted onto the connector line.
  1. The branch is preconfigured with an if-else statement.

Add paths

To add a path to a branch:

  1. Click the branch.
  2. In the branch window, select Add path.

Add path conditions

To add a condition to a path:

  1. Click the branch.
  2. 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:

    1. In the Condition builder Condition builder window, click plus icon and select a variable from the Available variables drop-down list.
    2. Click plus icon and select an Operator from the drop-down list.
    3. Click plus icon and Enter a Value.
    4. Press enter. To add more than one condition, select Add condition.
  • To build a condition by using Expression editor:

    1. Select Expression editor Expression editor.
    2. Click Enter expression and enter the Python expression.
  1. Click back.

Edit or delete a condition

To edit the conditions of a path:

  1. Click the branch.
  2. 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:

    1. Update the variable, operator, and value.
    2. Click enter.
  • To edit a condition by using Expression editor:

    1. Select expression editor Expression editor.
    2. Click the expression to open the editor window and update the Python expression.

To delete the condition of a path:

  1. Click the branch.
  2. Find the path and select Edit condition.
  3. Click delete condition delete.

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:

  1. Click the branch.
  2. Click more actions More actions.
  3. 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 move icon next to the path.

To edit a path:

  1. Click the branch.
  2. Click more actions More actions.
  3. Select Edit path name and enter the new name.

To delete a path:

  1. Click the branch.
  2. Click more actions More actions.
  3. 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:

  1. To create a For each variable, either:
  • Click the add icon 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 add icon. 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:

  1. Click the For each control.

  2. Use one of the following options to select a list:

    • By default, auto-map 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 Variable and choose a variable from the Available variables list.
    • To configure list object by using an expression, Select Expression and click Enter expression under Select a list field to open the editor window and update the Python expression.

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:

  1. Click the For each control.
  2. Click Edit details in the Local variables section.
  3. Select Add in the Local variables window.
  4. Choose the variable type from the drop-down list.
  5. Enter the Name and Description.
  6. Select the List of {object type} checkbox if you want to store a list of values in the variable.
  7. Click Add.
    To add more than one local variables, click Add.

Edit or delete local variable

To edit a local variable:

  1. Click the For each control.
  2. Click Edit details in the Local variables section.
  3. Hover over the variable and select Edit.
  4. Update the name and description in the Update output window.
  5. Click Save.

To delete a local variable:

  1. Click the For each control.
  2. Click Edit details in the Local variables section.
  3. Hover over the variable and select Delete.

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:

  1. Click start node.
  2. In the Inputs window, click Add.
  3. Select the input type from the list.
  4. Enter a Name and Description.
  5. If you want to store a list of values in the input, select the List of {data type} checkbox.
  6. Click Set default values to set the input with a default value.
  7. Enter a value and click Done 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.
  8. Click Add.

Adding outputs

To add agentic workflow outputs:

  1. Click the end node.
  2. In the Outputs window, click Add.
  3. Select the output type from the list.
  4. 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
  5. 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:

  1. Click flow variables icon on the left side of the agentic workflow window.
  2. Click Add and select the variable type from the list.
  3. Enter a Name and Description.
  4. If you want to store a list of values in the variable, select the List of {data type} checkbox.
  5. Click Set default values to set the variable with a default value.
  6. Enter a value and click Done 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.
  7. 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:

  1. Open the agentic workflow.
  2. Click the Settings icon settings icon.
  3. 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.

Automap
Figure 1. Automapping

  • 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.

Blank parameter
Figure 2. Blank parameter

  • Python expressions: You can add Python expressions for node parameters in an agentic workflow.

Expression
Figure 3. Adding expressions

  • Variables: You can add variables for node parameters in an agentic workflow.

Variables
Figure 4. Adding variables

  • 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.

Literal value
Figure 5. Adding 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.

Default value
Figure 6. Adding default 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
Note:
  • 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, and startDate are simple properties that hold integer, string, decimal, boolean, and date values.
  • address is an object property with nested properties: street, city, and zipCode.
  • badges is 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.