Mission Objective

Use Variables to pass data between agents. Implement Human-in-the-Loop approval with "Ask a Question". Create Conditional Logic with If/Then/Else. Build a Loop with the "Go To" action.

In Session 4, we built a simple chain: User → Title Generator → Output. But what if we have TWO generators (Title and Description)? And what if we want an Editor agent to review BOTH outputs together? The naive approach fails: User → Title Gen → Desc Gen → Editor. Problem: The Description Generator gets the Title Generator's output, not the user's original input. The Editor only sees the description.

The solution: Variables. A variable is a named container that stores data. Think of it as a labeled box in your backpack. Today we master variables, Human-in-the-Loop approval, conditional logic, and loops.

This is where your workflows become truly intelligent—able to branch, loop, and pause for human input.

Key Takeaways:

  • Use Variables to pass data between agents
  • Implement Human-in-the-Loop approval with "Ask a Question"
  • Create Conditional Logic with If/Then/Else
  • Build a Loop with the "Go To" action

The Gear List (Components)

Today we master the essential patterns for complex workflows:

Capturing User Input

Add a "Set Variable" node immediately after the Start node. Variable name: Local.user_input. Value: System.LastMessage.Text. Now, no matter how far down the workflow you are, you can always access the original user input.

Capturing Agent Outputs

In the Title Generator "Invoke Agent" node: Set Input = Local.user_input, Set Output variable = Local.title_output. In the Description Generator: Set Input = Local.user_input (same input!), Set Output variable = Local.desc_output. Both agents now receive the user's original prompt, not each other's outputs.

Concatenating Variables

Before the Editor agent, add a "Set Variable" node. Variable name: Local.combined_output. Value: Local.title_output & " " & Local.desc_output. The & operator concatenates text in Power Fx. Now the Editor sees both titles and descriptions!

Ask a Question (Human-in-the-Loop)

Add after the Editor. Message: "Here's your content: {Local.editor_output}. Do you approve? Type 'yes' to send by email." Save response as: Local.approval_input. The workflow PAUSES and waits for the user to respond.

If/Then/Else + Go To (Loop)

Add If/Then/Else after the question. Condition: Local.approval_input = "yes". TRUE branch: Continue to Email Agent. FALSE branch: Set Variable (Local.user_input = Local.combined_output & " User feedback: " & Local.approval_input), then Go To the Title Generator node. This creates a loop that regenerates with feedback!

The Complete YouTube Workflow

The Problem with Simple Workflows: In a simple chain, the Description Generator gets the Title Generator's output, not the user's original input. The Editor only sees the description. The solution is variables that preserve the original context.

Mastering Variables: Step 1—Add "Set Variable" after Start: Local.user_input = System.LastMessage.Text. Step 2—Title Generator: Input = Local.user_input, Output = Local.title_output. Step 3—Description Generator: Input = Local.user_input, Output = Local.desc_output. Step 4—Set Variable: Local.combined_output = Local.title_output & " " & Local.desc_output. Step 5—Editor: Input = Local.combined_output.

Human-in-the-Loop Approval: After the Editor, add "Ask a Question" with message showing the output and asking for approval. Save response to Local.approval_input. The workflow PAUSES until the user responds.

Building the Loop: On the FALSE branch of If/Then/Else, add Set Variable to append user feedback to the context, then use Go To to jump back to Title Generator. The workflow re-runs with the feedback included. Power Fx Basics: System.LastMessage.Text, Local.my_variable, "Hello " & Local.name (concatenate), Local.input = "yes" (equality check), Upper(Local.name), Local.amount > 500.

Key Points to Remember:

  • Variables are essential—use them to capture inputs and outputs
  • Set Variable + Concatenate lets you merge data from multiple agents
  • Ask a Question pauses for human input
  • If/Then/Else creates branching logic
  • Go To enables loops—but always ensure an exit condition!

The Trail Map (The Complete YouTube Workflow)

1 START → Set Variable: user_input = System.LastMessage.Text
2 Invoke Agent: Title Gen → Output: title_output
3 Invoke Agent: Desc Gen → Output: desc_output
4 Set Variable: combined = title_output & desc_output
5 Invoke Agent: Editor → Output: editor_output
6 Ask Question: "Do you approve?" → Response: approval_input
7 If/Then/Else: approval = "yes"?
8 YES → Set Variable (email_prompt) → Invoke Agent (Email Agent) → End
9 NO → Set Variable (updated_input) → Go To: Title Gen (LOOP)

Field Notes: Add Approval to Your Workflow

Take the workflow you built in Session 4 and add Human-in-the-Loop approval with a loop for revisions.

  1. Take the workflow from Session 4
  2. Add an "Ask a Question" node after the agents showing the output and asking: "Do you approve? Type 'yes' or describe changes."
  3. Add an "If/Then/Else" to check for "yes"
  4. On the "No" path, add Set Variable to append feedback, then "Go To" that loops back to regeneration
  5. Test it: try approving with "yes", then try requesting a change like "make it shorter"
  6. VERIFICATION: User can approve with "yes" and workflow continues. User can request changes and workflow loops. After the loop, output reflects the feedback.

Ranger's Warnings (Common Pitfalls)

The Naive Approach Fails

Without variables, agents pass their output to the next agent—not the original user input. The Editor only sees the last agent's output, not the complete context. Always capture user input in a variable first.

Infinite Loop Risk

If your loop condition never becomes true, the workflow runs forever (and costs you money!). Always ensure there's a way to exit the loop (e.g., user types "yes").

Power Fx Syntax

Use & for concatenation (not +). Use = for equality check in conditions. Variable names are case-sensitive.

Pro Tips

Each iteration, the user's feedback gets added to the context variable, so the AI "remembers" what was tried before. After 2-3 cycles, the content is usually perfect.

Combine all previous context when looping back so the agent understands the full history of changes requested.