This repository was archived by the owner on Jul 5, 2026. It is now read-only.
Add classifier_routing example: route nodes without an LLM call - #275
Open
jamsea wants to merge 5 commits into
Open
Add classifier_routing example: route nodes without an LLM call#275jamsea wants to merge 5 commits into
jamsea wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new example demonstrating an idiomatic “classifier router” pattern to deterministically route between FlowManager nodes without triggering an LLM call, while still allowing an LLM fallback for unclassified inputs.
Changes:
- New
examples/classifier_routing.pyexample implementing aFrameProcessorthat dropsLLMContextFrameon deterministic routes. - Updated
examples/README.mdto list the new example under Implementation Patterns. - Added a Towncrier changelog fragment documenting the new example.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/README.md | Adds the new example to the examples index. |
| examples/classifier_routing.py | New runnable example showing classifier-based node routing that can skip LLM inference. |
| changelog/275.added.md | Changelog entry for the new example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Author
|
Here's a demo: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new example,
examples/classifier_routing.py, showing how to route between Flow nodes using a classifier instead of an LLM call.Some node decisions are trivial: a verification step that only needs a yes/no, a menu where the user picks one of a few known options. Paying for an LLM inference to make that decision adds latency and cost you don't need. This example demonstrates the idiomatic Flows pattern for making those decisions with a plain classifier (a regex here, but the
classify()function is the seam to swap in a rules engine or a small binary classifier), while reserving the LLM only for inputs the classifier can't confidently handle.How it works
The example is a tiny age-verification bot:
verifynode usesrespond_immediately=False, so entering it triggers no LLM completion. It speaks its canned question via atts_saypre-action and then waits for the user.LLMContextFramethat the LLM service consumes and responds to. That is the LLM call we want to skip.ClassifierRouteris a customFrameProcessorplaced between the user context aggregator and the LLM. While in theverifynode it classifies the user's answer and either:yes-> confirmed,no-> declined) viaset_node_from_config(...)and drops theLLMContextFrameso the LLM never runs, orconfirmed/declinednodes also avoid the LLM: they speak a canned line and end the call with anend_conversationpre-action.ClassifierRouterdrops exactly one frame type (LLMContextFrame), and only in the deterministic branch, because that frame is precisely the LLM-run trigger. Every other frame is always pushed through.Changes
examples/classifier_routing.pyexamples/README.md: listed the new example under Implementation PatternsTesting
ruff format+ruff check: cleanclassify()returns the expected yes/no/None across cases, all three node builders produce validNodeConfigs, and the router instantiatesuv run examples/classifier_routing.py(needsCARTESIA_API_KEY+GOOGLE_API_KEY), then open http://localhost:7860/client. Saying "yes"/"no" routes with no LLM call between turn-end and the reply; asking a question instead falls through to the LLM.🤖 Generated with Claude Code