Download agents/react_agent.py from devserg/medi-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/devserg/medi-bot/resolve/main/agents/react_agent.py
- Command line
-
hf download hf://spaces/devserg/medi-bot/agents/react_agent.py
-
curl -L -o react_agent.py https://huggingface.co/spaces/devserg/medi-bot/resolve/main/agents/react_agent.py
1.11 kB
| """Build the LangGraph ReAct agent for MediBot.""" | |
| from langchain_openai import ChatOpenAI | |
| from langchain_core.messages import SystemMessage | |
| from langgraph.prebuilt import create_react_agent | |
| from langgraph.checkpoint.memory import MemorySaver | |
| from agents.tools import search_diseases, get_disease_details, calculate_severity, list_common_symptoms | |
| from prompts.templates import SYSTEM_PROMPT | |
| from config import CHAT_MODEL | |
| TOOLS = [search_diseases, get_disease_details, calculate_severity, list_common_symptoms] | |
| def build_agent(): | |
| """Return (graph, config). Call once at startup. | |
| Usage: | |
| graph, config = build_agent() | |
| result = graph.invoke({"messages": [HumanMessage(content="I have fever")]}, config) | |
| reply = result["messages"][-1].content | |
| """ | |
| llm = ChatOpenAI(model=CHAT_MODEL, temperature=0.2) | |
| memory = MemorySaver() | |
| graph = create_react_agent( | |
| model=llm, | |
| tools=TOOLS, | |
| prompt=SystemMessage(content=SYSTEM_PROMPT), | |
| checkpointer=memory, | |
| ) | |
| config = {"configurable": {"thread_id": "medibot-main"}} | |
| return graph, config |