Skip to main content
Loading navigation
Back to prompt library

Design Initial LangGraph Workflow

Linked challenge: Robotics & Biotech Research Navigator Agent

Prompt source

planning32 lines9 sectionsNo variables1 code block
Using `LangGraph` within `LangChain`, define an initial graph with at least three nodes: `researcher`, `analyst`, and `synthesizer`. The `researcher` should use a web search tool (e.g., `SerpAPI`) to gather information. The `analyst` should process this information. The `synthesizer` should compile a report. Define the state for your graph and the edges between these nodes, considering how information flows sequentially.

```python
from typing import List, Annotated, TypedDict
from langchain_core.messages import BaseMessage
from langgraph.graph import StateGraph, END

class AgentState(TypedDict):
    research_query: str
    raw_search_results: List[str]
    analyzed_data: str
    final_report: str

def researcher_node(state: AgentState):
    # Simulate SerpAPI call
    print(f'Researcher is searching for: {state["research_query"]}')
    return {'raw_search_results': ['Search Result 1', 'Search Result 2']}

def analyst_node(state: AgentState):
    print('Analyst is processing search results...')
    # Simulate analysis with Claude Opus 4.1
    return {'analyzed_data': 'Processed insights from results.'}

def synthesizer_node(state: AgentState):
    print('Synthesizer is generating report...')
    # Simulate report generation with Claude Opus 4.1
    return {'final_report': 'Comprehensive Report.'}

workflow = StateGraph(AgentState)
workflow.add_node('researcher', researcher_node)
workflow.add_node('analyst', analyst_node)
workflow.add_node('synthesizer', synthesizer_node)

workflow.set_entry_point('researcher')
workflow.add_edge('researcher', 'analyst')
workflow.add_edge('analyst', 'synthesizer')
workflow.add_edge('synthesizer', END)

app = workflow.compile()
```