Skip to content

Add search, update, categories, and default path to memory tool#1971

Open
nunocoracao wants to merge 4 commits intomainfrom
memory-improvements
Open

Add search, update, categories, and default path to memory tool#1971
nunocoracao wants to merge 4 commits intomainfrom
memory-improvements

Conversation

@nunocoracao
Copy link
Contributor

Summary

  • Search: New search_memories tool with keyword search (multi-word AND logic, case-insensitive) and optional category filter
  • Update: New update_memory tool to edit existing memories by ID (no more delete + re-add)
  • Categories: Optional category field on memories for organization (e.g. preference, fact, project)
  • Default path: Memory DB defaults to ~/.cagent/memory/<config-name>/memory.db - per-user, per-agent-config. Path is no longer required in YAML config
  • ToolsetCreator signature: Added configName parameter derived from the agent config file name, used by memory tool for per-config storage
  • Transparent migration: Existing SQLite databases get the category column added automatically

All existing tools (add_memory, get_memories, delete_memory) are unchanged. Existing databases and configs work without modification.

Test plan

  • go build ./... passes
  • go test ./pkg/memory/... ./pkg/tools/builtin/... ./pkg/teamloader/... ./pkg/config/... ./pkg/creator/... ./pkg/acp/... all pass
  • Manual test: docker-agent run with - type: memory (no path) creates DB at ~/.cagent/memory/<config>/memory.db
  • Manual test: search, update, category tools work end-to-end
  • Manual test: existing DB with memories migrates transparently (category column added)

Generated with Claude Code

- Add search_memories tool (keyword search with AND logic, optional category filter)
- Add update_memory tool (edit existing memories by ID)
- Add optional category field to memories for organization
- Default memory path to ~/.cagent/memory/<config-name>/memory.db (per-user, per-agent-config)
- Make path optional in config validation (was required, now defaults)
- Add configName parameter to ToolsetCreator for per-config-file identity
- SQLite migration adds category column transparently to existing databases
- Expand tool instructions with guidance on search vs get_all, update vs create

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nunocoracao nunocoracao requested a review from a team as a code owner March 6, 2026 15:26
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Assessment: 🔴 CRITICAL

Found 2 issues in the changed code that should be addressed:

  • 1 HIGH severity issue: Path traversal vulnerability
  • 1 MEDIUM severity issue: SQL wildcard escaping bug

Summary

This PR adds useful search, update, and category features to the memory tool. However, there are two bugs in the changed code:

  1. Path traversal vulnerability in configNameFromSource() - The function doesn't prevent ".." as a config name, which could allow directory traversal when constructing the memory DB path.

  2. SQL wildcard escaping in SearchMemories() - User input containing SQL wildcards (%, _) is not escaped before being used in LIKE patterns, preventing users from searching for strings containing these characters.

Both issues are in newly added code and should be fixed before merging.


This review was generated automatically. It only comments on code added in this PR.

Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Assessment: 🟡 NEEDS ATTENTION

Found 2 medium-severity issues in the changed code that should be addressed:

  1. Database migration error handling: Silent failures during schema migration could leave the database in an inconsistent state
  2. Memory database collision: Multiple agent configs with similar names could unintentionally share the same memory database

Both issues are in new code added by this PR. The features (search, update, categories, default paths) are well-designed overall, but these edge cases should be handled to prevent potential data integrity and isolation issues.

Findings: 2 medium severity issues


Review performed by cagent - automated code review bot

…rs, config collisions

- Reject ".." in configNameFromSource to prevent directory traversal
- Escape SQL wildcards (%, _, \) in LIKE patterns with ESCAPE clause
- Only ignore "duplicate column name" errors during migration, surface real failures
- Append short SHA-256 hash of full source path to config name to prevent collisions
  between identically named configs in different directories

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dgageot
Copy link
Member

dgageot commented Mar 6, 2026

@nunocoracao the v* packages are frozen. They shouldn't be changed. Only the latest config needs to be changed

Only pkg/config/latest/validate.go retains the optional path change.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nunocoracao
Copy link
Contributor Author

Good catch - reverted the v2-v5 changes. Only latest/validate.go is modified now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants