Memory bank for smolagents #1116
luiztauffer
started this conversation in
Ideas
Replies: 1 comment
-
|
Great idea! I've implemented similar patterns. Here's what works: Shared State File Patternimport json
from pathlib import Path
class MemoryBank:
def __init__(self, path: str = "memory_bank.json"):
self.path = Path(path)
self.state = self._load()
def _load(self) -> dict:
if self.path.exists():
return json.loads(self.path.read_text())
return {
"project_goal": None,
"completed_steps": [],
"facts": [],
"decisions": [],
"current_focus": None
}
def save(self) -> None:
self.path.write_text(json.dumps(self.state, indent=2))
def add_fact(self, fact: str) -> None:
self.state["facts"].append({"fact": fact, "timestamp": time.time()})
self.save()
def mark_complete(self, step: str) -> None:
self.state["completed_steps"].append(step)
self.save()Integration with AgentsOption 1: Tool @tool
def update_memory(key: str, value: str, memory: MemoryBank) -> str:
memory.state[key] = value
memory.save()
return f"Updated {key}"
@tool
def recall_memory(key: str, memory: MemoryBank) -> str:
return str(memory.state.get(key, "Not found"))Option 2: Context injection def build_context(memory: MemoryBank) -> str:
return f"""Current project goal: {memory.state["project_goal"]}
Completed: {memory.state["completed_steps"]}
Key facts: {memory.state["facts"][-5:]} # Last 5 facts"""Why This Pattern Works
This is the stigmergy pattern. Working example: https://github.com/KeepALifeUS/autonomous-agents |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How could we implement something similar to cline’s memory bank in smolagents? The goal is to have a source of long term memory for longer and complex tasks, which will help agents:
I guess we could simply have an optional addition to the agents system prompt with similar instructions as that reference, but given that smolagents is a more general tool than cline, I was wondering if anyone has had any experience in implementing a similar feature for smolagents, or if anyone would like to discuss strategies for that.
Some ideas:
MemoryBankToolwhich the agents could rely on to read or update those filesBeta Was this translation helpful? Give feedback.
All reactions