File size: 987 Bytes
bfb26a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from utils.agent_executor import create_agent_executor


class BasicAgent:
    def __init__(self):
        print("BasicAgent initialized with LangChain tools.")
        self.agent_executor = create_agent_executor()

    def __call__(self, question_data: dict) -> str:
        question_text = question_data.get('text', '')
        file_url = question_data.get('file_url')
        print(
            f"Agent received question (task_id: {question_data.get('task_id')}) (first 50 chars): {question_text[:50]}...")
        if file_url:
            print(f"With attached file URL: {file_url}")

        print(
            f"Start processing question (task_id: {question_data.get('task_id')})")
        response = self.agent_executor.invoke(
            {"input": question_text, "file_url": file_url})
        answer = response.get('output', 'No answer generated.')
        print(
            f"Agent generated answer (task_id: {question_data.get('task_id')}): {answer}")
        return answer