Module livekit.agents.beta.workflows.utils

Functions

def dtmf_event_to_code(event: DtmfEvent) ‑> int
Expand source code
def dtmf_event_to_code(event: DtmfEvent) -> int:
    if event.value.isdigit():
        return int(event.value)
    elif event.value == "*":
        return 10
    elif event.value == "#":
        return 11
    elif event.value in ["A", "B", "C", "D"]:
        # DTMF codes 10-15 are used for letters A-D
        return ord(event.value) - ord("A") + 12
    else:
        raise ValueError(f"Invalid DTMF event: {event}")
def format_dtmf(events: list[DtmfEvent]) ‑> str
Expand source code
def format_dtmf(events: list[DtmfEvent]) -> str:
    return " ".join(event.value for event in events)

Classes

class DtmfEvent (*args, **kwds)
Expand source code
class DtmfEvent(str, Enum):
    ONE = "1"
    TWO = "2"
    THREE = "3"
    FOUR = "4"
    FIVE = "5"
    SIX = "6"
    SEVEN = "7"
    EIGHT = "8"
    NINE = "9"
    ZERO = "0"
    STAR = "*"
    POUND = "#"
    A = "A"
    B = "B"
    C = "C"
    D = "D"

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

Ancestors

  • builtins.str
  • enum.Enum

Class variables

var A
var B
var C
var D
var EIGHT
var FIVE
var FOUR
var NINE
var ONE
var POUND
var SEVEN
var SIX
var STAR
var THREE
var TWO
var ZERO
class WorkflowInstructions (audio: str = '',
*,
text: str | None = None,
persona: NotGivenOr[Instructions | str] = NOT_GIVEN,
extra: Instructions | str = '')
Expand source code
class WorkflowInstructions(Instructions):
    """Customizable instruction sections for built-in workflow tasks.

    Extends :class:`Instructions` with ``persona`` and ``extra`` fields
    that workflow tasks resolve against their own templates and defaults.

    Each field overrides that section when set; leave as ``NOT_GIVEN`` to
    preserve the workflow's built-in default. Set to ``""`` to remove a
    section entirely.
    """

    def __init__(
        self,
        audio: str = "",
        *,
        text: str | None = None,
        persona: NotGivenOr[Instructions | str] = NOT_GIVEN,
        extra: Instructions | str = "",
    ) -> None:
        super().__init__(audio=audio, text=text)
        self.persona: NotGivenOr[Instructions | str] = persona
        self.extra: Instructions | str = extra

    def resolve(
        self,
        *,
        template: str,
        default_persona: str,
        **format_kwargs: Any,
    ) -> Instructions:
        """Resolve into a final :class:`Instructions` by formatting the template."""
        return Instructions.resolve_template(
            template,
            persona=self.persona if is_given(self.persona) else default_persona,
            extra=self.extra,
            **format_kwargs,
        )

Customizable instruction sections for built-in workflow tasks.

Extends :class:Instructions with persona and extra fields that workflow tasks resolve against their own templates and defaults.

Each field overrides that section when set; leave as NOT_GIVEN to preserve the workflow's built-in default. Set to "" to remove a section entirely.

Ancestors

  • livekit.agents.llm.chat_context.Instructions

Methods

def resolve(self, *, template: str, default_persona: str, **format_kwargs: Any) ‑> livekit.agents.llm.chat_context.Instructions
Expand source code
def resolve(
    self,
    *,
    template: str,
    default_persona: str,
    **format_kwargs: Any,
) -> Instructions:
    """Resolve into a final :class:`Instructions` by formatting the template."""
    return Instructions.resolve_template(
        template,
        persona=self.persona if is_given(self.persona) else default_persona,
        extra=self.extra,
        **format_kwargs,
    )

Resolve into a final :class:Instructions by formatting the template.