Build Your Own AI Podcasting Agent with LangGraph, Gemini, and Chirp 3

Source notebook

Repo path: gemini/orchestration/langgraph_gemini_podcast.ipynb · Open on GitHub · advanced

Builds a LangGraph podcast agent using Gemini research loops and Chirp 3 text-to-speech audio.

Summary

This notebook teaches how to orchestrate an AI podcast creation workflow with LangGraph, LangChain, Gemini in Vertex AI, and Google Cloud Text-to-Speech. The workflow defines agent state and memory, generates an outline, plans and runs searches across arXiv, PubMed, and Wikipedia, writes and critiques a script, revises it, then synthesizes alternating host audio with Chirp 3 voices and combines MP3 parts into one podcast file.

Key code patterns

Gemini chat model on Vertex AI

model = ChatGoogleGenerativeAI(
    model="gemini-3.5-flash",
    project=PROJECT_ID,
    location=LOCATION,
    vertexai=True,
    temperature=0,
    thinking_level="low",
)

Configures Gemini as the core model for outline, research planning, writing, and critique nodes.

LangChain search tools

@tool
def search_arxiv(query: str) -> list[Document]:
    retriever = ArxivRetriever(load_max_docs=2, get_full_documents=False)
    docs = retriever.invoke(query)
    if docs:
        return docs
    return ["No results found on arXiv"]

Wraps external retrievers as tools that the LangGraph research node can call.

Tool-calling research node

tools = [search_arxiv, search_pubmed, search_wikipedia]
model_with_tools = model.bind_tools(tools)
response_tool_calls = model_with_tools.invoke(messages)
tool_node = ToolNode(tools)
response = tool_node.invoke({"messages": [response_tool_calls]})

Lets Gemini select a search tool, then executes the selected tool through a LangGraph ToolNode.

StateGraph workflow loops

workflow = StateGraph(AgentState)
workflow.add_node("research_agent", research_agent_node)
workflow.add_conditional_edges(
    "research_agent",
    should_continue_tools,
    {"generate_script": "generate_script", "research_plan": "research_plan"},
)
graph = workflow.compile(checkpointer=memory)

Encodes iterative research and revision as conditional graph transitions with memory checkpointing.

Alternating Chirp 3 voices

for count, line in enumerate(parsed_script):
    synthesis_input = texttospeech.SynthesisInput(text=line)
    voice_name = "en-US-Chirp3-HD-Aoede" if count % 2 == 0 else "en-US-Chirp3-HD-Puck"
    voice = texttospeech.VoiceSelectionParams(language_code="en-US", name=voice_name)
    response = client.synthesize_speech(input=synthesis_input, voice=voice, audio_config=audio_config)

Turns alternating script lines into two-host podcast audio using Text-to-Speech voices.

Models & APIs used

When to use this

Use this pattern to build a customizable research, script-writing, critique, revision, and audio-generation podcast agent.

Gotchas & caveats

  • Requires an existing Google Cloud project with Vertex AI API enabled.
  • Colab users must authenticate with google.colab.auth.authenticate_user().
  • LOCATION defaults to global from GOOGLE_CLOUD_REGION when not set.
  • FFmpeg must be installed for pydub AudioSegment MP3 handling.
  • Text-to-Speech client sets quota_project_id to PROJECT_ID.
  • The notebook installs required packages before running the workflow.
  • Temporary part-N.mp3 files are removed after combining audio.

Best practices

  • Defines AgentState with typed workflow fields for task, outline, queries, content, draft, critique, and tool calls.
  • Uses MemorySaver and thread_id to preserve unique workflow execution history.
  • Uses temperature=0 for deterministic agent node outputs.
  • Limits arXiv retrieval with load_max_docs=2 and get_full_documents=False.
  • Prompts the research agent to vary tools and avoid repeating prior sources and queries.
  • Separates workflow stages into outline, research planning, research execution, script generation, critique, and critique-driven research.
  • Visualizes the compiled LangGraph workflow with a Mermaid diagram.
  • Combines short generated audio segments with silence between lines for listenability.