Designing a Local Agentic Storytelling Pipeline
Learn to create a local storytelling system with Griptape and Hugging Face.
Overview
This tutorial demonstrates how to build a fully local, API-free agentic storytelling system using Griptape and a lightweight Hugging Face model. We'll create an agent with tool-use capabilities, generate a fictional world, design characters, and orchestrate a multi-stage workflow that produces a coherent short story. By dividing the implementation into modular snippets, we can clearly understand each component as it comes together into an end-to-end creative pipeline.
Environment Setup
We start by setting up our environment:
!pip install -q "griptape[drivers-prompt-huggingface-pipeline]" "transformers" "accelerate" "sentencepiece"We initialize a local Hugging Face driver and a helper function to display outputs cleanly, allowing us to follow each step of the workflow.
Creating an Agent
Next, we create an agent equipped with a calculator tool and test it:
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)This validates that our local driver and tool integration work correctly.
World and Character Generation
We construct the world-generation task and dynamically create character-generation tasks:
world_task = PromptTask(
input="Create a vivid fictional world using these cues: {{ args[0] }}.
Describe geography, culture, and conflicts in 3–5 paragraphs.",
id="world",
prompt_driver=local_driver,
)By defining a reusable function for character tasks, we see the workflow take shape through hierarchical dependencies.
Introducing Stylistic Rules
We integrate stylistic rules and create the final storytelling task:
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."),
],
)This brings all tasks into a coherent narrative workflow and allows us to run it effectively.
Output and Summarization
Finally, we gather all generated outputs and compute metrics for the story:
metrics = summarize_story(story_text)
show("Story Metrics", metrics)In summary, we orchestrate complex reasoning, tool interactions, and creative generation using local models within the Griptape framework. This presents a pathway for advanced experiments in local agent pipelines and automated writing systems.
For the complete code, check out the FULL CODES here.
Сменить язык
Читать эту статью на русском