Skip to content

Pipelines

Overview

A Pipeline is very similar to an Agent, but allows for multiple tasks.

You can access the final output of the Pipeline by using the output attribute.

Context

Pipelines have access to the following context variables in addition to the base context.

  • task_outputs: dictionary containing mapping of all task IDs to their outputs.
  • parent_output: output from the parent task if one exists, otherwise None.
  • parent: parent task if one exists, otherwise None.
  • child: child task if one exists, otherwise None.

Pipeline

from griptape.structures import Pipeline
from griptape.tasks import PromptTask

pipeline = Pipeline()

pipeline.add_tasks(
    # take the first argument from the pipeline `run` method
    PromptTask("{{ args[0] }}"),
    # take the output from the previous task and insert it into the prompt
    PromptTask("Say the following like a pirate: {{ parent_output }}"),
)

pipeline.run("Write me a haiku about sailing.")
[09/08/23 10:18:46] INFO     PromptTask b2d35331b8e5455abbb9567d10044001
                             Input: Write me a haiku about sailing.
[09/08/23 10:18:50] INFO     PromptTask b2d35331b8e5455abbb9567d10044001
                             Output: Sails catch morning breeze,
                             Sea whispers secrets to hull,
                             Horizon awaits.
                    INFO     PromptTask 28e36610063e4d728228a814b48296ef
                             Input: Say the following like a pirate: Sails catch morning breeze,
                             Sea whispers secrets to hull,
                             Horizon awaits.
[09/08/23 10:19:21] INFO     PromptTask 28e36610063e4d728228a814b48296ef
                             Output: Yarr! Th' sails snag th' mornin' zephyr,
                             Th' sea be whisperin' secrets to th' hull,
                             Th' horizon be awaitin', matey.