Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/smolagents_doc/en/memory.ipynb
Views: 2935
📚 Manage your agent's memory
In the end, an agent can be defined by simple components: it has tools, prompts. And most importantly, it has a memory of past steps, drawing a history of planning, execution, and errors.
Replay your agent's memory
We propose several features to inspect a past agent run.
You can instrument the agent's run to display it in a great UI that lets you zoom in/out on specific steps, as highlighted in the instrumentation guide.
You can also use agent.replay()
, as follows:
After the agent has run:
If you want to replay this last run, just use:
Dynamically change the agent's memory
Many advanced use cases require dynamic modification of the agent's memory.
You can access the agent's memory using:
Use agent.memory.get_full_steps()
to get full steps as dictionaries.
You can also use step callbacks to dynamically change the agent's memory.
Step callbacks can access the agent
itself in their arguments, so they can access any memory step as highlighted above, and change it if needed. For instance, let's say you are observing screenshots of each step performed by a web browser agent. You want to log the newest screenshot, and remove the images from ancient steps to save on token costs.
You culd run something like the following. Note: this code is incomplete, some imports and object definitions have been removed for the sake of concision, visit the original script to get the full working code.
Then you should pass this function in the step_callbacks
argument upon initialization of your agent:
Head to our vision web browser code to see the full working example.
Run agents one step at a time
This can be useful in case you have tool calls that take days: you can just run your agents step by step. This will also let you update the memory on each step.