Calling Children Flows
One of the powerful features of AnswerAI 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.
.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:
.png)
- Test it out!
.png)
- From the response, you can see the input and output from the Chatflow Tool:
.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).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.
.png)
- From the response, you can see the input and output from the Custom Tool:
.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.