Rebase onto upstream (a4d95fd) #12

Closed
wylab wants to merge 144 commits from rebase-onto-upstream into main
3 changed files with 129 additions and 0 deletions
Showing only changes of commit 311e7b5fc6 - Show all commits
@@ -9,6 +9,7 @@ from nanobot.agent.tools.anthropic.base import (
from nanobot.agent.tools.anthropic.bash import BashTool20250124
from nanobot.agent.tools.anthropic.edit import EditTool20250728
from nanobot.agent.tools.anthropic.computer import ComputerTool20251124
from nanobot.agent.tools.anthropic.memory import MemoryTool20250818
__all__ = [
"BaseAnthropicTool",
@@ -18,4 +19,5 @@ __all__ = [
"BashTool20250124",
"EditTool20250728",
"ComputerTool20251124",
"MemoryTool20250818",
]
+92
View File
@@ -0,0 +1,92 @@
"""MemoryTool20250818 - Anthropic's native memory tool.
Enables Claude to create, read, update, and delete files in a persistent
/memories directory across conversations.
"""
from __future__ import annotations
from pathlib import Path
from typing import Any, Literal
from nanobot.agent.tools.anthropic.base import BaseAnthropicTool, CLIResult
class MemoryTool20250818(BaseAnthropicTool):
"""Anthropic's native memory_20250818 tool.
Client-side tool for persistent memory storage across conversations.
All operations are restricted to the /memories directory.
Commands:
- view: Show directory contents or file contents with line numbers
- create: Create a new file with content
- str_replace: Replace unique text occurrence in a file
- insert: Insert text at a specific line number
- delete: Delete a file or directory
- rename: Rename or move a file/directory
"""
api_type: Literal["memory_20250818"] = "memory_20250818"
name: Literal["memory"] = "memory"
beta_flag: str = "context-management-2025-06-27"
def __init__(self, workspace: Path):
"""Initialize Memory tool.
Args:
workspace: Root workspace directory
"""
self.workspace = workspace
self.memories_dir = workspace / "memories"
self.memories_dir.mkdir(parents=True, exist_ok=True)
async def __call__(
self,
command: Literal["view", "create", "str_replace", "insert", "delete", "rename"],
path: str | None = None,
old_path: str | None = None,
new_path: str | None = None,
file_text: str | None = None,
old_str: str | None = None,
new_str: str | None = None,
insert_line: int | None = None,
insert_text: str | None = None,
view_range: list[int] | None = None,
**kwargs: Any,
) -> CLIResult:
"""Execute memory command.
Args:
command: Command to execute
path: File/directory path (for view/create/str_replace/insert/delete)
old_path: Source path (for rename)
new_path: Destination path (for rename)
file_text: File content (for create)
old_str: Text to find (for str_replace)
new_str: Replacement text (for str_replace)
insert_line: Line number to insert at (for insert)
insert_text: Text to insert (for insert)
view_range: [start_line, end_line] for view
**kwargs: Additional arguments (ignored)
Returns:
CLIResult with command output or error
"""
# Placeholder - will implement in later tasks
return CLIResult(
exit_code=1,
output="",
error="Not implemented yet"
)
def to_params(self) -> dict[str, Any]:
"""Convert to Anthropic API tool parameter format.
Returns:
Tool definition for Anthropic API
"""
return {
"type": self.api_type,
"name": self.name,
}
+35
View File
@@ -0,0 +1,35 @@
"""Tests for MemoryTool20250818."""
import pytest
from pathlib import Path
from nanobot.agent.tools.anthropic import MemoryTool20250818
from nanobot.agent.tools.anthropic.base import CLIResult
@pytest.fixture
def temp_workspace(tmp_path):
"""Create temporary workspace."""
return tmp_path
@pytest.fixture
def memory_tool(temp_workspace):
"""Create MemoryTool instance."""
return MemoryTool20250818(workspace=temp_workspace)
def test_memory_tool_initialization(memory_tool, temp_workspace):
"""Test that MemoryTool initializes correctly."""
assert memory_tool.api_type == "memory_20250818"
assert memory_tool.name == "memory"
assert memory_tool.beta_flag == "context-management-2025-06-27"
assert (temp_workspace / "memories").exists()
def test_memory_tool_to_params(memory_tool):
"""Test that to_params returns correct format."""
params = memory_tool.to_params()
assert params == {
"type": "memory_20250818",
"name": "memory"
}