# Calling Children Flows

***

One of the powerful features of Tailwinds is that you can turn flows into tools. For example, having a main flow to orchestrate which/when to use the necessary tools. And each tool is designed to perform a niece/specific thing.

This offers a few benefits:

* Each children flow as tool will execute on its own, with separate memory to allow cleaner output
* Aggregating detailed outputs from each children flow to a final agent, often results in higher quality output

You can achieve this by using the following tools:

* Chatflow Tool
* Custom Tool

## Chatflow Tool

1. Have a chatflow ready. In this case, we create a Chain of Thought chatflow that can go through multiple chainings.

<figure><img src="/files/Yih5pMZt412wFTgCuvbu" alt=""><figcaption></figcaption></figure>

2. Create another chatflow with Tool Agent + Chatflow Tool. Select the chatflow you want to call from the tool. In this case, it was Chain of Thought chatflow. Give it a name, and an appropriate description to let LLM knows when to use this tool:

<figure><img src="/files/fOI3fq7wiLXAznRq8lrR" alt="" width="245"><figcaption></figcaption></figure>

3. Test it out!

<figure><img src="/files/gTu5brxioGMprWUTFo33" alt=""><figcaption></figcaption></figure>

4. From the response, you can see the input and output from the Chatflow Tool:

<figure><img src="/files/Mrqfhw7tgxfOmlu0MLjt" alt=""><figcaption></figcaption></figure>

## Custom Tool

With the same example as above, we are going to create a custom tool that will calls the [Prediction API](https://github.com/innovativeSol/tailwinds-docs/blob/main/using-flowise/api.md#prediction-api) of the Chain of Thought chatflow.

1. Create a new tool:

<table><thead><tr><th width="180">Tool Name</th><th>Tool Description</th></tr></thead><tbody><tr><td>ideas_flow</td><td>Use this tool when you need to achieve certain objective</td></tr></tbody></table>

Input Schema:

<table><thead><tr><th>Property</th><th>Type</th><th>Description</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>input</td><td>string</td><td>input question</td><td>true</td></tr></tbody></table>

<figure><img src="/files/QBE1qCHVSzzSQHoXDOZq" alt=""><figcaption></figcaption></figure>

Javascript Function of the tool:

```javascript
const fetch = require('node-fetch');
const url = 'http://<yourTailwindsURL>/api/v1/prediction/<chatflow-id>'; // replace with specific chatflow id

const body = {
	"question": $input
};

const options = {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json'
	},
	body: JSON.stringify(body)
};

try {
	const response = await fetch(url, options);
	const resp = await response.json();
	return resp.text;
} catch (error) {
	console.error(error);
	return '';
}
```

2. Create a Tool Agent + Custom Tool. Specify the tool we've created in Step 1 in the Custom Tool.

<figure><img src="/files/84WnUFhZexXPjterAOr8" alt=""><figcaption></figcaption></figure>

3. From the response, you can see the input and output from the Custom Tool:

<figure><img src="/files/Fdskuff2ftCJD5X1Nbta" alt=""><figcaption></figcaption></figure>

## Conclusion

In this example, we have successfully demonstrate 2 ways of turning other chatflows into tools, via Chatflow Tool and Custom Tool. Both are using the same code logic under the hood.


---

# 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://tailwindsdocs.innovativesol.com/readme/use-cases/calling-children-flows.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.
