from typing import TypedDictfrom langchain_core.messages import SystemMessagefrom langchain_openai import ChatOpenAIfrom langgraph.graph import StateGraphclass State(TypedDict): topic: str research: str report: strllm = ChatOpenAI(model="gpt-4o-mini", temperature=0.7)def researcher(state: State) -> dict: """Research a topic and produce bullet-point notes.""" response = llm.invoke([ SystemMessage(content=( "You are a senior researcher. Given a topic, produce 10 concise bullet " "points covering the most important facts, recent developments, and key " "insights. Return only the bullet list." )), SystemMessage(content=f"Topic: {state['topic']}"), ]) return {"research": response.content}def reporter(state: State) -> dict: """Expand research notes into a polished markdown report.""" response = llm.invoke([ SystemMessage(content=( "You are a senior reporting analyst. Given research bullet points, " "expand them into a well-structured markdown report with an introduction, " "detailed sections, and a conclusion." )), SystemMessage(content=f"Research notes:\n{state['research']}"), ]) return {"report": response.content}builder = StateGraph(State)builder.add_node("researcher", researcher)builder.add_node("reporter", reporter)builder.set_entry_point("researcher")builder.add_edge("researcher", "reporter")builder.set_finish_point("reporter")graph = builder.compile()
The compiled graph object is what Crewship invokes. Your input (e.g., {"topic": "quantum computing"}) becomes the initial state.