Skip to content

feat: knowledge base for long-term memory (#1099)#1115

Open
bitloi wants to merge 44 commits intoeigent-ai:mainfrom
bitloi:feature/knowledge-base-1099
Open

feat: knowledge base for long-term memory (#1099)#1115
bitloi wants to merge 44 commits intoeigent-ai:mainfrom
bitloi:feature/knowledge-base-1099

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?

@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.

bitloi and others added 2 commits February 14, 2026 20:58
…ory, move tests, add continuation note

- Rename memory_file.py to long_term_memory.py and update logger/imports
- Rename use_project_memory to use_long_term_memory (NewAgent, ActionNewAgent, chat_service)
- Add remaining line count to truncation note in get_index_for_prompt
- Move tests to backend/tests/app/utils/test_long_term_memory.py
- Add comment that memory index is snapshot at agent-creation time
@bitloi
Copy link
Author

bitloi commented Feb 15, 2026

@bytecii Ready for review!

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