Sudheer Tripathi
feat: agent with uvlock setup
3f8a628
raw
history blame
1.57 kB
from datetime import datetime
from pathlib import Path
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
from tools import GetCurrentDateTool
model = InferenceClientModel(
model_id="Qwen/Qwen3-Next-80B-A3B-Thinking"
#model_id="Qwen/Qwen3.5-9B"
)
search_tool = DuckDuckGoSearchTool()
date_tool=GetCurrentDateTool()
QUESTIONS_LOG = Path(__file__).parent / "questions.log"
class LoggingCodeAgent(CodeAgent):
def run(self, task, *args, **kwargs):
try:
with QUESTIONS_LOG.open("a", encoding="utf-8") as f:
f.write(f"[{datetime.now().isoformat()}] Q: {task}\n")
except Exception as e:
print(f"Failed to log question: {e}")
answer = super().run(task, *args, **kwargs)
try:
with QUESTIONS_LOG.open("a", encoding="utf-8") as f:
f.write(f"[{datetime.now().isoformat()}] A: {answer}\n")
except Exception as e:
print(f"Failed to log answer: {e}")
return answer
codeAgent = LoggingCodeAgent(
max_steps=10,
model=model,
tools=[ search_tool, date_tool ],
additional_authorized_imports=[
'time',
'itertools',
'random',
'statistics',
'stat',
'datetime',
'queue',
'unicodedata',
'math',
'collections',
're'
]
)
# response = agent.run(
# """
# First use python to get current date. Then answer questions.
# Who is the president of India as of today ?
# """
# )
# print(response, date_tool)