Calling Children Flows
One of the powerful features of CiniterFlow 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
- Have a chatflow ready. In this case, we create a Chain of Thought chatflow that can go through multiple chainings.
-ea1d2c8be200a9eb90ba50f8e8db55d5.png)
- 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:
-e82daaff8a4c27548fe520e0fb758567.png)
- Test it out!
-c5669da53d015912d01ed26a1e4b0c7e.png)
- From the response, you can see the input and output from the Chatflow Tool:
-b3429ff7cf79342bb6e59b2e04de36c9.png)
Custom Tool
With the same example as above, we are going to create a custom tool that will calls the Prediction API of the Chain of Thought chatflow.
- Create a new tool:
| Tool Name | Tool Description |
|---|---|
| ideas_flow | Use this tool when you need to achieve certain objective |
Input Schema:
| Property | Type | Description | Required |
|---|---|---|---|
| input | string | input question | true |
 (1)-dd348797e20ae5c7c35a1cca0a520081.png)
Javascript Function of the tool:
const fetch = require('node-fetch');
const url = 'http://localhost:3000/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 '';
}
- Create a Tool Agent + Custom Tool. Specify the tool we've created in Step 1 in the Custom Tool.
-e5269dc62cf7adfcf059e4e64ab1a076.png)
- From the response, you can see the input and output from the Custom Tool:
-205baa861967a4c6bb49e8ea14915a04.png)
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.