Add --show-code flag to agent-cascade for script generation#182
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--show-codeflag to theassembly agent-cascadecommand that generates and prints the equivalent Python script instead of running an interactive conversation. This mirrors the existing--show-codefunctionality in theagentcommand.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:sounddevice.RawStreamfor mic capture and speaker playback (required for macOS CoreAudio compatibility)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):show_code: booloption toAgentCascadeOptions_print_show_code()to generate and print the script without authenticating or opening audioPublic API (
aai_cli/code_gen/__init__.py): Exportsagent_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 Pythontests/test_agent_cascade_show_code.py: CLI integration tests covering the print-only path, sandbox-only enforcement, and warning behaviorDocumentation: Updated help text and snapshot to reflect the new flag.
Implementation Details
--stt/--llm/--tts-config) are notformat_turns: with formatting on, it waits for the punctuated turn; off, a bare end-of-turn fires> script.py), with warnings on stderr if neededhttps://claude.ai/code/session_01Bx8YSbUmmzaQFqyJPRHrq3