import talk_box as tb
= (
pathway
tb.Pathways(="Process Name",
title="clear description of what this pathway accomplishes",
desc="when to use this pathway",
activation="what indicates success",
completion_criteria="how to handle edge cases"
fallback_strategy
)# === STATE: state_name ===
"state name: description of what happens")
.state("essential information needed"])
.required(["helpful but not required info"])
.optional(["How to know this state is complete")
.success_condition("next_state_name")
.next_state(# ...include more states
)
Conversational Pathways
Pathways provide intelligent conversation flow guidance while maintaining the flexibility to adapt to natural conversation patterns. Think of them as guardrails rather than rigid state machines. They help LLMs provide consistent and thorough assistance while remaining responsive to user needs.
What Are Pathways?
A Pathway defines a structured flow through a conversation, breaking complex interactions into clear states with specific objectives. Each state represents a step in achieving the overall goal, with defined information requirements, success conditions, and transition logic.
Some of the key benefits of Pathways are:
- Consistency: ensure important steps aren’t skipped
- Thoroughness: gather all necessary information systematically
- Flexibility: adapt to natural conversation patterns
- Error Recovery: handle unexpected situations gracefully
- Scalability: manage complex multi-step processes
Basic Pathway Structure
Every pathway follows this pattern:
Creating Your First Pathway
Let’s build a customer onboarding pathway step by step:
# Start with pathway setup
= (
onboarding
tb.Pathways(="Customer Onboarding",
title="welcome new customers and set up their accounts",
desc="new customer signs up",
activation="customer is ready to use the platform",
completion_criteria="if customer needs help, provide direct support contact"
fallback_strategy
)
# === STATE: welcome ===
"welcome: welcome customer and collect basic information")
.state(
.required(["customer's full name",
"email address",
"company or organization name"
])"customer feels welcomed and basic info is collected")
.success_condition("setup")
.next_state(
# === STATE: setup ===
"setup: configure account preferences")
.state(
.required(["password created and confirmed",
"notification preferences selected",
"timezone configured"
])"profile photo uploaded", "team member invitations"])
.optional(["Account is fully configured")
.success_condition("tour")
.next_state(
# === STATE: tour ===
"tour: provide guided tour of key features")
.state("main features demonstrated", "first task completed"])
.required(["customer understands how to use core functionality")
.success_condition( )
A flow diagram of the Pathways
object can be viewed in HTML notebooks:
onboarding
Customer Onboarding
welcome new customers and set up their accounts
.visualize()
to save detailed pathway diagrams
And we can view the pathway structure as a formatted prompt fragment via print()
:
print(onboarding)
**Customer Onboarding**
Purpose: welcome new customers and set up their accounts
Activate when:
- new customer signs up
Flow guidance:
- WELCOME (collect): welcome: welcome customer and collect basic information
Required: (1) customer's full name, (2) email address, (3) company or organization name
Success: customer feels welcomed and basic info is collected
- SETUP (collect): setup: configure account preferences
Required: (1) password created and confirmed, (2) notification preferences selected,
(3) timezone configured
Optional: (1) profile photo uploaded, (2) team member invitations
Success: Account is fully configured
- TOUR (collect): tour: provide guided tour of key features
Required: (1) main features demonstrated, (2) first task completed
Success: customer understands how to use core functionality
Complete when: customer is ready to use the platform
Fallback: if customer needs help, provide direct support contact
Follow as flexible guidance, adapting to user conversation patterns while ensuring key objectives
are addressed.
This example demonstrates how pathways create structured yet flexible conversation flows. Notice how each state builds logically on the previous one—we collect basic information first, then configure account preferences, and finally provide training. This progressive approach helps users feel guided through what could otherwise be an overwhelming process.
The pathway uses clear, specific requirements at each step (like "password created and confirmed"
rather than just "password"
), which helps the AI understand exactly what to accomplish. Optional items in the setup state show how pathways can accommodate different user needs while maintaining the core flow structure.
State Types and Inference
Pathways automatically infer both state types and IDs based on the methods you use and the shorthand syntax:
- State Types: Inferred from method usage (
.required()
→"collect"
,.branch_on()
→"decision"
,.tools()
→"tool"
) - State IDs: Extracted from
"id: description"
format, with automatic normalization (spaces → underscores) - State Blocks: Method calls between
.state()
definitions belong to the previous state, creating natural configuration blocks
Collection States (type="collect"
)
Automatically inferred when using .required()
or .optional()
:
"requirements: gather project requirements")
.state("project goals", "timeline", "budget range"])
.required(["preferred technologies", "team size"]) .optional([
Collection states are perfect for systematic information gathering. When you specify what information is required or optional, the AI knows to ask questions and collect responses before moving forward.
Decision States (type="decision"
)
Automatically inferred when using .branch_on()
:
"triage: determine support type needed")
.state("technical issue reported", id="tech_support")
.branch_on("billing question asked", id="billing")
.branch_on("general inquiry", id="general_help") .branch_on(
Decision states create conditional pathways based on user responses or circumstances. The AI evaluates which branch condition matches the situation and routes the conversation accordingly.
Tool States (type="tool"
)
Automatically inferred when using .tools()
:
"diagnostics: analyze system performance")
.state("system_monitor", "log_analyzer", "performance_profiler"])
.tools(["performance issues identified") .success_condition(
Tool states enable external capabilities and automated processes. When you specify tools, the AI understands it needs to use those resources to accomplish the state’s objectives.
Chat States (type="chat"
)
The default for open conversation, explanations, and guidance:
"explanation: explain the recommended solution")
.state("customer understands the approach") .success_condition(
Chat states handle open-ended conversation, explanations, and guidance where no specific tools or branching logic are needed. This is the default state type when you don’t use collection, decision, or tool methods.
Branching and Decision Logic
Use .branch_on()
to create conditional flows:
= (
support_pathway
tb.Pathways(="Customer Support Triage",
title="route customers to appropriate support channels",
desc="customer needs assistance"
activation
)
# === STATE: assessment ===
"assessment: assess customer needs")
.state("issue description", "urgency level", "customer type"])
.required(["triage")
.next_state(
# === STATE: triage ===
"triage: route to appropriate support")
.state(
# Perform branching -----
"critical system outage", id="emergency")
.branch_on("technical issue needing expert help", id="technical")
.branch_on("billing or account question", id="billing")
.branch_on("general question or guidance needed", id="general")
.branch_on(
# === STATE: emergency ===
"emergency: handle critical emergency")
.state("incident escalated", "immediate response initiated"])
.required(["emergency team engaged")
.success_condition("follow_up")
.next_state(
# === STATE: technical ===
"technical: provide technical support")
.state("diagnostic_tools", "knowledge_base", "screen_sharing"])
.tools(["technical issue resolved or escalated appropriately")
.success_condition("follow_up")
.next_state(
# === STATE: follow_up ===
"follow up: ensure customer satisfaction")
.state("resolution confirmed", "satisfaction rating collected"])
.required(["customer issue fully resolved")
.success_condition(
)
support_pathway
Customer Support Triage
route customers to appropriate support channels
.visualize()
to save detailed pathway diagrams
Branching logic enables pathways to handle diverse user scenarios while maintaining a structured approach. By defining conditions for each branch, you can create intelligent routing that adapts conversations to specific user needs while also ensuring consistent outcomes.
Error Handling with Fallbacks
Use .fallback()
to handle situations where normal flow doesn’t work:
import talk_box as tb
= (
problem_solving_pathway
tb.Pathways(="Technical Problem Resolution",
title="systematically resolve technical issues",
desc="user reports technical problem"
activation
)
# === STATE: analysis ===
"analysis: analyze the reported problem")
.state("problem details", "error messages", "system context"])
.required(["problem is clearly understood")
.success_condition("standard_solution")
.next_state(
# === STATE: standard_solution ===
"standard solution: apply standard troubleshooting steps")
.state("troubleshooting steps completed", "results documented"])
.required(["problem is resolved")
.success_condition("standard solution doesn't work", "advanced_diagnostics")
.fallback("completion") # Normal success path
.next_state(
# === STATE: advanced_diagnostics ===
"advanced diagnostics: perform detailed system analysis")
.state("system_diagnostics", "log_analyzer", "network_tracer"])
.tools(["root cause identified and resolved")
.success_condition("issue remains unresolved", "escalation")
.fallback("completion") # Success after advanced diagnostics
.next_state(
# === STATE: escalation ===
"escalation: escalate to specialist support")
.state("detailed case summary", "specialist contacted"])
.required(["case transferred successfully")
.success_condition("completion") # All paths converge here
.next_state(
# === STATE: completion ===
"completion: document resolution and close case")
.state("resolution documented", "customer notified"])
.required(["case fully resolved and documented")
.success_condition(
)
problem_solving_pathway
Technical Problem Resolution
systematically resolve technical issues
.visualize()
to save detailed pathway diagrams
This fallback pattern is essential for creating robust pathways that gracefully handle real-world complexity. By defining clear escalation paths, you ensure that conversations never reach dead ends, maintaining user confidence even when standard approaches fail.
Using Pathways with ChatBot
Once you’ve designed a pathway, you’ll want to integrate it with a ChatBot
to enable structured conversations in practice. Pathways work seamlessly with the ChatBot
class through the PromptBuilder
system, automatically providing the AI model with clear guidance about conversation flow, state transitions, and information requirements.
# Create your pathway
= (
support_pathway
tb.Pathways(="Customer Support",
title="comprehensive customer assistance",
desc="Customer needs help",
activation
)# === STATE: intake ===
"intake: understand customer needs")
.state("problem description", "contact information"])
.required(["resolution")
.next_state(# === STATE: resolution ===
"resolution: provide solution")
.state("customer problem is resolved")
.success_condition(
)
# Use with ChatBot via PromptBuilder
= (
bot
tb.ChatBot()"gpt-4")
.model(
.system_prompt(
tb.PromptBuilder()"helpful customer support agent")
.persona(
.pathways(support_pathway)
)
)
bot
🤖 Talk Box ChatBot 🟢 LLM Ready
📊 Configuration
⚙️ Advanced Settings
📝 System Prompt (514 characters)
Now configured with the Pathways directives, the bot will now follow the structure you defined.
= bot.chat("I'm having trouble with my account") response
Best Practices
1. Clear State Descriptions
# Good: Specific and actionable
"shipping: collect shipping address and delivery preferences")
.state(
# Avoid: Vague or unclear
"info: get info") .state(
Clear, descriptive state names help both AI models and human developers understand the purpose and scope of each step. When state descriptions are specific, the AI can better guide conversations toward the intended outcomes and provide appropriate responses to user questions.
2. Specific Information Requirements
# Good: Concrete and measurable
.required(["complete shipping address with postal code",
"preferred delivery time window",
"special delivery instructions if any"
])
# Avoid: Generic or ambiguous
"address", "preferences"]) .required([
Detailed requirement specifications ensure the AI knows exactly what information to gather and how to validate completeness. This reduces back-and-forth exchanges and helps users provide the right level of detail from the start.
3. Observable Success Conditions
# Good: Clear completion criteria
"customer confirms shipping details are correct")
.success_condition(
# Avoid: Internal or unclear
"data is valid") .success_condition(
Success conditions should describe observable user behaviors or confirmations rather than internal system states. This helps the AI recognize when to move forward and gives users clear expectations about what constitutes completion.
4. Meaningful State Names
# Good: Descriptive and unique
"order confirmation: review order details and confirm purchase")
.state(
# Avoid: Generic or confusing
"process: process order") .state(
State IDs serve as navigation waypoints and debugging references throughout your pathway logic. Descriptive names make it easier to understand pathway flow, troubleshoot issues, and maintain complex conversation structures over time.
5. Logical Information Flow
# Good: Progressive information gathering
# === STATE: contact ===
"contact: collect basic contact info")
.state("name", "email"])
.required(["detailed_requirements")
.next_state(# === STATE: detailed_requirements ===
"detailed requirements: gather detailed project requirements")
.state("project scope", "timeline", "budget"]) .required([
Structure your pathway states to build naturally from simple to complex information gathering. This progressive approach feels more conversational and prevents users from feeling overwhelmed by too many questions at once.
Advanced Patterns
Once you’re comfortable with basic pathway construction, these advanced patterns help you handle more sophisticated conversation flows. These techniques are particularly useful for complex business processes, multi-step workflows, and scenarios where different user paths need to converge or diverge based on specific conditions.
Multi-Path Convergence
Different branches can reconverge to common states:
import talk_box as tb
= (
multi_branch_pathway ="Multi-path Process", desc="...")
tb.Pathways(title"assessment: initial assessment")
.state("path A condition", id="path_a")
.branch_on("path B condition", id="path_b")
.branch_on(# === STATE: path_a ===
"path a: handle path A")
.state("path A requirements"])
.required(["completion") # Converge here
.next_state(# === STATE: path_b ===
"path b: handle path B")
.state("path B requirements"])
.required(["completion") # Converge here
.next_state(# === STATE: completion ===
"completion: complete process")
.state("all paths lead to successful completion")
.success_condition(
)
multi_branch_pathway
Multi-path Process
...
.visualize()
to save detailed pathway diagrams
This pattern demonstrates how different conversation branches can merge back into a common endpoint. The power of convergence lies in its ability to handle diverse user needs or circumstances while ensuring all paths lead to the same comprehensive completion state. For example, a customer service pathway might branch into technical support, billing assistance, or general inquiries, but all branches eventually converge at a customer satisfaction check and case closure state. This approach maintains consistency in final outcomes while allowing flexibility in the journey to get there.
Progressive Disclosure
Progressive disclosure is a design principle that presents information and options incrementally, starting with the most essential elements and gradually revealing more advanced features as users demonstrate readiness or express specific needs. This approach prevents cognitive overload while ensuring power users can access sophisticated capabilities when required.
In pathway design, progressive disclosure helps you create conversation flows that feel natural and approachable to beginners while providing depth for experienced users. Instead of overwhelming users with all possible options upfront, you guide them through a logical progression from basic to advanced configurations.
= (
complex_pathway
tb.Pathways(="System Configuration",
title="Progressive disclosure pathway"
desc
)"basic: basic setup")
.state("essential settings configured"])
.required(["intermediate")
.next_state(# === STATE: intemediate ===
"intermediate: intermediate configuration")
.state("advanced options reviewed"])
.required(["performance tuning preferences"])
.optional(["user wants advanced setup", id="advanced")
.branch_on("completion") # Skip advanced if not needed
.next_state(# === STATE: advanced ===
"advanced: advanced configuration")
.state("expert settings configured"])
.required(["completion")
.next_state(# === STATE: completion ===
"completion: finalize setup")
.state("System is fully configured and tested")
.success_condition( )
This example demonstrates the progressive disclosure pattern in action: starting with basic setup that everyone needs, moving to intermediate configuration with optional customizations, and only branching to advanced features when users explicitly request them.
Pathway Visualization
For complex pathways, visual flow diagrams can help you understand and validate the conversation structure:
# Create and open an HTML flowchart visualization
complex_pathway.visualize()
# Or save to a specific file without opening
complex_pathway.visualize(="System Configuration Flow",
title="pathway_diagram.html",
filename=False
auto_open )
The .visualize()
method creates interactive flowcharts with:
- visual flow structure showing states and transitions
- color-coded state types for quick identification
- reconvergence detection highlighting where paths merge
- final state indicators with special styling
- undefined state warnings for missing referenced states
Generated HTML visualizations are saved to the pathway_visualizations/
directory by default, making it easy to share diagrams or archive them for documentation.
This is especially useful for:
- validating pathway logic before implementation
- debugging complex branching and reconvergence scenarios
- sharing pathway designs with team members
- documenting conversation flows for reference
Summary
Pathways provide a powerful way to structure complex conversations while maintaining natural flexibility. A typical pathway development cycle looks like this:
# 1. Build your pathway
= tb.Pathways(title="My Process", desc="...").state("...")
my_pathway
# 2. Check the structure in your notebook
# HTML display shows overview
my_pathway
# 3. Review the prompt format
print(my_pathway) # See exactly what the AI will receive
# 4. Integrate with ChatBot
= tb.ChatBot().pathways(my_pathway) bot
Some key takeaways:
- start with clear pathway objectives and success criteria
- use descriptive state names and specific information requirements
- let type inference work for you—it reduces boilerplate
- handle edge cases with the
.fallback()
method - inspect pathways with
print()
and use visualization for complex flows - keep states focused and break complex processes into multiple branches if needed
With Pathways, you can create sophisticated conversation flows that guide users efficiently while adapting to their natural communication patterns.