Structure Run#
Overview#
Structure Run Drivers can be used to run Gen AI Builder Structures in a variety of runtime environments. When combined with the Structure Run Task or Structure Run Tool you can create complex, multi-agent pipelines that span multiple runtime environments.
Structure Run Drivers#
Local#
The LocalStructureRunDriver is used to run Gen AI Builder Structures in the same runtime environment as the code that is running the Structure.
from griptape.drivers.structure_run.local import LocalStructureRunDriver
from griptape.rules import Rule
from griptape.structures import Agent, Pipeline
from griptape.tasks import StructureRunTask
def build_joke_teller() -> Agent:
return Agent(
rules=[
Rule(
value="You are very funny.",
)
],
)
def build_joke_rewriter() -> Agent:
return Agent(
rules=[
Rule(
value="You are the editor of a joke book. But you only speak in riddles",
)
],
)
joke_coordinator = Pipeline(
tasks=[
StructureRunTask(
structure_run_driver=LocalStructureRunDriver(
create_structure=build_joke_teller,
),
),
StructureRunTask(
("Rewrite this joke: {{ parent_output }}",),
structure_run_driver=LocalStructureRunDriver(
create_structure=build_joke_rewriter,
),
),
]
)
joke_coordinator.run("Tell me a joke")
Gen AI Builder#
The GriptapeCloudStructureRunDriver is used to run Gen AI Builder Structures in the Gen AI Builder.
import os
from griptape.drivers.structure_run.griptape_cloud import GriptapeCloudStructureRunDriver
from griptape.drivers.structure_run.local import LocalStructureRunDriver
from griptape.rules import Rule
from griptape.structures import Agent, Pipeline
from griptape.tasks import StructureRunTask
base_url = os.environ["GT_CLOUD_BASE_URL"]
api_key = os.environ["GT_CLOUD_API_KEY"]
structure_id = os.environ["GT_CLOUD_STRUCTURE_ID"]
pipeline = Pipeline(
tasks=[
StructureRunTask(
("Think of a question related to Retrieval Augmented Generation.",),
structure_run_driver=LocalStructureRunDriver(
create_structure=lambda: Agent(
rules=[
Rule(
value="You are an expert in Retrieval Augmented Generation.",
),
Rule(
value="Only output your answer, no other information.",
),
]
)
),
),
StructureRunTask(
("{{ parent_output }}",),
structure_run_driver=GriptapeCloudStructureRunDriver(
base_url=base_url,
api_key=api_key,
structure_id=structure_id,
),
),
]
)
pipeline.run()