consolidate: Evo LangGraph StateGraph — training loop orchestration
Browse files- evo/langgraph_graph.py +62 -0
evo/langgraph_graph.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Agent Q3 [Evo] — LangGraph StateGraph
|
| 3 |
+
Self-improvement loop: ingest → train → benchmark → feedback → repeat
|
| 4 |
+
"""
|
| 5 |
+
from langgraph.graph import StateGraph, END
|
| 6 |
+
from typing import TypedDict
|
| 7 |
+
|
| 8 |
+
class EvoState(TypedDict):
|
| 9 |
+
cycle: int
|
| 10 |
+
ingest_done: bool
|
| 11 |
+
train_done: bool
|
| 12 |
+
benchmark_score: float
|
| 13 |
+
feedback_pushed: bool
|
| 14 |
+
notes: str
|
| 15 |
+
|
| 16 |
+
def ingest_node(state: EvoState) -> EvoState:
|
| 17 |
+
from arxiv_ingestor import ingest
|
| 18 |
+
ingest(max_results=10)
|
| 19 |
+
state["ingest_done"] = True
|
| 20 |
+
state["notes"] += " | arXiv ingested"
|
| 21 |
+
return state
|
| 22 |
+
|
| 23 |
+
def train_node(state: EvoState) -> EvoState:
|
| 24 |
+
from training_pipeline import run
|
| 25 |
+
run()
|
| 26 |
+
state["train_done"] = True
|
| 27 |
+
state["notes"] += " | LoRA trained"
|
| 28 |
+
return state
|
| 29 |
+
|
| 30 |
+
def benchmark_node(state: EvoState) -> EvoState:
|
| 31 |
+
import asyncio
|
| 32 |
+
from benchmark_runner import run_all
|
| 33 |
+
results = asyncio.run(run_all())
|
| 34 |
+
avg = sum(r["score"] for r in results) / len(results)
|
| 35 |
+
state["benchmark_score"] = avg
|
| 36 |
+
state["notes"] += f" | benchmark={avg:.2%}"
|
| 37 |
+
return state
|
| 38 |
+
|
| 39 |
+
def feedback_node(state: EvoState) -> EvoState:
|
| 40 |
+
from feedback_collector import push_to_hf
|
| 41 |
+
push_to_hf()
|
| 42 |
+
state["feedback_pushed"] = True
|
| 43 |
+
state["notes"] += " | feedback pushed"
|
| 44 |
+
return state
|
| 45 |
+
|
| 46 |
+
def should_continue(state: EvoState) -> str:
|
| 47 |
+
return "continue" if state["benchmark_score"] < 0.80 else END
|
| 48 |
+
|
| 49 |
+
def build_evo_graph() -> StateGraph:
|
| 50 |
+
g = StateGraph(EvoState)
|
| 51 |
+
g.add_node("ingest", ingest_node)
|
| 52 |
+
g.add_node("train", train_node)
|
| 53 |
+
g.add_node("benchmark", benchmark_node)
|
| 54 |
+
g.add_node("feedback", feedback_node)
|
| 55 |
+
g.set_entry_point("ingest")
|
| 56 |
+
g.add_edge("ingest", "train")
|
| 57 |
+
g.add_edge("train", "benchmark")
|
| 58 |
+
g.add_edge("benchmark", "feedback")
|
| 59 |
+
g.add_conditional_edges("feedback", should_continue, {"continue":"ingest", END: END})
|
| 60 |
+
return g.compile()
|
| 61 |
+
|
| 62 |
+
graph = build_evo_graph()
|