branch_text¶
basemode.continue_.branch_text
async def branch_text(
prefix: str,
model: str = "gpt-4o-mini",
*,
n: int = 4,
max_tokens: int = 200,
temperature: float = 0.9,
strategy: str | None = None,
rewind: bool = False,
strict_max_tokens: bool = False,
record_health: bool = True,
observation: ObservationContext | None = None,
retry_empty_completion: bool = True,
on_usage: BranchUsageCallback | None = None,
**extra,
) -> AsyncGenerator[tuple[int, str], None]
Stream n parallel continuations.
Yields (branch_idx, token) tuples until all branches finish.
Notes¶
- Branches run concurrently with
asynciotasks. - Stream order is interleaved across branches.
branch_idxis zero-based.nmust be at least one; a provider error from any branch is propagated and cancels the rest. This includesEmptyCompletionError(withmodel,strategy, andfinish_reason) when a branch's stream ends without yielding any content.strict_max_tokens=Truestops each visible branch stream atmax_tokensusing client-side token counting. Some models are sent a wider budget than requested, because their hidden reasoning would otherwise consume it (seebasemode.strategies.compat); pass this flag when the visible length must matchmax_tokensexactly.observationattaches the same allow-listed caller provenance to each independent branch operation. It never carries prompt or response content.record_healthis retained for source compatibility but does not bypass the unified ledger.retry_empty_completion=Falsedisables the default retry after an empty response.on_usageis called once per branch with its index and provider usage payloads.