File size: 1,050 Bytes
1c86fb3
10e9b7d
31243f4
 
1c86fb3
473f360
 
 
351264a
1c86fb3
473f360
 
e80aab9
 
351264a
1c86fb3
 
473f360
 
 
 
 
 
 
1c86fb3
 
473f360
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
26
27
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel

class BasicAgent:
    def __init__(self):
        print("BasicAgent initialized.")
        self.model = InferenceClientModel(
            model_id="Qwen/Qwen2.5-Coder-32B-Instruct"
        )
        self.agent = CodeAgent(
            tools=[WebSearchTool()],
            model=self.model,
            add_base_tools=True  # يضيف: calculator, final_answer, إلخ
        )

    def __call__(self, question: str) -> str:
        print(f"Agent received question (first 50 chars): {question[:50]}...")
        try:
            formatted_question = (
                f"{question}\n\n"
                "Answer with ONLY the final answer, no explanation, "
                "no extra words, no 'The answer is', just the exact value/word/number requested."
            )
            answer = self.agent.run(formatted_question)
            return str(answer).strip()
        except Exception as e:
            print(f"Error running agent: {e}")
            return f"AGENT ERROR: {e}"