Specify optional information that would be helpful but not required.
USAGE
Pathways.optional(info_types)
Use to define nice-to-have information that can improve the outcome but isn’t essential for state completion. The LLM will attempt to gather this if the conversation allows. Often used alongside .required() to create comprehensive information gathering states.
Parameters
info_types:Union[str, List[str]]
Additional information that would be beneficial but not essential. Can be a single string or a list of strings.
Returns
Pathways
Self for method chaining, allowing combination with other pathway building methods to create comprehensive conversation flows.
Integration Notes
Flexible Progression: state can progress without optional items
Enhanced Outcomes: helps create more comprehensive outcomes when available
Balanced Flow: use sparingly as too many optionals can slow the flow
State Compatibility: best used in states with type="collect" or structured chat states
Complementary Use: often used alongside .required() to create comprehensive information gathering
Conversation Adaptation: allows gathering helpful information when conversation naturally allows
The .optional() method allows conversations to gather helpful information when available, but doesn’t block progress if users want to move forward quickly.
Examples
Complete pathway showing .optional() enhancing outcomes without blocking progress:
import talk_box as tb# Creating a travel booking pathwaypathway = ( tb.Pathways( title="Flight Booking Assistant", desc="help customers find and book flights", activation="customer wants to book a flight" )# === STATE: travel_basics === .state("travel basics: gather essential travel details") .required(["departure city", "destination city", "preferred travel date"])# .optional() adds helpful details without slowing the process ----- .optional(["return date if roundtrip","preferred departure time window","airline preference or loyalty program" ]) .next_state("search_flights")# === STATE: search_flights === .state("search flights: find matching flights") .required("available flight options found and presented")# .optional() can improve personalization --- .optional("preferred seating section or specific seat requests") .success_condition("customer has reviewed flight options") .next_state("booking")# === STATE: booking === .state("booking: complete the booking") .required(["valid payment information", "complete traveler details for all passengers"])# .optional() for enhanced services --- .optional(["travel insurance coverage options","special meal requests or dietary needs","frequent flyer number for miles credit" ]) .success_condition("booking confirmed"))# See how optional items enhance the pathwayprint(pathway)
**Flight Booking Assistant**
Purpose: help customers find and book flights
Activate when:
- customer wants to book a flight
Flow guidance:
- TRAVEL_BASICS (collect): travel basics: gather essential travel details
Required: (1) departure city, (2) destination city, (3) preferred travel date
Optional: (1) return date if roundtrip, (2) preferred departure time window,
(3) airline preference or loyalty program
- SEARCH_FLIGHTS (collect): search flights: find matching flights
Required: available flight options found and presented
Optional: preferred seating section or specific seat requests
Success: customer has reviewed flight options
- BOOKING (collect): booking: complete the booking
Required: (1) valid payment information, (2) complete traveler details for all passengers
Optional: (1) travel insurance coverage options, (2) special meal requests or dietary needs,
(3) frequent flyer number for miles credit
Success: booking confirmed
Follow as flexible guidance, adapting to user conversation patterns while ensuring key objectives
are addressed.