In this tutorial, we build a completely native, API-free agentic storytelling system grip tape And a light hugging face model. We walk you through creating an agent with tool-using capabilities, creating a fictional world, designing characters, and organizing a multi-stage workflow that produces a coherent short story. By breaking down the implementation into modular snippets, we can clearly understand each component as it comes together in an end-to-end creative pipeline. check it out full code here,
!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))
We’ve set up our environment by installing GripTape and starting the local Hugging Face driver. We configure a helper function to display the output clearly, so we can follow each step of the workflow. As we build the foundation, we make sure everything runs locally without relying on external APIs. check it out full code here,
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)
We create an agent equipped with a calculator tool and test it with a simple mathematical signal. We see how the agent submits calculations to the tool and then produces a natural-language explanation. By running this, we verify that our local driver and tool integration works correctly. check it out full code here,
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') }}nn"
"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")
We create a world-generation function and dynamically create character-generation functions that depend on the output of the world. We define a reusable function to create character actions based on a shared context. As we assemble these components, we see how the workflow begins to take shape through hierarchical dependencies. check it out full code here,
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.nn"
"World:n{{ parent_outputs('world') }}nn"
"Character 1 (Scotty):n{{ parent_outputs('scotty') }}nn"
"Character 2 (Annie):n{{ parent_outputs('annie') }}nn"
"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)
We introduce stylistic rules and create a final storytelling act that blends world building and characters into a coherent narrative. Then we gather all the tasks into one workflow and run it with the chosen theme. Through this, we see how GripTape connects multiple signals into a structured creative pipeline. check it out full code here,
world_text = world_task.output.value
scotty_text = scotty_task.output.value
annie_text = annie_task.output.value
story_text = story_task.output.value
show("Generated World", world_text)
show("Character: Scotty", scotty_text)
show("Character: Annie", annie_text)
show("Final Story", story_text)
def summarize_story(text):
paragraphs = (p for p in text.split("n") if p.strip())
length = len(text.split())
structure_score = min(len(paragraphs), 10)
return {
"word_count": length,
"paragraphs": len(paragraphs),
"structure_score_0_to_10": structure_score,
}
metrics = summarize_story(story_text)
show("Story Metrics", metrics)
We retrieve all the generated output and display the world, characters, and final story. We also calculate simple metrics to evaluate structure and length, giving us a quick analytical summary. As we finish, we see that the entire workflow produced measurable, interpretable results.
Finally, we demonstrate how easily we can organize complex reasoning steps, tool interactions, and creative generation using local models within the GripTap framework. We experience how modular tasks, rule-sets and workflows merge into a powerful agent system capable of generating structured narrative outputs. By running everything without external APIs, we gain full control, reproducibility, and flexibility, opening the door to more advanced experiments in native agent pipelines, automated authoring systems, and multi-task orchestration.
check it out full code hereFeel free to check us out GitHub page for tutorials, code, and notebooksAlso, feel free to follow us Twitter And don’t forget to join us 100k+ ml subreddit and subscribe our newsletterwait! Are you on Telegram? Now you can also connect with us on Telegram.
Asif Razzaq Marktechpost Media Inc. Is the CEO of. As a visionary entrepreneur and engineer, Asif is committed to harnessing the potential of Artificial Intelligence for social good. Their most recent endeavor is the launch of MarketTechPost, an Artificial Intelligence media platform, known for its in-depth coverage of Machine Learning and Deep Learning news that is technically robust and easily understood by a wide audience. The platform boasts of over 2 million monthly views, which shows its popularity among the audience.

