Skip to main content

On This Page

How to Design a Fully Local Agentic Storytelling Pipeline Using Griptape Workflows, Hugging Face Models, and Modular Creative Task Orchestration

3 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Fully Local Agentic Storytelling Pipeline

This tutorial details the creation of a fully local, API-free agentic storytelling system utilizing Griptape and a lightweight Hugging Face model, culminating in a coherent short story. The system leverages a modular approach to creative task orchestration, demonstrating the feasibility of end-to-end creative pipelines without external dependencies.

Why This Matters

Ideal AI systems often rely on cloud-based APIs for language modeling and tool use, introducing latency, cost, and data privacy concerns. Building a fully local pipeline, like the one presented, addresses these issues, but requires careful consideration of model size and computational resources. While larger models generally produce higher-quality outputs, they demand significant hardware, potentially making local execution impractical for many users, highlighting the trade-offs between performance and accessibility.

Key Insights

  • Griptape is open-source: Griptape provides a framework for building agentic workflows (Griptape, 2024).
  • Local LLMs enable privacy: Running models locally avoids sending data to third-party APIs, enhancing data security and control.
  • Modular design promotes reusability: Breaking down the storytelling process into independent tasks allows for easy modification and extension of the pipeline.

Working Example

!pip install -q "griptape[drivers-prompt-huggingface-pipeline]" "transformers" "accelerate" "sentencepiece"
import textwrap
from griptape.structures import Workflow, Agent
from griptape.tasks import PromptTask
from griptape.tools import CalculatorTool
from griptape.rules import Rule, Ruleset
from griptape.drivers.prompt.huggingface_pipeline import HuggingFacePipelinePromptDriver
local_driver = HuggingFacePipelinePromptDriver(
model="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
max_tokens=256,
)
def show(title, content):
print(f"\n{'='*20} {title} {'='*20}")
print(textwrap.fill(str(content), width=100))
math_agent = Agent(
prompt_driver=local_driver,
tools=[CalculatorTool()],
)
math_response = math_agent.run(
"Compute (37*19)/7 and explain the steps briefly."
)
show("Agent + CalculatorTool", math_response.output.value)
world_task = PromptTask(
input="Create a vivid fictional world using these cues: {{ args[0] }}.\nDescribe geography, culture, and conflicts in 3–5 paragraphs.",
id="world",
prompt_driver=local_driver,
)
def character_task(task_id, name):
return PromptTask(
input=(
"Based on the world below, invent a detailed character named {{ name }}.\n"
"World description:\n{{ parent_outputs['world'] }}\n\n"
"Describe their background, desires, flaws, and one secret."
),
id=task_id,
parent_ids=["world"],
prompt_driver=local_driver,
context={"name": name},
)
scotty_task = character_task("scotty", "Scotty")
annie_task = character_task("annie", "Annie")
style_ruleset = Ruleset(
name="StoryStyle",
rules=[
Rule("Write in a cinematic, emotionally engaging style."),
Rule("Avoid explicit gore or graphic violence."),
Rule("Keep the story between 400 and 700 words."),
],
)
story_task = PromptTask(
input=(
"Write a complete short story using the following elements.\n\n"
"World:\n{{ parent_outputs['world'] }}\n\n"
"Character 1 (Scotty):\n{{ parent_outputs['scotty'] }}\n\n"
"Character 2 (Annie):\n{{ parent_outputs['annie'] }}\n\n"
"The story must have a clear beginning, middle, and end, with a meaningful character decision near the climax."
),
id="story",
parent_ids=["world", "scotty", "annie"],
prompt_driver=local_driver,
rulesets=[style_ruleset],
)
story_workflow = Workflow(tasks=[world_task, scotty_task, annie_task, story_task])
topic = "tidally locked ocean world with floating cities powered by storms"
story_workflow.run(topic)

Practical Applications

  • Content Creation: Automating the generation of story drafts for game development or marketing materials.
  • Pitfall: Over-reliance on a single, small language model can lead to repetitive or predictable narratives, requiring careful prompt engineering and model selection.

References:

Continue reading

Next article

Using Local Packages with Composer for PHP Development

Related Content