Use Scenario
A self evolving agent increases its capabilities by attempting to insert more text than what can fit in a given memory block.
Context
The suite of memory tools provide dynamic growth to Letta agents. Large inserts of text into memory blocks present a limitation because the memory tool cannot adjust block size.
Overview
Upon a failure of the memory tool due to a block size constraint, the memory_update_size tool is invoked during the tool flow to support the insert by increasing the target block size.
Required Dependencies
This custom tool leverages the new in-built Letta
clientcontext provided to tools. The agent does not need a Letta API key configured in the ADE. The tool can pull from Letta’s in built environment variables to extract an agent’s id
- Letta agent with
memorytools enabled agent_id: os.getenv(“LETTA_AGENT_ID”); no need for agent id storage in core memory.
Tool Implementation
import os
def memory_update_size(block_label:str, new_block_limit: int):
"""
Updates the character limit for a specific memory block within an agent.
Args:
block_label: The label identifying the specific memory block (e.g., 'human', 'persona').
new_block_limit: The new maximum character limit for the specified memory block.
"""
try:
## check if block exists
block_response = client.agents.blocks.retrieve(
block_label=block_label,
agent_id=os.getenv("LETTA_AGENT_ID"),
)
## apply size increase
updated_response = client.agents.blocks.update(
block_label=block_label,
agent_id=os.getenv("LETTA_AGENT_ID"),
limit=new_block_limit
)
return updated_response
except Exception as e:
error_message = f"Error updating block '{block_label}': {str(e)}"
return {"error": error_message}
Tool Schema
{
"name": "memory_update_size",
"description": "Updates the character limit for a specific memory block within an agent.",
"parameters": {
"type": "object",
"properties": {
"block_label": {
"type": "string",
"description": "The label identifying the specific memory block (e.g., 'human', 'persona')."
},
"new_block_limit": {
"type": "integer",
"description": "The new maximum character limit for the specified memory block."
}
},
"required": [
"agent_id",
"block_label",
"new_block_limit"
]
}
}
Prelim Check To Verify Block Exists
When an invalid block name is used as a parameter, the tool did not fail as expected. Instead, the update endpoint auto-selected a random block as a default fallback and applied the limit change. The behavior created hallucinations as the LLM believed that it had access to non-existent blocks.
To avoid this, I opted to apply a precheck to verify the block exists.