A flow is a collection of nodes and edges that define the logic of your workflow. To build a flow, follow these steps:

1

Import your agents and tools

Ensure that the agents and tools you want to connect in a flow are already imported.

2

Define a Python function with the @flow decorator

Use the @flow decorator to define your flow. In the decorator, specify the flow’s name, description, input_schema, and output_schema.

  • The function must take a single parameter of type Flow and return a Flow object.
  • Construct the flow using a combination of tool(), agent(), and edge-building functions like sequence() or edge().
  • For Branch and Loop nodes, use a Python expression in the evaluator to define the branching or looping condition. For more information, see Flow expressions.

The following tabs show some code snippet examples of flows:

Example 1: Sequencing two tools

[Python]
@flow(
    name = "hello_message_flow",
    input_schema=Name,
    output_schema=str
)
def build_hello_message_flow(aflow: Flow = None) -> Flow:
    """ Based on the first and last name of a person, combine into a single name and create a simple hello world message. """

    combine_names_node = aflow.tool(combine_names)
    get_hello_message_node = aflow.tool(get_hello_message)

    aflow.edge(START, combine_names_node).edge(combine_names_node, get_hello_message_node).edge(get_hello_message_node, END)

    return aflow

For the full example and complete code, see hello_message_flow.

3

Import the flow

Import the flow as a tool using the orchestrate tools import command in the CLI.

[BASH]
orchestrate tools import -k flow -f <path-to-python-file>
4

Test the flow locally in the ADK

Test the flow you created using a Python script before adding it to an agent. For more information, see Testing flows.

5

Add the flow to one agent

After successfully testing the flow, add it to an agent’s specification and update the agent.