Psiska commited on
Commit
5d85d64
Β·
1 Parent(s): 67c7260

Made the agent conversational without memory

Browse files
Files changed (1) hide show
  1. agent.py +10 -5
agent.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  from dotenv import load_dotenv
3
  from huggingface_hub import InferenceClient
4
- from smolagents import CodeAgent, Model, ChatMessage, SimpleMemory
5
  import tools.tools as tls # Your tool definitions
6
 
7
  load_dotenv()
@@ -61,18 +61,23 @@ class BasicAgent:
61
  def __init__(self):
62
  print("βœ… BasicAgent initialized with Hugging Face chat model.")
63
  self.model = HuggingFaceChatModel()
64
- self.memory = SimpleMemory(k=5) # k = how many turns to remember
65
-
66
  self.agent = CodeAgent(
67
  tools=[tls.search_tool, tls.calculate_cargo_travel_time],
68
  model=self.model,
69
- memory=self.memory,
70
  additional_authorized_imports=["pandas"],
71
  max_steps=20,
72
  )
73
 
74
- def __call__(self, question: str) -> str:
 
 
 
 
 
 
75
  print(f"πŸ“₯ Received question: {question[:60]}...")
76
  response = self.agent.run(question)
77
  print(f"πŸ“€ Response generated: {response[:60]}...")
78
  return response
 
 
1
  import os
2
  from dotenv import load_dotenv
3
  from huggingface_hub import InferenceClient
4
+ from smolagents import CodeAgent, Model, ChatMessage
5
  import tools.tools as tls # Your tool definitions
6
 
7
  load_dotenv()
 
61
  def __init__(self):
62
  print("βœ… BasicAgent initialized with Hugging Face chat model.")
63
  self.model = HuggingFaceChatModel()
64
+
 
65
  self.agent = CodeAgent(
66
  tools=[tls.search_tool, tls.calculate_cargo_travel_time],
67
  model=self.model,
 
68
  additional_authorized_imports=["pandas"],
69
  max_steps=20,
70
  )
71
 
72
+ def __call__(self, messages) -> str:
73
+ # Extract last user message from the chat history
74
+ if isinstance(messages, list):
75
+ question = messages[-1]["content"] # Gradio gives list of dicts
76
+ else:
77
+ question = messages # Fallback if it's just a string
78
+
79
  print(f"πŸ“₯ Received question: {question[:60]}...")
80
  response = self.agent.run(question)
81
  print(f"πŸ“€ Response generated: {response[:60]}...")
82
  return response
83
+