Pathways.optional()

Specify optional information that would be helpful but not required.

Usage

Source

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 pathway
pathway = (
    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 pathway
print(pathway)