Using Workflows as Functions in Botpress
# 📖tutorials
p
Want to keep your bots clean and modular? You can treat workflows like functions, here’s how: 🛠️** Steps to Create a Function-like Workflow:** 1. Create a New Workflow: Think of it as your reusable “function.” 2. Define Your Variables: Add variables for data the workflow will use. E.g. userEmail, userPassword 3. Toggle Variables on Entry/Exit Nodes: * Entry node → variables the workflow should receive * Exit node → variables the workflow should return 4. Call It from your Main Workflow: Insert the sub-workflow as a card in a node. It acts as a function call: inputs go in, results come out. 5. (Optional) AI Node: If you use an AI Node to call the workflow: * Give clear instructions on what to extract and pass as input variables. * Describe when to route to the sub-workflow 💡 Use Cases for Workflow-as-Function Here’s where this approach really shines: * 🔍 Querying Specific Knowledge Bases * If your bot has multiple KBs, route to a workflow that targets the right one based on user input or context. * 🛒 Handling Complex Use Cases * Separate flows make the logic easier to maintain. * 🔁 Reusable Logic Blocks * Use the same logic (e.g., date formatting, location verification) in multiple places without copy-pasting nodes. * 📞 Escalation/Hand-off * A clean workflow for escalating to human agents or switching channels (e.g., live chat, email). 🎥 [See it in action](

https://www.youtube.com/watch?v=-N4OoKg_w4I

) (18:53) Happy Bot Building! https://cdn.discordapp.com/attachments/1375204118876000387/1375204120109256837/Screenshot_2025-05-22_at_4.08.02_PM.png?ex=6830d624&is=682f84a4&hm=15d71b913e5b4c0267116f06e9e68e7a8ffe45787dd9a1ff791101eb80b3caf7& https://cdn.discordapp.com/attachments/1375204118876000387/1375204120482418889/Screenshot_2025-05-22_at_4.05.42_PM.png?ex=6830d624&is=682f84a4&hm=d580de1814b8814f4d9f19cbe5ccc0485bb009d359401a2d717fe2e294a9151d&
b
I wish there where more in-depth tutorials. This one is actually insanely good. I geniunely learned so much from this
p
Is there any specific information you'd like to see in this format? Thank you for your feedback!
c
Is session 3 recorded last Friday
p
Unfortunately, not.
b
Mostly, in other type of scenarios, like "an inner chatbot to respond team questions" or with Integrations, and each tab, Actions, Agents, Knowledge base best practices/DOs and DON'Ts/Limitations
plus, I loved the concept of using workflows as functions.
p
These are great ideas to keep in mind for sure :))
5 Views