Skip to content

Add --show-code flag to agent-cascade for script generation#182

Merged
alexkroman merged 1 commit into
mainfrom
claude/sharp-mccarthy-t0pshp
Jun 16, 2026
Merged

Add --show-code flag to agent-cascade for script generation#182
alexkroman merged 1 commit into
mainfrom
claude/sharp-mccarthy-t0pshp

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Adds a --show-code flag to the assembly agent-cascade command that generates and prints the equivalent Python script instead of running an interactive conversation. This mirrors the existing --show-code functionality in the agent command.

Key Changes

  • New code generation module (aai_cli/code_gen/agent_cascade.py): Renders a complete, runnable Python script that reproduces the cascade session by wiring Streaming STT → LLM Gateway → streaming TTS client-side. The script:

    • Uses a single full-duplex sounddevice.RawStream for mic capture and speaker playback (required for macOS CoreAudio compatibility)
    • Streams STT at 24 kHz with configurable speech model and turn formatting
    • Calls the LLM Gateway with the running conversation history
    • Synthesizes replies sentence-by-sentence via streaming TTS
    • Supports barge-in (interrupting a reply with a new user turn)
  • Static body module (aai_cli/code_gen/agent_cascade_body.py): Separates the orchestration logic (with many literal braces for dict/set literals and protocol loops) from the formatted header, avoiding the need to double-escape braces.

  • CLI integration (aai_cli/commands/agent_cascade/_exec.py):

    • Adds show_code: bool option to AgentCascadeOptions
    • Implements _print_show_code() to generate and print the script without authenticating or opening audio
    • Warns on stderr (not stdout) if a file source is passed, since the generated script is microphone-driven
  • Public API (aai_cli/code_gen/__init__.py): Exports agent_cascade(config, speech_model) function for script generation.

  • Tests:

    • tests/test_code_gen_agent_cascade.py: Example-based tests verifying all three legs (STT/LLM/TTS) are wired, session knobs are injected, and the generated code is valid Python
    • tests/test_agent_cascade_show_code.py: CLI integration tests covering the print-only path, sandbox-only enforcement, and warning behavior
  • Documentation: Updated help text and snapshot to reflect the new flag.

Implementation Details

  • The generated script targets the active environment's hosts (sandbox-only, since streaming TTS has no production host), so URLs are always valid for the key's environment
  • Named per-leg knobs (voice, model, max_tokens, etc.) are reflected; escape hatches (--stt/--llm/--tts-config) are not
  • The reply-cue predicate adapts based on format_turns: with formatting on, it waits for the punctuated turn; off, a bare end-of-turn fires
  • The script is printed to stdout (clean for > script.py), with warnings on stderr if needed

https://claude.ai/code/session_01Bx8YSbUmmzaQFqyJPRHrq3

Mirror the --show-code flag the other run commands carry (transcribe / stream /
agent) on agent-cascade: print a runnable Python script that wires the three
primitives client-side — Streaming STT -> LLM Gateway -> streaming TTS — instead
of holding a live conversation.

The generated script targets the active environment's hosts (sandbox-only, since
streaming TTS has no production host) and reflects the named per-leg knobs (voice,
language, system prompt, greeting, model, max tokens, speech model, format-turns);
the --stt/--llm/--tts-config escape hatches are not inlined. As with `agent
--show-code`, a passed audio source warns on stderr that the script is mic-driven.

The code_gen template is split into a brace-free header (filled via str.format with
the injected constants) and a static body holding the brace-heavy orchestration, so
no literal brace has to be doubled.
@alexkroman alexkroman enabled auto-merge June 16, 2026 19:00
@alexkroman alexkroman added this pull request to the merge queue Jun 16, 2026
Merged via the queue into main with commit 30a4bb8 Jun 16, 2026
19 checks passed
@alexkroman alexkroman deleted the claude/sharp-mccarthy-t0pshp branch June 16, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants