# graph_deep_research.py — Deep Research (LangGraph sketch) # pip install langgraph langchain-core (pin yourself) # Use a local chat model binder; do not embed secrets. from typing import TypedDict, Literal from langgraph.graph import StateGraph, END SYSTEM = """You are a careful research desk. Goal: produce a brief, not a verdict. RULES: - Use only facts present in the user paste or clearly marked as [UNVERIFIED]. - Separate: Known / Inferred / Unknown / Next checks. - Label every finding Known vs Inferred. Never state Inferred as fact. - Do not invent causes (trust, reputation, criteria changes, market effects) not in the paste. - Do not invent metrics, percentages, or dates. - If recommending a priority, phrase as hypothesis under Open questions / Next checks — not as decided scope. - Prefer quoting pasted labels/counts exactly. - Cite sources as the user labeled them (URL, doc name, date). Do not invent citations. - No spending, no shell commands, no credential requests. - Stop after the brief. Ask one clarifying question only if blocking. OUTPUT: 1) One-sentence scope 2) Findings (bullets) 3) Open questions 4) Next checks (max 5) 5) Confidence: low|medium|high + why""" class State(TypedDict): user_input: str draft: str approved: bool notes: str def produce(state: State) -> State: # Pseudo: call your local model with SYSTEM + state["user_input"] draft = "[MODEL OUTPUT PLACEHOLDER — wire your local LLM here]\n" + state["user_input"][:500] return {**state, "draft": draft, "notes": "awaiting human"} def human_gate(state: State) -> State: # In real use: interrupt / input() / UI approval. # Default False so nothing auto-publishes. return {**state, "approved": False} def route_after_gate(state: State) -> Literal["done", "revise"]: return "done" if state.get("approved") else "done" # stage-1: always end after gate g = StateGraph(State) g.add_node("produce", produce) g.add_node("human_gate", human_gate) g.set_entry_point("produce") g.add_edge("produce", "human_gate") g.add_conditional_edges("human_gate", route_after_gate, {"done": END, "revise": "produce"}) app = g.compile() if __name__ == "__main__": out = app.invoke({"user_input": "PASTE_EXAMPLE_IN", "draft": "", "approved": False, "notes": ""}) print(out)