Spaces:
Configuration error
Configuration error
Download app/agent/graph.py from welcometoFightclub/acpc_testing_third: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/welcometoFightclub/acpc_testing_third/resolve/main/app/agent/graph.py
- Command line
-
hf download hf://spaces/welcometoFightclub/acpc_testing_third/app/agent/graph.py
-
curl -L -o graph.py https://huggingface.co/spaces/welcometoFightclub/acpc_testing_third/resolve/main/app/agent/graph.py
1.33 kB
| """ | |
| LangGraph StateGraph definition for the Agentic RAG pipeline. | |
| """ | |
| import threading | |
| from langgraph.graph import StateGraph, END, START | |
| from app.agent.state import AgentState | |
| from app.agent.nodes import ( | |
| retrieve, | |
| generate, | |
| fallback, | |
| respond, | |
| ) | |
| _compiled_graph = None | |
| _graph_lock = threading.Lock() | |
| def build_graph(): | |
| """Build and compile the LangGraph agent graph.""" | |
| graph = StateGraph(AgentState) | |
| # Register all nodes | |
| graph.add_node("retrieve", retrieve) | |
| graph.add_node("generate", generate) | |
| graph.add_node("fallback", fallback) | |
| graph.add_node("respond", respond) | |
| # Entry point: go straight to retrieval | |
| graph.add_edge(START, "retrieve") | |
| # After retrieval: go directly to generation | |
| graph.add_edge("retrieve", "generate") | |
| # After generation: straight to respond | |
| graph.add_edge("generate", "respond") | |
| # Terminal nodes | |
| graph.add_edge("fallback", "respond") | |
| graph.add_edge("respond", END) | |
| return graph.compile() | |
| def get_graph(): | |
| """Return the singleton compiled graph.""" | |
| global _compiled_graph | |
| if _compiled_graph is None: | |
| with _graph_lock: | |
| if _compiled_graph is None: | |
| _compiled_graph = build_graph() | |
| return _compiled_graph | |