import talk_box as tb
= (
simple_pathway
tb.Pathways(="Password Reset",
title="Help users reset their forgotten passwords",
desc=["User can't log in", "User forgot password"],
activation="User successfully logs in with new password",
completion_criteria="If user lacks access to recovery methods, escalate to manual verification"
fallback_strategy
)# === STATE: verification ===
"verification: verify user identity")
.state("email address", "account verification"])
.required(["password_update")
.next_state(# === STATE: password_update ===
"password update: guide user through creating new password")
.state("new password is created", "password requirements are met"])
.required(["User successfully logs in with new password")
.success_condition( )
Pathwaysclass
Chainable builder for defining structured conversational pathways.
USAGE
Pathways(
title,='',
desc=None,
activation=None,
completion_criteria=None,
fallback_strategy )
The Pathways
class provides intelligent conversation flow guidance while maintaining flexibility to adapt to natural conversation patterns. They serve as guardrails rather than rigid state machines, helping LLMs provide consistent and thorough assistance while remaining responsive to user needs and conversational context.
Parameters
title : str
-
A short, descriptive name for the pathway.
desc : str = ''
-
Clear, concise explanation of the pathway’s purpose and scope.
activation : Union[str, List[str], None] = None
-
Specific situations or user intents that trigger pathway activation. Can be a single string or a list of strings.
completion_criteria : Union[str, List[str], None] = None
-
High-level conditions that indicate the pathway’s objectives have been fully achieved. Can be a single string or a list of strings. Optional.
fallback_strategy : str = None
-
General approach for handling situations where the pathway doesn’t apply or users need different support. Optional.
Returns
Pathways
-
The configured
Pathways
object for further chaining with.state()
and other methods.
Building Pathways
Building a pathway follows a specific sequence that ensures proper configuration and flow logic. Each step builds upon the previous one to create a coherent conversation structure.
1. Pathway Setup (call once, in order)
= (
pathway
tb.Pathways(="Title",
title="Purpose and scope", # What this pathway does
desc=[...], # When to use this pathway
activation=[...], # What makes pathway successful
completion_criteria="..." # Handle unexpected situations
fallback_strategy
)# First .state() call automatically becomes the starting state
2. State Definition
= (
pathway
tb.Pathways(="Support Flow",
title="Customer support pathway",
desc="User needs help"
activation
)# === STATE: intake ===
"intake: gather customer information")
.state("issue description", "contact info"])
.required(["triage")
.next_state(# === STATE: triage ===
"triage: route to appropriate support")
.state("Technical issue", id="tech_support")
.branch_on("Billing question", id="billing")
.branch_on(# === STATE: tech_support ===
"tech support: resolve technical problems")
.state("Issue resolved")
.success_condition( )
This approach provides:
- visual state boundaries with
# === STATE: description ===
comments - natural state definition with shorthand syntax:
.state("id: what happens here")
- smart type inference where
.tools()
→"tool"
,.branch_on()
→"decision"
,.required()
→"collect"
- automatic start state where the first
.state()
becomes the starting state
3. State Configuration Pattern (repeat for each state):
# Define the state with description first
"What happens in this state", id="state_name")
.state("info: collect required information") # inferred as "collect", id="info"
.state("make decision: evaluate options and choose") # "make decision" → id="make_decision"
.state("use tools: apply specific capabilities") # type inferred as "tool" from .tools()
.state("final summary: provide conclusion", type="summary") # explicit type with shorthand syntax
.state("Wrap up") # Linear states don't really need IDs
.state(
# Configure the state
# What must be accomplished
.required([...]) # What would be nice to have
.optional([...]) # Available tools (infers type="tool")
.tools([...]) "When state succeeds") # How to know it's complete
.success_condition(
# Define state transitions (choose one)
"next_state") # Linear progression
.next_state("condition", id="target_state") # Conditional (infers type="decision")
.branch_on("common_state") # Reconverge after branching
.next_state("error_condition", "backup_state") # Error handling .fallback(
State Types and Their Purpose
Each state type serves a specific role in the conversation flow:
type="chat"
: open conversation, explanations, guidance (default)type="decision"
: branching logic, must usebranch_on()
notnext_state()
type="collect"
: structured information gatheringtype="tool"
: using specific tools or APIs, requirestools()
type="summary"
: conclusions, confirmations, completion actions
Key Rules
- description is required and provided in
.state()
method - if you use
type="decision"
, you must usebranch_on()
and nevernext_state()
type="tool"
must include atools()
specification- state names must be unique and use
"lowercase_with_underscores"
- target states in transitions must be defined later with another
.state()
Examples
The following examples demonstrate common pathway patterns that address different conversation needs. The first shows a simple linear flow where states progress sequentially—ideal for straightforward processes. The second illustrates branching logic that routes users down different paths before converging to a common endpoint—perfect for triage and support scenarios.
Simple Linear Flow
This password reset pathway demonstrates the basic pattern: setup the pathway, define states sequentially, and specify what information each state needs to collect. Notice how each state builds naturally toward the goal of helping the user regain access to their account.
This linear flow moves step-by-step from identity verification to password creation. Each state has clear requirements and success conditions, making the pathway easy to follow and validate.
Branching Flow with Decision Points
This customer support pathway demonstrates decision state branching using the unified .state()
method. Notice how different support paths merge back to a common completion state, ensuring consistent wrap-up regardless of the support type provided.
= (
support_pathway
tb.Pathways(="Customer Support",
title="route and resolve customer inquiries",
desc=["user needs help", "user reports problem"],
activation=["customer issue fully resolved", "customer satisfied"],
completion_criteria="if issue is complex, escalate to human support"
fallback_strategy
)# === STATE: triage ===
"triage: determine the type of support needed")
.state("Technical problem reported", id="technical_support")
.branch_on("Billing question asked", id="billing_support")
.branch_on("General inquiry made", id="general_help")
.branch_on(# === STATE: technical_support ===
"technical support: diagnose and resolve technical issues")
.state("system_diagnostics", "troubleshooting_guide"])
.tools(["Technical issue is resolved")
.success_condition("completion")
.next_state(# === STATE: billing_support ===
"billing support: address billing and account questions")
.state("billing issue is understood", "solution is provided"])
.required(["completion")
.next_state(# === STATE: completion ===
"completion: ensure customer satisfaction and wrap up", type="summary")
.state("issue resolved confirmation", "follow up if needed"])
.required(["Customer satisfaction confirmed")
.success_condition( )
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/talk_box/pathways.py:545: UserWarning: State 'completion' was explicitly set to 'summary' but method suggests 'collect'. Keeping explicit type 'summary'.
warnings.warn(
This branching example shows how .state()
creates clear decision points that route conversations appropriately, then merge back together for consistent completion.
Inspecting Pathways
Once you’ve built a pathway, you can inspect it using different string representations:
import talk_box as tb
# Create a simple pathway
= (
pathway
tb.Pathways(="Quick Help",
title="Provide rapid assistance",
desc="User needs help",
activation="User's problem is resolved",
completion_criteria="If problem is complex, escalate to specialized support"
fallback_strategy
)# === STATE: problem_intake ===
"problem intake: understand the issue details")
.state("issue description"])
.required(["provide_solution")
.next_state(# === STATE: provide_solution ===
"provide solution: offer targeted assistance")
.state("User's problem is resolved")
.success_condition( )
We can view the pathway in two ways, either as a brief summary by examining the object itself:
pathway
Quick Help
Provide rapid assistance
.visualize()
to save detailed pathway diagrams
Or with print()
for a more detailed view:
print(pathway)
**Quick Help**
Purpose: Provide rapid assistance
Activate when:
- User needs help
Flow guidance:
- PROBLEM_INTAKE (collect): problem intake: understand the issue details
Required: issue description
- PROVIDE_SOLUTION (summary): provide solution: offer targeted assistance
Success: User's problem is resolved
Complete when: User's problem is resolved
Fallback: If problem is complex, escalate to specialized support
Follow as flexible guidance, adapting to user conversation patterns while ensuring key objectives
are addressed.
The summary view gives you a quick overview, while the detailed view shows the state types, description, and other configuration details. This is especially useful when debugging complex pathways or understanding existing pathway configurations.