https://discord.gg/botpress logo
Transitioning from Sequential Flows to an Agentic ...
# 🤝help
a
Hi everyone! I’ve recently completed a major architectural pivot and wanted to share the challenges I faced and the solutions implemented to achieve my goal, I want you to give me your thoughts. 1. The Problem: The "Rigidity Wall" of Sequential V1 Initially, the bot was built on a sequential model (decision trees). While robust on paper, it failed in real-world scenarios. BUT I did try to manage the cases were the user exit from my script like i mean i had a solution for the "yes" and the "no", the big issue is when the user says something or do something totally random at ANY STEP. Context Fragmentation: Variables were scoped to specific workflows. If a user switched topics mid-flow, the bot "forgot" the previous state, making transversal navigation impossible. The generate ai text: Just a terrible card, actually in botpress the only way we have to generate a quality llm text is with automnous nodes. Inability to handle "Off-Script" behavior: Any user input that didn't match a specific node caused either a crash or a generic, frustrating response. 2. The Solution: A Hybrid Hub-and-Spoke Architecture To solve this, I moved to a Hub-and-Spoke model where a central orchestrator manages specialized "Expert" modules. A. The "Gatekeeper" Pattern (Technical Firewall) To stop the AI from consuming non-text events, I implemented a Technical Gatekeeper before any AI node. Logic: A standard node checks event.type === 'file' or specific payloads. Result: Media is routed to technical processing (S3/OCR) instantly. The LLM never sees the file, preventing loops and ensuring 100% deterministic handling of uploads. In my new bot architecture, the user can send a file at any step it will be still handled correctly cause every non logical input loop on my hub.
B. Hierarchical (Cascade) Classification To maintain 99% accuracy without overloading a single prompt, I used a two-tier routing system: Tier 1 (Global): Segments the intent into broad domains (Service, Legal, Support, Small Talk). Tier 2 (Expert): Once in a domain, a second specialized router identifies the exact entry point for a sub-workflow. C. The "Hub Loop" Strategy for Autonomous Nodes To prevent the LLM from staying "in control" too long, I configured the Autonomous Nodes to act as Action Routers: The AI generates a high-quality, brief response. An instruction in the prompt forces the automnous node to swicth to the next workflow after generating an answer. The workflow then waits for the next user input at a neutral "Hub" node, keeping the bot responsive and cost-effective.
D. Global State & "Save Points" I moved critical data from temporary workflow variables to a User-Scoped Persistence layer (via Supabase/External DB). Stack-based navigation: The bot tracks the progress of each workflow. If a user deviates to ask a question, the bot can later propose: "Now that we've answered that, should we resume your previous task where we left off?" like every workflow got a variable named "steps_progression_in_this_workflow" so the user can decide to go back to the logical script if he wants to.
this workflow is a masterpiece it actually allows me to use automnous nodes like i wanted to use them
some images
sorry it was long i spend my weekend on this I’d love to get your feedback on this setup!
l
If you stumble upon this thread guys please do share your thoughts 💪🏻
a
hi @loud-crowd-60573 do botpress AI can read my workflows and summarize the architecture for someone to read it ?
so i can share it to botpress help team
w
you could try exporting your bot and passing the first half of the resulting .bpz file to an LLM and ask it to summarize
l
That is not a built in feature
a
i will try this and if doest work i will try to summarize it myself
i know its hard to understand with just the theory
w
.bpz is a zip file, inside you'll find some json files
w
.bpz is actually partially json i think
it has very readable information about your variables nodes etc when opening with an IDE
a
hey guys i will describe it in a thread when i have time !
------------------ HERE STARTS the explanations of my workflows ---------------------
Workflows Hub : What is the purpose of this workflow? The Hub-and-Spoke Orchestrator is designed to break the "Rigidity Wall" of linear chatbots. Its primary goal is to provide a non-linear, state-persistent user experience where the bot can handle unexpected user behavior, transversal topic-switching, and deterministic data processing (OCR/Calculations) without losing context or crashing. Who calls this workflow? This is the Entry Point for the entire ecosystem. It is called by: New Users: Starting their first interaction. Returning Users: Resuming a session or starting a new request. Autonomous Experts: When they detect a "Topic Deviation" (the user changes the subject), they hand control back to the Hub.
Who does he call? The Hub acts as a Grand Central Station, routing users to: Expert Workflows: (Electricity, Gas, Telecom, etc.) for specialized advice. Technical Workflows: (Upload/OCR, Manual Data Entry) for utility processing. Support/HITL: (Human-in-the-Loop) when a user explicitly asks for a person.
The walkthrough : The Hub is the first workflow you interact with in my bot, the default main botpress workflow only calls this workflow before ending. https://cdn.discordapp.com/attachments/1462809307035861153/1466071111111278723/image.png?ex=697b689f&is=697a171f&hm=0e5742f764c19ca66f5d935b548b3844586a252d2951c50e97c1d4331eaaa9a3&
Keep in mind later in the explanations, many of my workflows loop on the Hub, so I needed to build logic that handles the fact that there can be inputs from the user already sent to the bot when i come back to this workflow.
First steps, the hub capture the last input whatever the type of it in a variable, if that input is a file type or "equivalent" it calls direcrtly a workflow called Upload. Other wise it advances and start doing verifications, like if I retreieve my user and conv ids from my database or not yet, and it checks if the last input is exactly a certain string or not.
Now the most important steps of the Hub the double classifier logic, a first AI transition check whats inside 2 variables, "last input" in case of the conversation just started "llm context" which contains the last input of the user + the last answer of the automnous node about that somewhere in my workflows wherever the user was. This will make sense later https://cdn.discordapp.com/attachments/1462809307035861153/1466072825545752667/image.png?ex=697b6a37&is=697a18b7&hm=598955f4e59eae7fe970ec41420f3ebeea86fcc3817c5e94dc706cc404a99263&
that double combo of AI transition cards allows me to precisely sent the user to the right automnous node or workflows according to what i put as choices.
if the automnous nodes are out of the context of my app, they generate an answer and then they call the Hub Loop workflow. https://cdn.discordapp.com/attachments/1462809307035861153/1466073659469991978/image.png?ex=697b6afe&is=697a197e&hm=cfed53ba767ba6fddbc6ca336942ce797a9a35424f07ec03eb19cec661109742&
if its the context then we switch to expertise workflows
Workflows Hub Loop : This workflow purpose is to send the user back to the hub if the last input was text and not a file, before he send the user back to the hub he setup the llm context variable.
Expertise workflows : They are called after the ai transition card in the Hub decided to send the user to the X or Y expertise workflow, those workflows are only made of 1 automnous node who is expert in the subject. https://cdn.discordapp.com/attachments/1462809307035861153/1466074994974130247/image.png?ex=697b6c3d&is=697a1abd&hm=03a7d42c8898e6c9ad795aa3e36050f219cc7b21fb5d18cb078bca2136e1b36c&
this automnous node have 3 exits, the Automnous "Expertise" Loop (Automnous_electricity in the photo), its basically a trick that i have builded to allow me to stop the automnous node from generating text after the first answer, so i can check if that input is a text or a file. And also i dont want my user being caged in the automnous node forever if the condition X or Y is fullfield
He exit to the hub loop if the automnous node decide that according to the variable llm context (which i remind you is the previous llm answer + what the user answered to that) that the user changed the subject, thats the only way i find so that the automnous node can understand the switch of subject AND preventing him from repeating the same thing again and again.
He exit to the Ask expertise info workflow when the user ask something specific to the automnous node.
Upload Workflow : Its the workflow who handles the operations linked to my area of business once a file is upload, it made basically of execute code card which calls external database and integrations. https://cdn.discordapp.com/attachments/1462809307035861153/1466077542933856286/image.png?ex=697b6e9c&is=697a1d1c&hm=7d6d16b0df37bc7e36dbc8aefd102c039d5174b875a76915485701c979660ba0&
The only trick to know with this workflow is that first I use a variable as a "save" of where the user advanced in this workflow since my bot is totally adaptable, the user needs to be capable of adavancing the upload steps then change his mind write something totally out of subject being sent to the right place (typically) the hub so we give him an answer and then comeback to the upload workflow is he wants.
and all illogical answers actually calls the Hub.
So this is the solution I came to to resolve the problem I had of the user being totally random. I woukd like your feedbacks guys and if you you would have done something else to build and resolve this.
The only problem I have now is the scalability of this implementation, each new input of a user and an answer takes like 3, 4 secs which is according to my boss too long
w
the transitions are simple typescript which is very fast
and your ai tasks take only ~2s which is very good
but still seems like your bottleneck
if you need absolute speed you should use groq as a provider
could get each task down to ~500ms
a
groq is known to be faster ?
w
groq is the fastest provider i know
not grok mind you
groq
a
I will try and let you know
10 Views