Skip to content

Generate and Speak

The Generate-and-Speak node fuses LLM token generation with streaming TTS synthesis: it runs the same projection and language-model inference as a Generate node, but as tokens arrive it segments them into sentences, dispatches each sentence to a dedicated TTS strand, and emits PCM audio frames alongside the text deltas.

Because synthesis overlaps generation, audio begins after roughly the first sentence (min_sentence_chars) rather than after the whole answer — the TTS of one sentence runs while the LLM is still generating the next. This is the lowest-latency way to speak a generated answer (measured by the time_to_first_audio_ms diagnostic). sampling.max_tokens is fixed at creation, the same as on Generate. Chaining a standalone Generate → Speak instead (with Speak's input set to the Generate node's output) produces the same voice but cannot start until generation has fully finished, since Speak only sees the completed text. Prefer this fused node when you want a generated answer spoken with minimal delay, and the split form only when you need to branch on, inspect, or transform the text in between.

The node has no voice settings. It speaks with the agent's voice profile, which you pass when you create the agent. A graph with a Generate and Speak node and no voice fails agent creation with 3025 AgentVoiceRequired. The TTS model, speaker, speed, language, reference clip, delivery mode and emit_visemes all come from the profile. The node keeps its language-model settings and its chunking (min_sentence_chars, first_chunk_max_chars).

The audio format is announced once per turn, by the first speaking node that produces audio, so a later Speak node in the same turn reuses it. With the voice's emit_visemes on, the node sends one lip-sync viseme frame per sentence.

NodeType: GenerateAndSpeak.

Leave context_size at 0 to inherit the model variant's window, then the server default_n_ctx (commonly 8192) — the same resolution as Generate. The context table is an advanced structural override. Do not set q4_0 KV expecting a VRAM win at a right-sized window.

Parameters

Param Type Default Range Structural Localizable Description
model_name str empty — ✓ — LLM model catalog name. Empty = use the agent's default_model_name.
context_size int 0 ≥ 0.0 ✓ — KV-cache / context window (n_ctx) for the LLM in tokens. 0 = fall back to the model variant's context_size, else the server default_n_ctx. Validated against the model's trained maximum at agent creation.
system_prompt str (multiline) empty — — ✓ Prepended before the user turn during projection. Empty = none.
input str empty — ✓ — Slot name this node consumes as its primary text. Empty = "user_message". Structural: immutable after creation — rebinding would re-wire the slot dataflow that is validated once at agent creation.
template str (multiline) empty — — ✓ Mustache template applied to the user-area message at projection time. Empty = no template.
placement Placement Placement.BeforeUserAsSystem — — — Where the rendered template body is placed relative to the resolved input.
output_name str empty — ✓ — Name this node's output slot is stored under. Empty = the node's own name. Structural: immutable after creation — renaming would re-wire the slot dataflow that is validated once at agent creation.
history_role HistoryRole HistoryRole.Assistant — — — Controls whether/how this node's slot replays in later turns' projected transcript. No send field — GenerateAndSpeak always streams text (streaming and non-streaming delivery would need incompatible projection-replay handling, so only the streamed mode is supported).
sampling SamplingOverrides unset — — — Sparse sampling overrides applied on top of the model-catalog defaults.
grammar str (multiline) empty — — — Optional GBNF grammar. When non-empty, the generated (and spoken) output is constrained to this grammar at every decode step. Empty = unconstrained. Must contain a root rule. Mutable — rebuilt per turn. Narrower fit than on Generate: use it to constrain spoken output to a fixed set of barks / canned lines. Validated at agent creation and on mutation (3007).
min_sentence_chars int 12 ≥ 1.0 — — Minimum width of the text since the last cut before a sentence end closes a chunk; a CJK or other 3–4-byte character counts as 2. The default 12 is two or three English words. Lower values reduce first-utterance latency at the cost of more, smaller TTS calls.
first_chunk_max_chars int 0 ≥ 0.0 — — Time-to-first-audio knob. When > 0, the FIRST chunk may also end at a comma, semicolon or colon followed by a space, or at an em dash, and is cut at the next space once it is this wide, so speech starts sooner. Neither cut fires before 5 words or min_sentence_chars. Later chunks keep whole sentences. No effect on text without spaces (CJK). 0 = off. 48 is the measured starting point: about 40% less model-side wait on Supertonic and Pocket. Check how it sounds with your voice before shipping it.
substitute_agent_variables bool False — — — When true, replace __VARIABLE__ markers in streamed LLM output with the rendered values of agent variables that declared allow_output_substitution. Matching is ASCII case-insensitive. Default false. Transformed text is authoritative for the slot, wire answer, history, and TTS input (substitution runs before synthesis).
output_filter OutputFilterOverrides unset — — — Opt-in bounded artifact cleanup applied to streamed LLM output before variable substitution, slot/history write, wire delivery, and TTS. Missing/null = all flags off (defaults).
context ContextOverrides unset — ✓ — Backend context construction. Null table inherits, except CreateContext still defaults n_outputs_max to 1. Structural.
adaptation ModelAdaptation unset — ✓ — Changes how the model behaves for this node (LoRA adapters; later control vectors). Null = base model. Structural: applied to the llama context at creation, so a change means a new context. Appended last so existing field IDs do not move.

Exits

Each exit is a structural string field on the node's params; its value names the target node (empty = END).

Exit Param field Description
default default_exit Default exit target — routes here after generation + synthesis complete. Empty string = END.

LoRA adapters

adaptation.loras runs this node's model with one or more fine-tuned LoRA adapters, each with a scale. See Use a LoRA Adapter for where to put the file and how to tune the scale.

Constrained output (GBNF grammar)

Like Generate, this node accepts an optional grammar (GBNF) that constrains the generated output at every decode step. The full rules there apply verbatim (must contain a root rule; fail-fast at agent creation and InvalidParamValue 3007 on a bad mutation; mutable per turn; constrain the wire, not the thinking).

The fit here is narrower than on Generate: the constrained output is also spoken, so grammar only makes sense when the constrained text is itself meant to be voiced — e.g. restricting an NPC to a fixed set of barks or canned lines:

root ::= "Halt!" | "Who goes there?" | "Move along." | "For the throne!"

Note the interaction with min_sentence_chars (default 12): very short constrained output may never cross the sentence-boundary threshold, so the whole (tiny) output flushes as a single TTS call — which is fine for barks.

See Concept: Constrained output (GBNF) for what a grammar does and doesn't guarantee, and How to constrain output with a grammar for a worked example.

Diagnostics

When enable_diagnostics = true, this node contributes to debug_info.nodes[].diagnostics. See Turn Diagnostics JSON for the envelope, the shared input.prompt[] shape, and the engine counters.

This is the only node that emits a fifth section, tts — the voice half of the fused step is kept separate from the language-model parameters. It holds the agent's voice as it was when the node ran, plus this node's chunking.

Key Meaning Absent when
parameters.model_name The language model that actually ran, after fallback. The name could not be resolved.
parameters.temperature, top_p, top_k, max_tokens The resolved sampling set. Unlike Generate, the penalty and seed keys are not recorded. —
parameters.history_role How the answer replays into later turns. —
parameters.substitute_agent_variables true. Output substitution is off.
parameters.output_filter.strip_speaker_prefix, parameters.output_filter.strip_asterisk_spans, parameters.output_filter.strip_paren_spans, parameters.output_filter.strip_bracket_spans true, one key per enabled rule. That rule is off.
parameters.output_filter.max_prefix_bytes, parameters.output_filter.max_span_bytes The scan limits the filter ran with. No filter rule is enabled.
parameters.input The configured input slot name. Using the user_message default.
parameters.output_name The configured output slot name. Defaulting to the node name.
tts.tts_model_name, speaker_id, speed, lang, reference_voice The agent's voice as authored. An empty lang means the session locale or catalog default applied; reference_voice is the authored path, not a per-locale file resolved from it. —
tts.voice_description The Maya1 voice description. Not set.
tts.delivery_mode, tts.intensity The active delivery mode (neutral when none) and its intensity. —
tts.delivery_instruction The active mode's instruction. The mode has none.
tts.emit_visemes Whether the voice sends a viseme track. —
tts.sample_rate The TTS model's native sample rate, in Hz. —
tts.min_sentence_chars Sentence-boundary threshold before a chunk is synthesized. —
tts.first_chunk_max_chars First-chunk length cap (0 = off). —
tts.time_to_first_audio_ms Delay before the first audio chunk was produced — the voice counterpart of time_to_first_token_ms. No audio was produced.
input.prompt[] The rendered prompt as the model received it. —
output.text The text this node produced (and spoke). The node produced no output slot.
engine.* Grammar state and scheduler counters. Server config include_engine_diagnostics is off.

The node-level variable_replacements[] and output_filter_removals[] arrays behave exactly as on Generate, and matter more here: what the filter removed is also what the voice did not say.