Notebooks
M
Mistral AI
Serial Chain Agentic Workflow

Serial Chain Agentic Workflow

agentsnon_frameworkmistral-cookbookagentic_workflowsmistral

Serial Chain Agent Workflow - Content Repurposing

Open In Colab

Introduction

In this implementation, we'll explore how to build an LLM agent workflow that transforms long-form content into engaging Twitter threads using a series of specialized LLM calls.

The serial chain agent workflow represents a powerful pattern for complex content generation and transformation tasks. At its core, this approach involves making sequential calls to language models, where each call builds upon the output of the previous one. This creates a chain of specialized processing steps that progressively refine the content toward the desired output.

Our content repurposing workflow demonstrates this pattern perfectly. We start with a blog post or video transcript and transform it into a carefully crafted Twitter thread through the following sequential steps:

  1. LLM Call 1: Extract Key Information - Analyze the source content to identify the most valuable insights, statistics, quotes, and main arguments
  2. LLM Call 2: Structure Thread Flow - Organize the extracted information into a logical thread structure with a compelling hook and satisfying conclusion
  3. LLM Call 3: Generate Tweet Text - Transform the structured outline into actual tweet text, ensuring each tweet is engaging and within character limits
  4. LLM Call 4: Enhance Engagement - Add hashtags, call-to-actions, and visual content suggestions to maximize engagement

Understanding Serial Chain Workflow

The power of the serial chain pattern lies in its simplicity and flexibility. Each LLM in the chain performs a specialized task, focusing on one aspect of the overall process. This division allows LLM to excel at a specific task rather than trying to handle the entire complex task at once.

The workflow processes the input content through consecutive LLM calls, with each step taking the output from the previous call and transforming it further. This sequential processing creates a pipeline where the content becomes increasingly refined and specialized toward the target format with each step.

Let's examine how this serial chain workflow can be implemented using MistralAI LLMs to create a powerful content repurposing system that transforms verbose blog content into concise, engaging social media formats.

Solution Architecture

solution architecture

Installation

[ ]
Collecting mistralai==1.5.0
  Downloading mistralai-1.5.0-py3-none-any.whl.metadata (29 kB)
Collecting eval-type-backport>=0.2.0 (from mistralai==1.5.0)
  Downloading eval_type_backport-0.2.2-py3-none-any.whl.metadata (2.2 kB)
Requirement already satisfied: httpx>=0.27.0 in /usr/local/lib/python3.11/dist-packages (from mistralai==1.5.0) (0.28.1)
Collecting jsonpath-python>=1.0.6 (from mistralai==1.5.0)
  Downloading jsonpath_python-1.0.6-py3-none-any.whl.metadata (12 kB)
Requirement already satisfied: pydantic>=2.9.0 in /usr/local/lib/python3.11/dist-packages (from mistralai==1.5.0) (2.11.3)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from mistralai==1.5.0) (2.8.2)
Collecting typing-inspect>=0.9.0 (from mistralai==1.5.0)
  Downloading typing_inspect-0.9.0-py3-none-any.whl.metadata (1.5 kB)
Requirement already satisfied: anyio in /usr/local/lib/python3.11/dist-packages (from httpx>=0.27.0->mistralai==1.5.0) (4.9.0)
Requirement already satisfied: certifi in /usr/local/lib/python3.11/dist-packages (from httpx>=0.27.0->mistralai==1.5.0) (2025.1.31)
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx>=0.27.0->mistralai==1.5.0) (1.0.7)
Requirement already satisfied: idna in /usr/local/lib/python3.11/dist-packages (from httpx>=0.27.0->mistralai==1.5.0) (3.10)
Requirement already satisfied: h11<0.15,>=0.13 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx>=0.27.0->mistralai==1.5.0) (0.14.0)
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.9.0->mistralai==1.5.0) (0.7.0)
Requirement already satisfied: pydantic-core==2.33.1 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.9.0->mistralai==1.5.0) (2.33.1)
Requirement already satisfied: typing-extensions>=4.12.2 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.9.0->mistralai==1.5.0) (4.13.1)
Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.9.0->mistralai==1.5.0) (0.4.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->mistralai==1.5.0) (1.17.0)
Collecting mypy-extensions>=0.3.0 (from typing-inspect>=0.9.0->mistralai==1.5.0)
  Downloading mypy_extensions-1.0.0-py3-none-any.whl.metadata (1.1 kB)
Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.11/dist-packages (from anyio->httpx>=0.27.0->mistralai==1.5.0) (1.3.1)
Downloading mistralai-1.5.0-py3-none-any.whl (271 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 271.6/271.6 kB 7.3 MB/s eta 0:00:00
Downloading eval_type_backport-0.2.2-py3-none-any.whl (5.8 kB)
Downloading jsonpath_python-1.0.6-py3-none-any.whl (7.6 kB)
Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)
Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Installing collected packages: mypy-extensions, jsonpath-python, eval-type-backport, typing-inspect, mistralai
Successfully installed eval-type-backport-0.2.2 jsonpath-python-1.0.6 mistralai-1.5.0 mypy-extensions-1.0.0 typing-inspect-0.9.0

Imports

[ ]

Initialize the Mistral client

[ ]

Execute LLM Query

Fucntion to execute a query with Mistral LLM with the given prompt and optional system prompt.

[ ]

Extract Key Information

LLM Call 1 to extract key information from the original blogpost or video transcript.

[ ]

Create Thread Structure

LLM Call 2 to create a logical thread structure from the extracted information.

[ ]

Generate Tweet Thread

LLM Call 3 to generate the actual tweets based on the thread structure.

[ ]

Add Engagement Elements

LLM Call 4 to enhance the tweet thread with engagement elements.

[ ]

Content Repurposing Chain

Run the full content repurposing chain to convert a blog post or video transcript into a Twitter thread.

[ ]

Sample Blog Post on AI in Healthcare

[ ]
[ ]
Step 1: Extracting key information...
Step 2: Creating thread structure...
Step 3: Generating tweet thread...
Step 4: Adding engagement elements...
[ ]
dict_keys(['extracted_information', 'thread_structure', 'base_tweet_thread', 'enhanced_tweet_thread'])

Final Enhanced tweet thread.

[ ]

We can check each LLM call output individually.

LLM Call-1: Extract key Information

[ ]

LLM Call-2: Create thread structure

[ ]

LLM Call-3: Create base tweet thread

[ ]

LLM Call-4: Ehanced Tweet Thread

[ ]
[ ]