Skip to content

Conversation

@bitloi
Copy link

@bitloi bitloi commented Feb 1, 2026

Description

Implements knowledge base for long-term memory (closes #1099).

What this PR does:

  • Storage: SQLite-backed knowledge store per project (file_save_path/.eigent_knowledge/ or ~/.eigent). Table: project_id, content, created_at. Data persists across sessions.
  • Ingestion: (1) REST API: POST /knowledge with project_id and content. (2) remember_this tool for the developer agent (and custom agents via knowledge_base_toolkit) so the assistant can save facts when the user asks.
  • Retrieval: Keyword filter via LIKE; get_context_for_prompt(project_id, query=...) builds a formatted string (max 4000 chars, 20 entries) for injection into prompts.
  • Integration: build_conversation_context() prepends knowledge base context when building prompts. Used for simple-question answers, multi-turn simple path, question_confirm, and workforce context. Optional query (user question) filters relevant entries when available.
  • REST API: GET /knowledge?project_id=...&query=...&limit=50, DELETE /knowledge/{id}?project_id=....
  • Tests: Unit tests for add/get/delete, keyword query, context formatting, wrong-project no-op, and TestClient API test for POST/GET/DELETE.

No frontend changes; backend-only. Users can add entries via API (e.g. curl) or by asking the developer agent to remember something; retrieved KB is injected into chat context automatically.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

bitloi and others added 15 commits February 1, 2026 02:49
- Add SQLite-backed knowledge store (backend/app/utils/knowledge_base.py)
  with add_entry, get_entries, delete_entry, get_context_for_prompt
- Inject KB context into chat prompts via build_conversation_context
  (query-scoped retrieval when user question is available)
- Add REST API: POST/GET/DELETE /knowledge (knowledge_controller)
- Add remember_this tool (KnowledgeBaseToolkit) for developer agent
  to save facts to the project KB; register in get_toolkits for custom agents
- Developer system message: use remember_this for important facts/decisions
…PI tests

- knowledge_base: use os.environ.get instead of app.component.environment.env
  so tests run from backend/ without repo-root utils
- tests: add test_knowledge_base.py (add/get/delete, query filter, context,
  wrong project no-op) and TestClient API test (POST/GET/DELETE /knowledge)
- Resolve router.py: use main's logging, add knowledge_controller
- Accept deletion of backend/app/utils/agent.py (agent code moved to app/agent/)
- Add knowledge base to new agent module: KnowledgeBaseToolkit in tools.py,
  developer.py (toolkit + tools + tool_names), remember_this in DEVELOPER_SYS_PROMPT
- Rebase KB changes onto upstream main chat_service: add get_knowledge_context
  import, query param and KB block in build_conversation_context, pass query=
  at simple-question, multi-turn simple, and question_confirm call sites
- router.py: align with main style (single-line imports/config), keep knowledge_controller
- chat_service.py: add ActionTimeoutData import for main compatibility, keep knowledge base
@bitloi
Copy link
Author

bitloi commented Feb 4, 2026

@a7m-1st @4pmtong @Wendong-Fan Please review my pr.

Copy link
Collaborator

@bytecii bytecii left a comment

Choose a reason for hiding this comment

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

Thanks for contribution. Left some comments.

@bitloi
Copy link
Author

bitloi commented Feb 4, 2026

@bytecii I just fixed the issues you mentioned, would you please review the updates again?

@bytecii
Copy link
Collaborator

bytecii commented Feb 4, 2026

@bitloi I don't think they are fixed

@bitloi
Copy link
Author

bitloi commented Feb 4, 2026

@bitloi I don't think they are fixed

Sorry for the mistake, I didn't push the changes.

@bitloi bitloi requested a review from bytecii February 4, 2026 22:34
@bitloi
Copy link
Author

bitloi commented Feb 5, 2026

@Wendong-Fan Would you please check the pr?

Copy link
Contributor

@Wendong-Fan Wendong-Fan left a comment

Choose a reason for hiding this comment

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

Thanks @bitloi for working on this feature! Long-term memory is a valuable addition. However, I would second @nitpicker55555 's concerns about the current design approach. SQLite may be too complex and introduce more cost for this use case, a simple .md file would be more appropriate than a database, in camel we also supported skills which would make using .md file system more suitable

the current design's reading would automatically injected into prompts but for writing it will require explicit toolkit call, this inconsistency is confusing. If we use a file like .eigent/memory.md, agents can do both reading and writing.

now the sqlite_toolkit.py is not a Toolkit (doesn't extend BaseToolkit), it's a data access layer. which adds to the confusion around its role and responsibilities

I’d strongly suggest implementing long-term memory using a markdown-based file system for now. Happy to discuss this further and iterate together.

…emory (eigent-ai#1099)

- Replace SQLite implementation with simple .eigent/memory.md file approach
- Add memory_file.py with thread-safe read/write/append operations
- Update KnowledgeBaseToolkit with both read_project_memory and remember_this tools
- Remove knowledge_controller.py REST API (no longer needed)
- Remove sqlite_toolkit.py (replaced by memory_file.py)
- Add comprehensive unit tests with edge case coverage
- Add proper input validation, error handling, and typed parameters

Per reviewer feedback: simpler file-based approach for long-term memory
@bitloi
Copy link
Author

bitloi commented Feb 8, 2026

Thanks @bitloi for working on this feature! Long-term memory is a valuable addition. However, I would second @nitpicker55555 's concerns about the current design approach. SQLite may be too complex and introduce more cost for this use case, a simple .md file would be more appropriate than a database, in camel we also supported skills which would make using .md file system more suitable

the current design's reading would automatically injected into prompts but for writing it will require explicit toolkit call, this inconsistency is confusing. If we use a file like .eigent/memory.md, agents can do both reading and writing.

now the sqlite_toolkit.py is not a Toolkit (doesn't extend BaseToolkit), it's a data access layer. which adds to the confusion around its role and responsibilities

I’d strongly suggest implementing long-term memory using a markdown-based file system for now. Happy to discuss this further and iterate together.

@Wendong-Fan, thanks for the review! I made the changes you suggested - switched from SQLite to a simple markdown file at .eigent/memory.md. Much cleaner now. The toolkit has both read and write tools, and I removed the REST API since it's not needed anymore. Tests are all green. Let me know if anything else needs tweaking!

@bitloi bitloi requested a review from Wendong-Fan February 8, 2026 00:46
@Wendong-Fan
Copy link
Contributor

Thanks @bitloi for working on this feature! Long-term memory is a valuable addition. However, I would second @nitpicker55555 's concerns about the current design approach. SQLite may be too complex and introduce more cost for this use case, a simple .md file would be more appropriate than a database, in camel we also supported skills which would make using .md file system more suitable
the current design's reading would automatically injected into prompts but for writing it will require explicit toolkit call, this inconsistency is confusing. If we use a file like .eigent/memory.md, agents can do both reading and writing.
now the sqlite_toolkit.py is not a Toolkit (doesn't extend BaseToolkit), it's a data access layer. which adds to the confusion around its role and responsibilities
I’d strongly suggest implementing long-term memory using a markdown-based file system for now. Happy to discuss this further and iterate together.

@Wendong-Fan, thanks for the review! I made the changes you suggested - switched from SQLite to a simple markdown file at .eigent/memory.md. Much cleaner now. The toolkit has both read and write tools, and I removed the REST API since it's not needed anymore. Tests are all green. Let me know if anything else needs tweaking!

thanks @bitloi for the update!

@Wendong-Fan Wendong-Fan modified the milestones: Sprint 13, Sprint 14 Feb 8, 2026
…dback)

- memory_file: get_context_for_prompt -> get_index_for_prompt (first max_lines;
  cap at _MAX_INDEX_LINES); add MEMORY_ARCHITECTURE_PROMPT
- knowledge_base_toolkit: remove remember_this/read_project_memory; agent uses
  file ops on .eigent/*.md; get_tools() returns []
- Validation, error handling, and tests updated for index-based design
@bitloi bitloi requested a review from nitpicker55555 February 9, 2026 01:07
…mpt, doc toolkit

- memory_file: remove append_memory, write_memory (unused in production); keep read_memory, get_index_for_prompt
- chat_service: when knowledge_base_toolkit in data.tools, inject MEMORY_ARCHITECTURE_PROMPT and get_index_for_prompt(working_directory) into system prompt
- knowledge_base_toolkit: doc why toolkit has no tools (signal for chat_service to inject memory prompt)
- tests: use _write_memory helper instead of removed append/write_memory
@bitloi bitloi requested a review from nitpicker55555 February 9, 2026 11:29
@bitloi
Copy link
Author

bitloi commented Feb 9, 2026

@nitpicker55555 I fixed them. Would you mind reviewing it?

- Remove KnowledgeBaseToolkit; add use_project_memory to NewAgent and ActionNewAgent
- chat_service injects memory prompt when use_project_memory is true
- Revert build_conversation_context to single-line args (no linter-only changes)
- Regenerate uv.lock without ruff
- Update tests: drop toolkit tests, keep memory_file tests
@bitloi
Copy link
Author

bitloi commented Feb 9, 2026

@nitpicker55555 Can you check the changes again?

@bitloi bitloi requested a review from nitpicker55555 February 9, 2026 18:49
@nitpicker55555
Copy link
Collaborator

@bitloi backend/app/router.py changes are still only linter changes. Please remove these linter changes

@Wendong-Fan what do you think of the current design?

@bitloi
Copy link
Author

bitloi commented Feb 9, 2026

@bitloi backend/app/router.py changes are still only linter changes. Please remove these linter changes

@Wendong-Fan what do you think of the current design?

@nitpicker55555 Fixed it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Move to backend/tests/app/utils/memory_file.py

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename to long_term_memory


lines = content.splitlines()
if len(lines) > effective_max:
index_content = "\n".join(lines[:effective_max]) + _CONTINUATION_NOTE
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:
Add remaining lines information to the _CONTINUATION_NOTE?

enhanced_description += MEMORY_ARCHITECTURE_PROMPT
memory_index = get_index_for_prompt(working_directory)
if memory_index:
enhanced_description += "\n" + memory_index
Copy link
Collaborator

Choose a reason for hiding this comment

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

This memory_index is changing right? I am not sure whether it's proper to add it to the system prompt

mcp_tools: McpServers | None
env_path: str | None = None
custom_model_config: AgentModelConfig | None = None
use_project_memory: bool = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
use_project_memory: bool = False
use_long_term_memory: bool = False

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.

[Feature Request] Support knowledge base for long-term memory

4 participants