Overview
Use GetCreditCardTask to collect complete credit card information from the user. This is a composite task that runs a TaskGroup internally to collect the cardholder name, card number, security code, and expiration date in sequence.
GetCreditCardTask handles the following:
- Sequential collection of cardholder name, card number, security code, and expiration date using a task group.
- Card number format validation.
- Card issuer detection (Visa, Mastercard, American Express, Discover).
- Expiration date validation to reject expired cards.
- Built-in restart flow if the user wants to provide a different card.
- Sensitive information is never repeated back to the user during audio sessions.
The task returns a GetCreditCardResult data class with five fields: cardholder_name, issuer, card_number, security_code, and expiration_date.
Usage
The following example uses GetCreditCardTask to collect payment information:
from livekit.agents.beta.workflows import GetCreditCardTaskfrom livekit.agents import function_tool, RunContext@function_tool()async def collect_payment(context: RunContext) -> str:"""Collect payment card information from the user"""card_result = await GetCreditCardTask(chat_ctx=context.session.chat_ctx,)last_four = card_result.card_number[-4:]return f"Payment recorded: {card_result.issuer} ending in {last_four}"
Sub-tasks
GetCreditCardTask internally runs a TaskGroup with the following sub-tasks in order:
GetNameTask: Collects the cardholder's full name (first and last).GetCardNumberTask: Collects and validates the card number format.GetSecurityCodeTask: Collects the 3 or 4 digit security code (CVV/CVC).GetExpirationDateTask: Collects and validates the expiration date.
Each sub-task includes a restart_card_collection tool that allows the user to start over from the beginning if needed.
Parameters
For a full list of parameters, see the GetCreditCardTask reference.
chat_ctxChatContextThe conversation history the task-specific LLM sees. If you omit it, the task runs with an empty context, with no memory of what was said earlier in the session. Pass the primary agent's chat context so the task can refer to prior turns and, when used inside a task group, so exchanges are summarized back into the main context.
require_confirmationboolWhether to confirm each piece of card information with the user before finalizing. For audio sessions this defaults to True, for text it defaults to False. This setting propagates to all sub-tasks.
toolslistAdditional tools available to the task. Use this to add or substitute function tools.