feat(memory): implement core memory and agentic components#67
Merged
feat(memory): implement core memory and agentic components#67
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request introduces a foundational memory system for our agentic "brain" component. This is the first step towards building stateful, multi-step agents by providing a structured way to record and replay an agent's history.
Refer to #64
classDiagram direction LR class AgentMemory { system_prompt: SystemPromptStep steps: list[MemoryStep] +reset() +get_succinct_steps() +get_full_steps() +replay(logger, detailed) } class MemoryStep { +dict() +to_messages(summary_mode) } class SystemPromptStep { system_prompt: str } class TaskStep { task: str task_images: list[Image]? } class PlanningStep { plan: str model_input_messages: list[ChatMessage] model_output_message: ChatMessage timing: Timing } class ActionStep { step_number: int model_input_messages: list[ChatMessage]? tool_calls: list[ToolCall]? model_output: str | list[dict]? observations: str? token_usage: TokenUsage? } class FinalAnswerStep { output: Any } class CallbackRegistry { +register(step_cls, callback) +callback(memory_step, **kwargs) } class ToolCall { name: str id: str arguments: Any } class ChatMessage { role: MessageRole content: str | list[dict] } class MessageRole class Timing class TokenUsage class AgentLogger AgentMemory --> SystemPromptStep AgentMemory --> MemoryStep AgentMemory --> AgentLogger AgentMemory --> CallbackRegistry MemoryStep <|-- SystemPromptStep MemoryStep <|-- TaskStep MemoryStep <|-- PlanningStep MemoryStep <|-- ActionStep MemoryStep <|-- FinalAnswerStep ActionStep --> ToolCall ActionStep --> ChatMessage ActionStep --> Timing ActionStep --> TokenUsage PlanningStep --> ChatMessage TaskStep --> ChatMessageKey Changes
Memory System (
quantmind/brain/memory.py):Memoryclass to store a sequential timeline of an agent's actions, including tasks, tool calls, and planning steps.CallbackRegistryto allow for hooking into different stages of an agent's execution.Structured Data Models (
quantmind/models/):ActionStep,TaskStep,PlanningStep,ChatMessage, etc.) to provide a strongly-typed representation of the agent's history and message formats.Agentic Utilities (
quantmind/utils/):AgentLogger,TokenUsage,Timing), error handling (AgentErrorsubclasses), and data parsing.AgentLoggerleverages therichlibrary for enhanced, readable console output.Examples & Tests:
examples/memory/basic_memory_usage.py) demonstrating how to construct and inspect a memory timeline.Documentation (
AGENTS.md):Implementation Notes
Memorystore from the immutableMemoryStepdata models, promoting clarity and easier state management.replaymethod in theMemoryclass, combined withAgentLogger, provides powerful debugging capabilities by visualizing the agent's entire run history.agentic_ext.pyandmessages.pyare adapted from common agentic frameworks to provide a robust foundation for future development.Checklist
Please feel free to remove inapplicable items for your PR.
$CATEGORY(xx): xxx(such asfeat(tool): xxx,fix(source): xxx,docs(README): xxx)