Lesson 3: Coordinating Agents
Welcome to the third tutorial in our Griptape Nodes series! In this guide, you'll learn how to coordinate multiple agents within a workflow to perform sequential tasks—specifically, translating stories between languages and summarizing them.
What we'll cover
In this tutorial, we will:
- Study then recreate a translation workflow between agents working sequentially
- Discover how to "merge texts" to take outputs and modify them into new prompts
- Learn about the "exec chain" for controlling workflow execution order
- Build more into the template workflow to add a summarization task
By the end of this journey, you'll understand how to create workflows where agents build upon each other's work, passing information seamlessly between specialized tasks. This foundation will prepare you for creating sophisticated AI systems that can handle multi-step processes requiring different types of intelligence at each stage.
Let's begin by examining a simple translation workflow that demonstrates these principles in action.
Navigate to the Landing Page
To begin this tutorial, go to the landing page via the nav bar with the Griptape Nodes logo in the top left. Locate and open the example workflow called "coordinating_agents" at the top of the page.
Explore the Template Workflow
When the template loads, you'll see a workflow with the following components:
- Agent Node (spanish_story): Generates a four-line story in Spanish
- Merge Text Node: Combines the Spanish story with "Rewrite this in English"
- Second Agent Node (to_english): Translates the merged prompt into English
- Display Text Node: Shows the final English translation
This workflow demonstrates how multiple agents can each perform their own distinct "jobs."
By connecting one agent's output to another through a MergeTexts node, you create new prompts that direct the next agent's behavior.
How we're using the MergeText node here
All a MergeTexts node does is combine incoming texts using the "merge string" as a separator. The default merge string is two newlines: \n\n. In this example, I've typed "Rewrite this in English:" into input_1 of the MergeTexts node and connected the output of my spanish_story node to input_2. When run, the MergeTexts node will output:
Rewrite this in English:
Bajo la luna, el río cantó, Un secreto antiguo en su agua dejó. La niña lo escuchó y empezó a soñar, Que el mundo era suyo, listo para amar.
You can see how this method of creating new prompts out of the results of other nodes can allow for a sophisticated multi-agent workflow where the first agent writes a Spanish story, and the second agent translates it to English. Your final output will be the English translation of whatever unique Spanish story was generated.
Info
You should expect variability in these from run-to-run. That's okay! Remember, talking with an agent can in a way be like talking to a person. You may get slightly different answers if you ask them the same question many times.
Build a sibling workflow
This is what we're aiming to get to:
Now it's time to build your own workflow. Create another nearly identical flow just below this one to practice creating and connecting nodes. Add the following to your workflow:
- Two Agents ( agents > Agent ) - These are agents that interact with LLMs (Like ChatGPT, or Claude)
- A MergeTexts node ( text > MergeTexts ) - A node to accept multiple texts and output them "merged"
- A DisplayText ( text > DisplayInput ) - A node to simply display text output for easier viewing
Configure the First Agent
Set up your first agent to generate content in your chosen language:
- In the first agent node, enter:
Write me a four line story in [your chosen language](e.g., Mandarin, French, etc.) - This agent will generate the initial story that we'll translate
Connect to the MergeTexts Node
Next, prepare the translation prompt:
- Type directly into the MergeTexts node's input_1 field and enter:
Rewrite this in English - Connect the output from the first Agent to input_2 of the MergeTexts node
Configure the Second Agent
Set up the translator agent:
Connect the output of the MergeTexts node to the second Agent node's prompt. This agent will now receive both the original story, and the instruction to translate it
Display the Result
To see the final translation:
- Connect the output of the second Agent to the DisplayText node
- Run your workflow.
- After the workflow runs, this node will show the translated English text:
Understanding Execution Order (Exec Chain)
A key concept in Griptape Nodes is the execution chain. As workflows become more complex, controlling the order of execution becomes important. Let's explore this concept.
- Notice the "exec in" and "exec out" pins (half-circle connectors) on nodes
- These define the order in which nodes run
- For complex workflows, connect the exec ports in the order you want execution to occur
- This ensures nodes run in the intended sequence, even with complex data flows
Info
Griptape Nodes will automatically determine the execution order of nodes by analyzing their dependencies.
However, when you need more precise control over the execution sequence, you can use the exec chain feature. This provides a way to explicitly define the order you want when the automatic dependency detection might not align with your intended behavior.
There is no cost or penalty to using the exec chain anytime you want, except for the possibility of forcing things to execute in a faulty order. For most simple flows, it is unnecessary.
Expand the Workflow: Summarize Multiple Stories
Let's enhance our workflow to handle summarization of all the stories:
- Add another new MergeTexts node that combines both English translations
- In this merge text node, enter:
Summarize both these storiesin input_1 - Connect both the translation nodes' outputs into input_1 and input_2 on the MergeTexts node
- In this merge text node, enter:
- Add another Agent node
- Connect the MergeTexts output into the prompt for your new agent
- Connect the agent output to a new DisplayText node
- Optionally, use exec chain connections to ensure this summary step runs last (you can even connect everything up to run in the order you want)
Run the Complete Workflow
Execute your expanded workflow and observe the process:
- The first agents generate stories in different languages
- The merge text nodes create prompts to translate them
- The second agents translate the stories into English
- The summary agent combines and summarizes both translations
- The display nodes show all the results
Info
Again, remember! Look for this construction in the response you get, not that it matches what you see here - it is likely to be wildly different!
Summary
In this tutorial, we covered:
- How a workflow can hand things off between agents to perform tasks like translation
- Discovered how "merge texts" allows you to take outputs and modify them into new prompts
- Learned about the "exec chain" for controlling workflow execution order
- Built more into the template workflow to add a summarization task
Next Up
In the next section: Lesson 4: Compare Prompts, we'll learn how to get AIs to bucket-brigade, where agents pass work sequentially, through flows!