Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/voice_agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ session = AgentSession(
### Getting Started

- [`basic_agent.py`](./basic_agent.py) - A fundamental voice agent with multilingual STT, turn detection, preemptive generation, and metrics collection
- [`credit_card_collection.py`](./credit_card_collection.py) - Stateful credit-card collection with confirmation

Run the credit-card collection example in console mode:

```bash
uv run examples/voice_agents/credit_card_collection.py console
```

### Real-time Models

Expand Down
50 changes: 50 additions & 0 deletions examples/voice_agents/credit_card_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import logging

from dotenv import load_dotenv

from livekit.agents import Agent, AgentServer, AgentSession, JobContext, cli, inference
from livekit.agents.beta.workflows import GetCreditCardTask

logger = logging.getLogger("credit-card-collection")

load_dotenv()


class CreditCardCollectionAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions=(
"You are a payment assistant. Never repeat, summarize, or expose payment "
"details supplied by the user."
)
)

async def on_enter(self) -> None:
await GetCreditCardTask(require_confirmation=True)

# Keep PCI-sensitive result fields out of logs and follow-up model context.
logger.info("credit-card collection completed")
await self.session.generate_reply(
instructions=(
"Tell the user their payment details were collected successfully. "
"Do not repeat any payment details."
)
)


server = AgentServer()


@server.rtc_session()
async def entrypoint(ctx: JobContext) -> None:
session: AgentSession = AgentSession(
stt=inference.STT("deepgram/nova-3", language="multi"),
llm=inference.LLM("openai/gpt-5.4"),
tts=inference.TTS("cartesia/sonic-3", voice="9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"),
)

await session.start(agent=CreditCardCollectionAgent(), room=ctx.room)


if __name__ == "__main__":
cli.run_app(server)
Loading