# Chaining Multiple Blocks Together

{% embed url="<https://youtu.be/b6isOq7j4aE>" %}

This guide covers how to build more advanced AI workflows by chaining blocks together. You’ll learn how to take the output from one block, save it as a variable, and use it downstream to enrich prompts, create media, and display final outputs.

## Overview: Blog Post Generator with Image

We’re building a multi-step **blog post generator** that does the following:

1. Collects a topic from the user.
2. Uses AI to generate an outline and key talking points.
3. Writes a full blog post using those points.
4. Generates a cover image based on the article.
5. Displays the final post and image together.

## Step 1: Collect the Topic

* Add a **User Input** block.
* Input type: Short text.
* Variable name: `topic`
* Label: “What topic would you like to write about?”

## Step 2: Brainstorm Key Points

* Add a **Generate Text** block.
* Prompt:

  ```
  cssCopyEditBrainstorm an outline and key topics that should be covered when writing an article about the following topic:
  <topic>{{ topic }}</topic>
  ```
* In **Output Behavior**, select “Save to Variable”.
* Name the variable: `key_points`

## Step 3: Generate the Blog Post

* Add another **Generate Text** block.
* Prompt:

  ```
  Write a long-form blog post about the following topic:
  <topic>{{ topic }}</topic>

  Make sure to follow the outline and cover key points mentioned below:
  <key_points>{{ key_points }}</key_points>
  ```
* Save the output to a new variable: `blog_post`

## Step 4: Create an Image Prompt

* Add another **Generate Text** block.
* Prompt:

  ```
  Generate an image prompt that can be used by an AI image model. Make it about the following blog post:
  <blog_post>{{ blog_post }}</blog_post>
  ```
* Save output to: `image_description`

## Step 5: Generate the Image

* Add a **Generate Image** block.
* Use `{{ image_description }}` as the image prompt.
* Save image output to: `image`

## Step 6: Display the Final Output

* Add a **Display Content** block.
* Use this markdown-style format to render both the image and blog content:

  ```
  ![Cover Image]({{ image }})

  {{ blog_post }}
  ```

This combines everything into one nicely formatted response.

## Testing the Workflow

Click **Preview** to open a draft and enter a test topic (e.g., “F1 cars and tech”). The AI will:

1. Generate an outline and key points.
2. Write the full blog post.
3. Generate an image description.
4. Create an image.
5. Display both in the final output.

Use the **Debugger** to monitor each step:

* Track inputs and outputs.
* View how variables are resolved.
* Analyze each block’s execution.

## Recap and Best Practices

* **Chaining blocks** means passing one block’s output as a variable to another block’s prompt.
* Use the **Save to Variable** setting to store data for reuse.
* Wrap variables with tags (e.g., `<blog_post>{{ blog_post }}</blog_post>`) to clarify structure.
* Use **Display Content** blocks to compile results into a final presentation.

Chaining is a core MindStudio principle that enables powerful, dynamic workflows. Practice chaining in small steps to build confidence and scale up to more complex agents.

Keep experimenting and expanding your workflows by connecting logic, generation, and media blocks together!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://university.mindstudio.ai/1-core-building-principles/chaining-multiple-blocks-together.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
