Saturday, December 13, 2025

The best way to Design a Totally Native Agentic Storytelling Pipeline Utilizing Griptape Workflows, Hugging Face Fashions, and Modular Artistic Process Orchestration


On this tutorial, we construct a totally native, API-free agentic storytelling system utilizing Griptape and a light-weight Hugging Face mannequin. We stroll by creating an agent with tool-use talents, producing a fictional world, designing characters, and orchestrating a multi-stage workflow that produces a coherent quick story. By dividing the implementation into modular snippets, we will clearly perceive every part because it comes collectively into an end-to-end inventive pipeline. Try the FULL CODES right here.

!pip set up -q "griptape[drivers-prompt-huggingface-pipeline]" "transformers" "speed up" "sentencepiece"


import textwrap
from griptape.buildings import Workflow, Agent
from griptape.duties import PromptTask
from griptape.instruments import CalculatorTool
from griptape.guidelines import Rule, Ruleset
from griptape.drivers.immediate.huggingface_pipeline import HuggingFacePipelinePromptDriver


local_driver = HuggingFacePipelinePromptDriver(
   mannequin="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
   max_tokens=256,
)


def present(title, content material):
   print(f"n{'='*20} {title} {'='*20}")
   print(textwrap.fill(str(content material), width=100))

We arrange our surroundings by putting in Griptape and initializing a neighborhood Hugging Face driver. We configure a helper perform to show outputs cleanly, permitting us to observe every step of the workflow. As we construct the muse, we guarantee all the pieces runs domestically with out counting on exterior APIs. Try the FULL CODES right here.

math_agent = Agent(
   prompt_driver=local_driver,
   instruments=[CalculatorTool()],
)


math_response = math_agent.run(
   "Compute (37*19)/7 and clarify the steps briefly."
)


present("Agent + CalculatorTool", math_response.output.worth)

We create an agent outfitted with a calculator software and check it with a easy mathematical immediate. We observe how the agent delegates computation to the software after which formulates a natural-language clarification. By operating this, we validate that our native driver and power integration work accurately. Try the FULL CODES right here.

world_task = PromptTask(
   enter="Create a vivid fictional world utilizing these cues: {{ args[0] }}.nDescribe geography, tradition, and conflicts in 3–5 paragraphs.",
   id="world",
   prompt_driver=local_driver,
)


def character_task(task_id, title):
   return PromptTask(
       enter=(
           "Primarily based on the world under, invent an in depth character named {{ title }}.n"
           "World description:n{{ parent_outputs['world'] }}nn"
           "Describe their background, wishes, flaws, and one secret."
       ),
       id=task_id,
       parent_ids=["world"],
       prompt_driver=local_driver,
       context={"title": title},
   )


scotty_task = character_task("scotty", "Scotty")
annie_task = character_task("annie", "Annie")

We construct the world-generation activity and dynamically assemble character-generation duties that rely upon the world’s output. We outline a reusable perform to create character duties conditioned on shared context. As we assemble these elements, we see how the workflow begins to take form by hierarchical dependencies. Try the FULL CODES right here.

style_ruleset = Ruleset(
   title="StoryStyle",
   guidelines=[
       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(
   enter=(
       "Write an entire quick story utilizing the next parts.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 will need to have a transparent starting, center, and finish, with a significant character resolution close to the climax."
   ),
   id="story",
   parent_ids=["world", "scotty", "annie"],
   prompt_driver=local_driver,
   rulesets=[style_ruleset],
)


story_workflow = Workflow(duties=[world_task, scotty_task, annie_task, story_task])
matter = "tidally locked ocean world with floating cities powered by storms"
story_workflow.run(matter)

We introduce stylistic guidelines and create the ultimate storytelling activity that merges worldbuilding and characters right into a coherent narrative. We then assemble all duties right into a workflow and run it with a selected matter. Via this, we witness how Griptape chains a number of prompts right into a structured inventive pipeline. Try the FULL CODES right here.

world_text = world_task.output.worth
scotty_text = scotty_task.output.worth
annie_text = annie_task.output.worth
story_text = story_task.output.worth


present("Generated World", world_text)
present("Character: Scotty", scotty_text)
present("Character: Annie", annie_text)
present("Closing Story", story_text)


def summarize_story(textual content):
   paragraphs = [p for p in text.split("n") if p.strip()]
   size = len(textual content.break up())
   structure_score = min(len(paragraphs), 10)
   return {
       "word_count": size,
       "paragraphs": len(paragraphs),
       "structure_score_0_to_10": structure_score,
   }


metrics = summarize_story(story_text)
present("Story Metrics", metrics)

We retrieve all generated outputs and show the world, characters, and ultimate story. We additionally compute easy metrics to judge construction and size, giving us a fast analytical abstract. As we wrap up, we observe that the total workflow produces measurable, interpretable outcomes.

In conclusion, we show how simply we will orchestrate advanced reasoning steps, software interactions, and inventive era utilizing native fashions throughout the Griptape framework. We expertise how modular duties, rulesets, and workflows merge into a strong agentic system able to producing structured narrative outputs. By operating all the pieces with out exterior APIs, we acquire full management, reproducibility, and suppleness, opening the door to extra superior experiments in native agent pipelines, automated writing techniques, and multi-task orchestration.


Try the FULL CODES right here. Be at liberty to take a look at our GitHub Web page for Tutorials, Codes and Notebooks. Additionally, be at liberty to observe us on Twitter and don’t overlook to affix our 100k+ ML SubReddit and Subscribe to our E-newsletter. Wait! are you on telegram? now you may be part of us on telegram as properly.


Asif Razzaq is the CEO of Marktechpost Media Inc.. As a visionary entrepreneur and engineer, Asif is dedicated to harnessing the potential of Synthetic Intelligence for social good. His most up-to-date endeavor is the launch of an Synthetic Intelligence Media Platform, Marktechpost, which stands out for its in-depth protection of machine studying and deep studying information that’s each technically sound and simply comprehensible by a large viewers. The platform boasts of over 2 million month-to-month views, illustrating its recognition amongst audiences.

Related Articles

Latest Articles