diff options
| author | batsumaru <> | 2026-09-14 17:21:33 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-09-14 17:21:33 +0900 |
| commit | a3e492d29c4ebb59a11dd6d6ffd1be04dca6834e (patch) | |
| tree | dcf9d474df6ced69b92c90656a1557b46f38354b /tools.py | |
| parent | e1d19cd60dd03b21617c09d3c535ef340a01fab1 (diff) | |
Added more memory management
Diffstat (limited to 'tools.py')
| -rw-r--r-- | tools.py | 121 |
1 files changed, 121 insertions, 0 deletions
@@ -61,6 +61,55 @@ class ToolRegistry: ] +class TaskStartTool(Tool): + def __init__(self, memory: WorkingMemory) -> None: + self.memory = memory + + @property + def name(self) -> str: + return "task_start" + + @property + def description(self) -> str: + return ( + "Record the user's ongoing project or goal as the current task. " + "Use this when the user intends to work on something across multiple " + "turns or over a period of time. Do not use it for one-off requests " + "or temporary side conversations." + ) + + @property + def schema(self) -> dict[str, object]: + return { + "type": "object", + "properties": { + "objective": { + "type": "string", + "description": ( + "A concise description of the ongoing objective the user wants " + "to pursue. For example: 'Build an image tagging API' or " + "'Design and implement a Rust CLI that converts directory trees " + "into static HTML.'" + ), + }, + }, + "required": ["objective"], + } + + def execute(self, arguments: dict[str, object]) -> ToolResult: + objective = arguments.get("objective") + + if not isinstance(objective, str): + raise ToolError("objective must be a string") + + if not objective.strip(): + raise ToolError("objective must not be empty") + + self.memory.start_task(objective) + + return ToolResult(content=f"Started task: {objective}") + + class MemoryAddFactTool(Tool): def __init__(self, memory: WorkingMemory) -> None: self.memory = memory @@ -133,6 +182,78 @@ class MemoryAddNoteTool(Tool): return ToolResult(content=f"Added working-memory note: {note}") +class MemoryRemoveFactTool(Tool): + def __init__(self, memory: WorkingMemory) -> None: + self.memory = memory + + @property + def name(self) -> str: + return "memory_remove_fact" + + @property + def description(self) -> str: + return "Remove a fact from the working memory when it is no longer true or relevant." + + @property + def schema(self) -> dict[str, object]: + return { + "type": "object", + "properties": { + "fact": { + "type": "string", + "description": "The exact fact to remove from working memory.", + }, + }, + "required": ["fact"], + } + + def execute(self, arguments: dict[str, object]) -> ToolResult: + fact = arguments.get("fact") + + if not isinstance(fact, str): + raise ToolError("fact must be a string") + + self.memory.add_fact(fact) + + return ToolResult(content=f"Removed fact: {fact}") + + +class MemoryRemoveNoteTool(Tool): + def __init__(self, memory: WorkingMemory) -> None: + self.memory = memory + + @property + def name(self) -> str: + return "memory_remove_note" + + @property + def description(self) -> str: + return "Remove a note from the working memory when it is no longer true or relevant." + + @property + def schema(self) -> dict[str, object]: + return { + "type": "object", + "properties": { + "note": { + "type": "string", + "description": "The exact note to remove from working memory.", + }, + }, + "required": ["note"], + } + + def execute(self, arguments: dict[str, object]) -> ToolResult: + note = arguments.get("note") + + if not isinstance(note, str): + raise ToolError("note must be a string") + + self.memory.add_note(note) + + return ToolResult(content=f"Removed note: {note}") + + class HelloTool(Tool): @property def name(self) -> str: |
