# Check every call from a LiveKit voice agent with one function

> A walkthrough of connecting a LiveKit agent to sopops with attach(): serve its instructions at call start and send every finished call back to be checked.

By sopops team. Published 2026-10-31. Source: https://sopops.dev/blog/check-every-call-from-a-livekit-agent

Tags: tutorials, LiveKit, SDK

**Short answer:** Install the sopops Python SDK with the LiveKit extra, set SOPOPS_URL and SOPOPS_TOKEN, and call attach(ctx, session) after ctx.connect(). attach fetches the agent's instructions, notes the release, and posts the finished call to sopops when the session shuts down.

This walks through connecting a LiveKit Agents voice agent to sopops in Python. When you're done, the agent gets its instructions from sopops when each call starts, and every finished call comes back to be checked against its procedures.

## Install the SDK

```bash
pip install "sopops[livekit]"
```

## Set two variables

Wherever the agent runs, set:

- `SOPOPS_URL`: your workspace's API URL.
- `SOPOPS_TOKEN`: a workspace token with both the `runtime` scope (to fetch instructions) and the `ingest` scope (to send calls). Create it under Settings → Access.

On LiveKit Cloud, add both as the agent's secrets and deploy again. The SDK can't reach sopops without them.

## Call attach

In your agent's entrypoint, call `attach` after `ctx.connect()` and use the text it returns as the agent's instructions:

```python
from livekit.agents import Agent, AgentSession
from sopops.livekit import attach

FALLBACK = "You are the scheduling assistant for a clinic. Verify the caller before discussing any appointment."

async def entrypoint(ctx):
    await ctx.connect()
    session = AgentSession(...)  # your STT, LLM and TTS, as before
    ins = await attach(ctx, session, fallback=FALLBACK)
    await session.start(agent=Agent(instructions=ins.text), room=ctx.room)
```

`attach` does three things:

1. Fetches the agent's live release from sopops. By default it identifies the agent by the job's agent name.
2. Notes the release and agent in the session's user data, so the call is tied to the exact instructions it ran.
3. Registers a shutdown callback that posts the finished call to sopops, with its transcript and tool calls.

If sopops doesn't answer in time, `attach` uses the last good copy it cached on disk, or your fallback text if there's nothing cached. Each result says where the text came from, which is worth logging.

## Read the results

Open Sessions in sopops. Each call shows its transcript, its tool calls, and a result for each procedure that applied: followed, partly followed, deviated, or not measurable. The parts of the transcript that show each result are highlighted.

When the same miss shows up on several calls, it becomes a pattern under Review. Give it a verdict, and for a real mistake sopops drafts the fix to the agent's instructions.

## Optional: stream the call as it happens

Pass `stream=True` to also send each turn and tool call while the call runs, instead of only at the end:

```python
ins = await attach(ctx, session, fallback=FALLBACK, stream=True)
```

The full docs cover pinning a release for an A/B test, filling placeholders per call, and the TypeScript version. [Read the docs →](/docs/connect)

## Questions

### What happens if sopops is down when a call starts?

The call still starts. The SDK uses the last good copy of the instructions it cached, or the fallback text you pass, if nothing is cached yet.

### Can I check calls without serving instructions from sopops?

Yes. On LiveKit you can capture calls with no code, using a project key and a webhook, or use record_session to post calls from an agent that gets its instructions some other way.

### Is there a TypeScript version?

Yes. The sopops npm package has the same attach function in sopops/livekit.
