Skip to content

Add memory bank functionality #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

luiztauffer
Copy link

@luiztauffer luiztauffer commented Apr 1, 2025

Fix #1121
Discussion

My goal here was to make the minimum amount of changes needed to implement a simple version of a memory bank. This includes:

  • an optional extra system prompt
  • one new optional argument at agent init
  • a new tool

here's an usage example:

from smolagents import (
    CodeAgent,
    LiteLLMModel,
    DuckDuckGoSearchTool,
    VisitWebpageTool,
    MemoryBankTool,
)


working_dir = "/home/agent_workspace"

memory_bank_tool = MemoryBankTool(
    memory_bank_dir_path=f"{working_dir}/memory_bank",
)

agent = CodeAgent(
    tools=[
        memory_bank_tool,
        DuckDuckGoSearchTool(),
        VisitWebpageTool(),
    ],
    model=LiteLLMModel("openrouter/anthropic/claude-3.7-sonnet"),
    max_steps=50,
    planning_interval=3,
    add_base_tools=True,
    use_memory_bank=True,
)

request = """
Do a deep research about vaccines:
- find the 5 most common vaccines used throughout the world nowadays
- find source material about the safety profile of each one of these vaccines
- find recommendations of application of these vaccines for public authorities, including schedules, target groups and other
similar relevant information
- add some historical context about each vaccine, including the year of introduction and the disease it is meant to prevent
- produce a final report with the relevant content summarized in a single markdown document, with references cited where needed
"""

response = agent.run(request)
print(response)

# save the final report
with open(f"{working_dir}/vaccine_report.md", "w") as f:
    f.write(response)

This is a first attempt that already showed interesting results in my local tests. But I'm happy to change the approach or incorporate new ideas!

@luiztauffer luiztauffer marked this pull request as ready for review April 1, 2025 16:11
@luiztauffer luiztauffer changed the title [DRAFT] memory bank Add memory bank functionality Apr 1, 2025
@aymeric-roucher
Copy link
Collaborator

Hi @luiztauffer ! I think memory bank is a great idea.

However I see an even better way to integrate it: it could be a great demo in our examples folder.
The way to do this would be simply to load the system prompts yaml file, manually modify the system prompt to add the memory bank explanation, and add the memory bank tool. If anything more is needed to enable this functionality, we can then make the necessary changes, making sure to keep it general enough to generalize to other use cases!

@dannydunk7
Copy link

This will be very useful! It seems there is no inter-run memory preservation for Smolagents yet.

@luiztauffer
Copy link
Author

@aymeric-roucher I agree, smolagents is flexible enough to have this working just with added custom prompts and tools. Other frameworks have this type of functionality by default, though, and it would be great to have something similar here as well! But I also think an example is a good start, and perhaps we can develop a discussion from there and eventually incorporate some aspects of this into the framework. I will work on that as soon as a I can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory bank
3 participants