> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reactor.inc/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> To build and serve your own model, start at /deploy/development/quickstart and /deploy/development/overview. Authenticate with reactor auth login, scaffold with reactor init, then run reactor deploy production from the workspace. Deploy builds remotely by default, creates a missing workspace project and its production environment, and waits for rollout. No local Docker or model.version bump is needed. Projects own images and weight sets; environments select the image, weights, GPU, instance count, and variables. Create staging explicitly with reactor environment create staging before deploying to it. Use reactor scale for capacity and reactor rollback for an earlier revision’s image and weights. See /deploy/platform/projects and /deploy/platform/deploy. Client SDK modelName remains account-qualified and selects production by default. Model code imports reactor_runtime; Python client code imports reactor_sdk. Local testing is optional; /deploy/development/local-testing covers reactor run, which needs Docker.
> Reactor hosts multiple models, each with its own connect slug (modelName) and command/event schema. The video model catalog — slug, typed SDK package, and links to its schema — is at /model-api-reference/overview. Robotics policy documentation starts at /robotics/overview; The launch policies are Cosmos Nano DROID (/robotics/cosmos/nano-policy-droid/), DreamZero DROID (/robotics/dreamzero/droid/), and FLUX Action DROID (/robotics/flux-action/droid/), organized by model family and embodiment. Some models expose one slug per experience (e.g. HappyOyster); always take the slug from the model's own pages, never guess it.
> Fastest path to a working app: `npx create-reactor-app my-app --model=<slug>` scaffolds a complete app with secure auth wired up. Typed TypeScript SDKs are published as @reactor-models/<model>; Python uses the base reactor-sdk package.
> Auth: exchange an API key (rk_...) for a JWT via POST https://api.reactor.inc/tokens from your server. Never put the API key in client-side code.
> Append .md to any docs URL for clean Markdown. Search these docs via the MCP server at https://docs.reactor.inc/mcp.

# Talking avatar model walkthrough

> The files, contract, loading, and render loop of the AURA talking avatar model on Reactor Runtime.

The talking avatar serves AURA as a face that joins a LiveKit room. Its source is
[`examples/talking-avatar/aura-model`](https://github.com/reactor-team/reactor-cookbook/tree/main/examples/talking-avatar/aura-model)
in the Reactor cookbook, and the code below is simplified from it.

## Files

```text aura-model/ highlight={4-7} theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
aura-model/
├── reactor.yaml
├── config.yml
├── avatar_app.py         # Avatar app: the room protocol and the render loop
├── avatar_contract.py    # What the app and the model exchange
├── aura_app.py           # AURA: builds the model for the app
├── aura_model.py         # The model: renders 1 chunk per call
├── aura_assets.py
├── prepare_weights.py
├── portrait.jpg
└── tests/
```

The runtime drives `AuraAvatar`, the model class. Most of its code is in `AvatarApp`, which it subclasses: the room
protocol and the render loop, for any model that renders a chunk of video from a chunk of speech. `AuraAvatar` only
builds that model, `AuraModel`, which runs AURA's own code and imports nothing from Reactor.
[Model Structure](https://docs.reactor.inc/deploy/development/reactor-app/application-and-model.md) describes this split.

## Contract

The contract declares the tracks and the messages that the room sees:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarMedia(MediaInput):
    agent_audio: AgentAudio      # The agent's speech, 24 kHz mono


class AvatarOutput(Output):
    main_video: Video
    main_audio: AvatarAudio      # The speech that plays with the frames, 24 kHz


class PlaybackStarted(ModelMessage):
    pass


class PlaybackFinished(ModelMessage):
    playback_position: float = MessageField()
    interrupted: bool = MessageField()


class AvatarFailed(ModelMessage):
    reason: str = MessageField()
```

* **Tracks:** `agent_audio` takes the agent's speech in. `main_video` and `main_audio` send the avatar out.
* **Messages:** `playback_started` and `playback_finished` tell the agent what played. `avatar_failed` tells the
  client that the model failed during the session.

The app also declares 3 commands with `@event`: `set_avatar`, `clear_buffer`, and `user_speaking_state`.

### How the room reaches the model

In the room, the avatar uses LiveKit's avatar protocol. Each signal of that protocol maps to a track, a command, or a
message of the model:

![From the agent: byte streams on lk.audio\_stream feed the agent\_audio input track. The lk.clear\_buffer RPC runs the clear\_buffer command. Data packets on avatar.user\_speaking\_state run the user\_speaking\_state command. Back to the room: the main\_video and main\_audio output tracks are published as the avatar's video and audio. The playback\_started and playback\_finished messages go back to the agent as the lk.playback\_started and lk.playback\_finished RPCs.](https://mintcdn.com/reactortechnologiesinc/AFS5VXMUwc0tUo4V/diagrams/talking-avatar-mapping.svg?fit=max\&auto=format\&n=AFS5VXMUwc0tUo4V\&q=85\&s=c2389fdfc0b4b866cdd864c214ae4306)

The `runtime.livekit` block in `reactor.yaml` declares this mapping. The output tracks need no entry, because the
runtime publishes them to the room:

```yaml reactor.yaml (the livekit block) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
runtime:
  livekit:
    rpc:
      - method: lk.clear_buffer
        command: clear_buffer
      - method: lk.playback_finished
        message: playback_finished
      - method: lk.playback_started
        message: playback_started
    topics: [avatar]
    media_inputs:
      lk.audio_stream: agent_audio
```

`set_avatar` is not mapped to the room. The portrait arrives in the starting input of the session. The
[`runtime.livekit` reference](https://docs.reactor.inc/deploy/platform/reactor-yaml#runtime-livekit) explains each key.

### Between the app and the model

The app and the model exchange 2 dataclasses, and the model implements 2 methods:

```python avatar_contract.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
@dataclass(frozen=True)
class AvatarInput:
    audio: np.ndarray        # 1.0 s of speech, or silence
    silent: bool
    listening: bool
    avatar: bytes | None     # The portrait, only when the model does not hold it
    avatar_id: int


@dataclass(frozen=True)
class AvatarResult:
    frames: np.ndarray       # Up to 16 frames


class AvatarModel(Protocol):
    def generate(self, input: AvatarInput) -> AvatarResult: ...
    def reset(self) -> None: ...
```

Another avatar model can use the same app: it implements `AvatarModel`. The example's second model, LiveAvatar in
`liveavatar-model/`, does exactly that, with the same `avatar_app.py` and `avatar_contract.py`.

## Loading

The runtime calls `load()` once, when the instance starts and before any session. `AvatarApp.load()` reads
`config.yml` and calls `create_model()`, which `AuraAvatar` implements:

```python aura_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AuraAvatar(AvatarApp):
    fps = 16

    def create_model(self, config, config_dir):
        model = AuraModel()
        model.load(weights, prompt=config["prompt"], warmup_blocks=config["warmup_blocks"])
        return model, default_portrait
```

`AuraModel.load()` builds AURA's pipeline from the weights folder, the way AURA builds it from Hugging Face, so the
model never reads the network. It then compiles the transformer and renders 6 warmup chunks, so the first call runs at
full speed. `create_model()` also returns a default portrait, which a session uses until `set_avatar` replaces it.

## The render loop

Most models leave the loop to the runtime and write the three step hooks. This app writes its own `run()` instead. The
render runs on a worker thread, so commands and speech keep arriving while a chunk renders:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    async def run(self):
        while True:
            await self.connected.wait()         # A client is connected
            plan = await self.next_plan()       # A chunk of speech, or an idle chunk
            result = await self.render(plan)    # generate() on the worker thread
            await self.send_block(plan, result) # The frames with their audio
```

### Plan a chunk

The agent's speech arrives on `agent_audio` faster than it plays, as one byte stream per utterance. A background task
collects it into utterances. The next chunk carries 1.0 second of one utterance as soon as that much is in, or the
last, shorter part when the utterance ends. With no speech, the next chunk is idle:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    def plan(self):
        utterance = self.session.next_speech()
        if utterance is not None and utterance.has_block():
            return self.speech_block(utterance.take(self.block_samples))
        return self.idle_block()
```

Speech renders at most 2 seconds ahead of what plays (`speech_lead_s` in `config.yml`). That is enough to keep the next
chunk ready, and an interrupt drops little rendered speech.

### Render the chunk

`render()` calls `generate()` on the model, on the worker thread. When the model does not hold the portrait, it starts
a new clip from it. Then it renders the chunk from its speech:

```python aura_model.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AuraModel:
    def generate(self, input: AvatarInput) -> AvatarResult:
        if input.avatar_id != self.avatar_id:
            self.bind(input.avatar)              # A new clip from the portrait

        features = self.features(input.audio)    # The speech, as Mimi features
        frames = self.render_chunk(features)     # AURA's 4 denoising steps, then the video decode
        return AvatarResult(frames=frames)
```

AURA reads speech as features of Kyutai's Mimi codec. It normally encodes a whole recording at once, so here each
chunk's features come from the chunk's speech plus up to 4 seconds before it (`audio_context_s` in `config.yml`). The
model keeps its key/value cache between chunks, so each chunk continues from the frames before it.

### Send the frames with their audio

`send_block()` sends the chunk's frames together with the exact speech that drove them. The runtime plays the two in
lockstep, so the mouth matches the sound:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    async def send_block(self, plan, result):
        if plan.cut_by_interrupt():
            return                              # clear_buffer cut this speech
        audio = plan.input.audio[: len(result.frames) * self.samples_per_frame]
        await self.emit(AvatarOutput(main_video=result.frames, main_audio=audio))
```

Each frame plays with 1,500 samples of speech: 1/16 of a second at 24 kHz. A playout clock records when each chunk
plays, which dates the playback reports.

## Interrupts and playback reports

When you talk over the avatar, the agent sends `lk.clear_buffer`, which runs `clear_buffer`:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    @event(name="clear_buffer")
    async def clear_buffer(self):
        self.session.drop_queued_speech()
        self.output.flush(hold=True)            # Stop the sound, hold the last frame
        await self.send(PlaybackFinished(playback_position=played, interrupted=True))
```

`clear_buffer` runs on the event loop, so it takes effect even while a chunk renders. When that chunk is done,
`send_block()` drops it.

The agent uses the playback reports to know what you heard. `playback_started` goes back when the first frame of an
utterance plays. `playback_finished` goes back when the utterance has played to its end, or when `clear_buffer` cut it,
with how many seconds of it played.

## When the model fails

An error in `generate()` during a call stops that call, not the runtime. `run()` catches it and calls `fail()`:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    async def fail(self, error):
        self.session.failed = True              # Nothing more renders in this session
        self.output.flush(hold=True)            # Hold the last frame
        await self.send(AvatarFailed(reason=str(error)))
```

The picture freezes on its last frame, and `avatar_failed` tells the client why. When the session ends, the model is
reset as after every session, and the next call starts normally.

## The portrait

`set_avatar` takes the portrait. Only the starting input of the session can send it, so a participant in the room
cannot change the face:

```python avatar_app.py (simplified) theme={"theme":{"light":"github-light","dark":"github-dark-high-contrast"}}
class AvatarApp(ReactorApp):
    @event(name="set_avatar")
    async def set_avatar(self, image: UploadedFile = InputField(), client: ClientInfo | None = None):
        if client is None or not client.system:
            raise CommandError("not_allowed", "Only the session's starting input can set the portrait.")
        self.session.avatar = image.data
        self.session.avatar_id = next(self.avatar_ids)
```

Each portrait gets an id that is unique for the life of the runtime. The app compares it with the portrait the model
holds, so the next chunk carries the portrait whenever the model needs it, and starts a new clip from it.

## Sessions and reset

* **Session start:** `@session_started` creates the session's state from the default portrait, and starts the tasks
  that collect the speech and send the playback reports.
* **Session end:** `@session_ended` stops those tasks, drops the queued speech and media, and has the loop reset the
  model before the next session.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.