* docs: restructure architecture documentation to sideline legacy agent types This commit reorganizes the agent architecture documentation to address confusion around legacy agent types (memgpt_agent, memgpt_v2_agent) and clarify that users should not specify agent_type for new projects. The documentation was causing confusion for both users and LLMs: - References to memgpt_agent, memgpt_v2_agent, and letta_v1_agent were scattered throughout main docs - The naming progression (memgpt → memgpt_v2 → letta_v1) is non-standard - LLMs trained on these docs were recommending deprecated architectures - Discord users were confused about which agent type to use - send_message tool and heartbeat references were in mainline docs - architectures_overview.mdx - Landing page explaining legacy types exist - migration_guide.mdx - Step-by-step migration with code snippets - naming_history.mdx - Hidden page explaining progression for LLMs - memgpt_agents_legacy.mdx - Moved from main docs with deprecation warnings - heartbeats_legacy.mdx - Moved from main docs with deprecation warnings - Removed "Agent Architectures" subsection from main nav - Moved "MemGPT Agents" to top-level (renamed "Agent Memory & Architecture") - Removed "Heartbeats" page from main nav - Added "Legacy & Migration" section with 5 sub-pages - Added redirects for old URLs - pages/agents/memgpt_agents.mdx - Completely rewritten to focus on current architecture without mentioning legacy agent types - pages/agents/sleep_time_agents.mdx - Changed from agent_type to enableSleeptime - pages/agents/base_tools.mdx - Added stronger deprecation warning for send_message - pages/agents/overview.mdx - Updated assistant_message description - pages/agents/tool_rules.mdx - Removed send_message default rule examples - pages/agents/message_types.mdx - Removed heartbeat message type section - pages/agents/json_mode.mdx - Removed send_message requirements - pages/agents/archival_best_practices.mdx - Removed send_message tool rule example - pages/agents/react_agents.mdx - Removed heartbeat mechanism reference - pages/getting-started/prompts.mdx - Removed send_message note - pages/ade-guide/simulator.mdx - Removed tip about removing send_message - pages/advanced/custom_memory.mdx - Changed send_message to "respond to user" - pages/deployment/railway.mdx - Removed legacy tools array from example - pages/selfhosting/overview.mdx - Changed send_message example to memory_insert - pages/agents/heartbeats.mdx - Moved to legacy section Added to memory: aggressively remove send_message and heartbeat references from main docs. Keep legacy content only in /guides/legacy/ section. Don't add notes about legacy in main docs - just remove the references entirely. * docs: remove evals tab from navigation The evals content is not ready for public documentation yet. * docs: move send_message to deprecated tools table with legacy link - Removed Legacy Tools section - Added send_message to Deprecated Tools table with link to legacy guide - Removed undefined warning text * docs: move ReAct agents to legacy section - Moved pages/agents/react_agents.mdx to pages/legacy/react_agents_legacy.mdx - Added deprecation warning at top - Updated slug to guides/legacy/react_agents_legacy - Added to Legacy & Migration navigation section - Added redirect from old URL to new legacy location ReAct agents are a legacy architecture that lacks long-term memory capabilities compared to the current Letta architecture. * docs: move workflow and low-latency architectures to legacy - Moved pages/agents/workflows.mdx to pages/legacy/workflows_legacy.mdx - Moved pages/agents/low_latency_agents.mdx to pages/legacy/low_latency_agents_legacy.mdx - Deleted pages/agents/architectures.mdx (overview page no longer needed) - Removed 'Agent Memory & Architecture' from main Agents section - Added workflows and low-latency to Legacy & Migration section - Added redirects for old URLs These agent architectures (workflow_agent, voice_convo_agent) are legacy. For new projects, users should use the current Letta architecture with tool rules or voice-optimized configurations instead. * docs: remove orphaned stateful workflows page - Deleted pages/agents/stateful_workflows.mdx - Page was not linked in navigation or from other docs - Feature (message_buffer_autoclear flag) is already documented in API reference - Avoids confusion with legacy workflow architectures
76 lines
3.1 KiB
Plaintext
76 lines
3.1 KiB
Plaintext
---
|
|
title: Creating custom memory classes
|
|
subtitle: Learn how to create custom memory classes
|
|
slug: guides/agents/custom-memory
|
|
---
|
|
|
|
|
|
## Customizing in-context memory management
|
|
|
|
We can extend both the `BaseMemory` and `ChatMemory` classes to implement custom in-context memory management for agents.
|
|
For example, you can add an additional memory section to "human" and "persona" such as "organization".
|
|
|
|
In this example, we'll show how to implement in-context memory management that treats memory as a task queue.
|
|
We'll call this `TaskMemory` and extend the `ChatMemory` class so that we have both the original `ChatMemory` tools (`core_memory_replace` & `core_memory_append`) as well as the "human" and "persona" fields.
|
|
|
|
We show an implementation of `TaskMemory` below:
|
|
```python
|
|
from letta.memory import ChatMemory, MemoryModule
|
|
from typing import Optional, List
|
|
|
|
class TaskMemory(ChatMemory):
|
|
|
|
def __init__(self, human: str, persona: str, tasks: List[str]):
|
|
super().__init__(human=human, persona=persona)
|
|
self.memory["tasks"] = MemoryModule(limit=2000, value=tasks) # create an empty list
|
|
|
|
|
|
|
|
def task_queue_push(self, task_description: str) -> Optional[str]:
|
|
"""
|
|
Push to a task queue stored in core memory.
|
|
|
|
Args:
|
|
task_description (str): A description of the next task you must accomplish.
|
|
|
|
Returns:
|
|
Optional[str]: None is always returned as this function does not produce a response.
|
|
"""
|
|
self.memory["tasks"].value.append(task_description)
|
|
return None
|
|
|
|
def task_queue_pop(self) -> Optional[str]:
|
|
"""
|
|
Get the next task from the task queue
|
|
|
|
Returns:
|
|
Optional[str]: The description of the task popped from the queue,
|
|
if there are still tasks in queue. Otherwise, returns None (the
|
|
task queue is empty)
|
|
"""
|
|
if len(self.memory["tasks"].value) == 0:
|
|
return None
|
|
task = self.memory["tasks"].value[0]
|
|
self.memory["tasks"].value = self.memory["tasks"].value[1:]
|
|
return task
|
|
```
|
|
|
|
To create an agent with this custom memory type, we can simply pass in an instance of `TaskMemory` into the agent creation.
|
|
We also will modify the persona of the agent to explain how the "tasks" section of memory should be used:
|
|
```python
|
|
task_agent_state = client.create_agent(
|
|
name="task_agent",
|
|
memory=TaskMemory(
|
|
human="My name is Sarah",
|
|
persona="You have an additional section of core memory called `tasks`. " \
|
|
+ "This section of memory contains of list of tasks you must do." \
|
|
+ "Use the `task_queue_push` tool to write down tasks so you don't forget to do them." \
|
|
+ "If there are tasks in the task queue, you should call `task_queue_pop` to retrieve and remove them. " \
|
|
+ "Keep calling `task_queue_pop` until there are no more tasks in the queue. " \
|
|
+ "Do *not* respond to the user until you have completed all tasks in your queue. " \
|
|
+ "If you call `task_queue_pop`, you must always do what the popped task specifies",
|
|
tasks=["start calling yourself Bob", "tell me a haiku with my name"],
|
|
)
|
|
)
|
|
```
|