> For the complete documentation index, see [llms.txt](https://docs.uncodie.com/1.0/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uncodie.com/1.0/agentbase/introduction/use-cases/agents-prompt-chaining.md).

# Agents Prompt Chaining

## Overview

Use a flow that executes a series of agents to solve a problem or prompt.

### Prompt Chaining

Prompt chaining is a method that involves linking multiple prompts together to generate more complex and refined outputs in natural language processing tasks. It enhances the performance of models by breaking down a task into smaller, manageable subtasks, each handled by a different prompt. This technique is useful for creating detailed and accurate responses by systematically narrowing down the scope and focusing on specific aspects of the task at each stage.

## Prompt Engineering

The easiest way to generate this behavior is with clear steps and actions and the prompt `Generate, create, etc`.

Prompt

{% code overflow="wrap" %}

```
1. Generate an agent to create 10 articles for health issues 2. Generate an agent to analyze the themes for an article and crate tags for each article.
```

{% endcode %}

## Usage

Leverage Base to easily design your API and prototype apps, UX, or screens. To experiment with different outcomes, set "`cached`" to `false`

Using `/base` with "`cached`" is equivalent to direclty calling the function after is creation, all none neccesary params will be ignored.

<mark style="color:green;">`POST`</mark> `/base`

Creates a new flow with one or more actions, installs dependencies, builds tests and executes the resulting code.

Actions can be agents, backend functions, or cloud functions.

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

<table><thead><tr><th width="219">Name</th><th width="101">Type</th><th width="103" data-type="checkbox">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>true</td><td>Name of the flow to summarize the actions</td></tr><tr><td><code>prompt</code></td><td>string</td><td>true</td><td>The instructions for AgentBase to transform in to code</td></tr><tr><td><code>data</code></td><td>object</td><td>false</td><td>The data example or parameters for your function to work</td></tr><tr><td><code>schedule</code></td><td>string</td><td>false</td><td>The cron calendar for the function to run automatically</td></tr><tr><td><code>return</code></td><td>object</td><td>false</td><td>The data example of your expected return</td></tr><tr><td><code>model</code></td><td>string</td><td>false</td><td>The model to run for your prompt</td></tr><tr><td><code>errors</code></td><td>array</td><td>false</td><td>List or possible errors your function needs to catch</td></tr><tr><td><code>cached</code></td><td>boolean</td><td>false</td><td>It will use the last version of the function whenever is available to save time and tokens</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "run_id": 1,
  "return" : {
        "sentiment":"sentiment",
        "sentiment_id":"id",
        "articles:" ["article"]
  },
  "error": null
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

#### Body Example

{% code overflow="wrap" lineNumbers="true" %}

```json

{
    "function": "analyze_sentiment",
    "prompt": "get the current sentimient for the message and save it as property in the post, then generate 10 articles thay may help the user to solve the problem",
    "data" : {
        "message": "message example"
    },
    "return" : {
        "sentiment":"sentiment",
        "sentiment_id":"id",
        "articles:" ["article"]
    }
}
```

{% endcode %}
