| | from __future__ import annotations |
| |
|
| | """A light-weight module that exposes the BasicAgent class and DEFAULT_API_URL constant. |
| | |
| | Importing from this file is safe in CLI/unit-test contexts because it has **no** side |
| | effects such as instantiating a Gradio Blocks UI or requiring the optional OAuth |
| | dependencies of Gradio. |
| | """ |
| |
|
| | import logging |
| |
|
| | from langchain_core.messages import HumanMessage |
| |
|
| | from langraph_agent import build_graph |
| |
|
| | |
| | |
| | |
| | DEFAULT_API_URL: str = "https://agents-course-unit4-scoring.hf.space" |
| |
|
| |
|
| | class BasicAgent: |
| | """A minimal wrapper around the LangGraph agent used in this repo.""" |
| |
|
| | def __init__(self) -> None: |
| | |
| | |
| | logging.debug("[BasicAgent] Building LangGraph …") |
| | self.agent = build_graph() |
| | logging.debug("[BasicAgent] LangGraph ready.") |
| |
|
| | async def aquery(self, question: str) -> str: |
| | """Asynchronously ask the agent a question and return the raw answer text.""" |
| | messages = [HumanMessage(content=question)] |
| | response = await self.agent.ainvoke({"messages": messages}) |
| | if isinstance(response, dict) and response.get("messages"): |
| | return response["messages"][-1].content |
| | return str(response) |