Final_Assignment / agents /search_agent.py
sebastianfrench's picture
feat: add json with the questions
494f954
raw
history blame contribute delete
960 Bytes
from graphs.evaluation import build_workflow
from langchain_core.messages import HumanMessage, SystemMessage
from langfuse.callback import CallbackHandler
from dotenv import load_dotenv
import json
load_dotenv()
langfuse_handler = CallbackHandler(host="https://cloud.langfuse.com")
class SearchAgent:
def __init__(self):
"""
Initialize the SearchAgent with the workflow.
"""
self.workflow = build_workflow()
def __call__(self, question: str) -> str:
messages = [HumanMessage(content=question)]
state = self.workflow.invoke({
"messages":messages,
"question": question,
"external_information": "",
"is_valid_answer": False,
"has_enough_information": False,
"answer": "",
"step_counter" : {"iteration": 0,"validator": 0},
}, config={"callbacks": [langfuse_handler]})
return state["answer"]