Transitions and Tool calling
This example demonstrates how to create a simple workflow with three transitions that perform sequential operations. Weβll build a data processing workflow that extracts, transforms, and validates data to illustrate the core workflow concepts.
Note: This example uses
create_mock
tools for demonstration purposes to keep the example simple and focused on core workflow concepts. In real-world use cases, you would replace these mock tools with actual tools that perform the specific processing operations your automation requires (such as API calls, data transformations, file operations, or LLM interactions).
Example: Data Processing Workflow
The workflow demonstrates the three core concepts through a simple data processing example:
workflows:
- name: process_data
type: stateMachine
transitions:
- name: extract_data # Step 1: Extract raw data
from: start
to: data_extracted
call:
- tool: create_mock
arguments:
input: 'customer_records.csv'
output: 'John Doe,john@example.com,Premium,2024-01-15'
as: RAW_DATA
- tool: create_chat_message
arguments:
role: 'assistant'
content: ${ RAW_DATA }
- name: transform_data # Step 2: Transform the data
from: data_extracted
to: data_transformed
call:
- tool: create_mock
arguments:
input: ${ RAW_DATA }
output:
name: "John Doe"
email: "john@example.com"
tier: "Premium"
signup_date: "2024-01-15"
as: STRUCTURED_DATA
- tool: create_chat_message
arguments:
role: 'assistant'
content: |
Transformed Entry Name: {{ STRUCTURED_DATA.name }}
- name: validate_data # Step 3: Validate the result
from: data_transformed
to: end
call:
- tool: create_mock
arguments:
input: ${ STRUCTURED_DATA }
output: true
as: VALIDATION_RESULT
- tool: create_chat_message
arguments:
role: 'assistant'
content: 'Data processing complete: {{#if VALIDATION_RESULT}}Validation passed.{{else}}Validation failed.{{/if}}'
Understanding Transitions
Each transition represents a step in your business process and moves the workflow between states:
- Workflow starts in the
start
state extract_data
transition moves todata_extracted
state and exports RAW_DATAtransform_data
transition moves todata_transformed
state and exports STRUCTURED_DATAvalidate_data
transition moves toend
state, completing the workflow
Transition 1: Extract Data
- name: extract_data
from: start # Starting state
to: data_extracted # Target state after completion
call: # Tools to execute during this step
- tool: create_mock
arguments:
input: 'customer_records.csv'
output: 'John Doe,john@example.com,Premium,2024-01-15'
as: RAW_DATA # Make result available to next transitions
- tool: create_chat_message
arguments:
role: 'assistant'
content: ${ RAW_DATA } # Display the extracted data
Key Concepts:
- State Progression: Moves workflow from
start
todata_extracted
- Mock Tool:
create_mock
simulates data extraction for demonstration - Data Export:
as: RAW_DATA
stores the result for later use - Immediate Display: Chat message shows the extracted data in the interface
Transition 2: Transform Data
- name: transform_data
from: data_extracted # Must match the 'to' state from previous transition
to: data_transformed
call:
- tool: create_mock
arguments:
input: ${ RAW_DATA } # Access data from previous transition
output:
name: "John Doe"
email: "john@example.com"
tier: "Premium"
signup_date: "2024-01-15"
as: STRUCTURED_DATA
- tool: create_chat_message
arguments:
role: 'assistant'
content: |
Transformed Entry Name: {{ STRUCTURED_DATA.name }}
Key Concepts:
- Data Access: Use
${ RAW_DATA }
to access exported variables from previous transitions
Transition 3: Validate Data
- name: validate_data
from: data_transformed
to: end # 'end' is a special state that completes the workflow
call:
- tool: create_mock
arguments:
input: ${ STRUCTURED_DATA }
output: true # Boolean output for validation result
as: VALIDATION_RESULT
- tool: create_chat_message
arguments:
role: 'assistant'
content: 'Data processing complete: {{#if VALIDATION_RESULT}}Validation passed.{{else}}Validation failed.{{/if}}'
Key Concepts:
- End State: Workflows complete when they reach the
end
state - Template Logic: Use
{{#if VALIDATION_RESULT}} ... {{else}} ... {{/if}}
syntax for conditional logic
Tool Calling
Tools perform the actual work during transitions and can be chained together:
call:
- tool: create_mock # First tool call
arguments:
input: ${ PREVIOUS_RESULT }
output: 'Processed result'
as: NEW_RESULT
- tool: create_chat_message # Second tool call in same transition
arguments:
role: 'assistant'
content: ${ NEW_RESULT } # Uses result from first tool call
Key Concepts:
- Tool Chaining: Multiple tools can execute in sequence within one transition
- Immediate Access: Later tool calls in the same transition can access
as
results - Chat Integration:
create_chat_message
displays results in the Studio interface
Data Flow between transitions
Variables flow between transitions using the as
mechanism:
Data Flow Pattern:
- Step 1:
RAW_DATA
contains the raw CSV string - Step 2:
STRUCTURED_DATA
contains the parsed object - Step 3:
VALIDATION_RESULT
contains the boolean validation result - Scope: Variables are available to all subsequent transitions in the same workflow
Running This Example
This example is already available in Loopstack Studio:
- Navigate to the Studio interface
- Switch to the examples workspace
- Select βExample 3: Transitions and Tool Callingβ from the available automations
- Watch each transition execute in order, displaying results in the chat interface
Configuration Location: You can also view the complete configuration file at src/config/examples/basic/transitions-and-tool-calling-example.yaml
Complete Example:
include:
- core/tools/create-mock.yaml
- core/tools/create-chat-message.yaml
pipelines:
- name: transitions_tool_example
title: "Example 3: Transitions and Tool Calling"
type: root
workspace: examples
sequence:
- workflow: process_data
workflows:
- name: process_data
type: stateMachine
transitions:
- name: extract_data # Step 1: Extract raw data
from: start
to: data_extracted
call:
- tool: create_mock
arguments:
input: 'customer_records.csv'
output: 'John Doe,john@example.com,Premium,2024-01-15'
as: RAW_DATA
- tool: create_chat_message
arguments:
role: 'assistant'
content: ${ RAW_DATA }
- name: transform_data # Step 2: Transform the data
from: data_extracted
to: data_transformed
call:
- tool: create_mock
arguments:
input: ${ RAW_DATA }
output:
name: "John Doe"
email: "john@example.com"
tier: "Premium"
signup_date: "2024-01-15"
as: STRUCTURED_DATA
- tool: create_chat_message
arguments:
role: 'assistant'
content: |
Transformed Entry Name: {{ STRUCTURED_DATA.name }}
- name: validate_data # Step 3: Validate the result
from: data_transformed
to: end
call:
- tool: create_mock
arguments:
input: ${ STRUCTURED_DATA }
output: true
as: VALIDATION_RESULT
- tool: create_chat_message
arguments:
role: 'assistant'
content: 'Data processing complete: {{#if VALIDATION_RESULT}}Validation passed.{{else}}Validation failed.{{/if}}'