-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: knowledge base for long-term memory (#1099) #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
|
@a7m-1st @4pmtong @Wendong-Fan Please review my pr. |
bytecii
left a comment
There was a problem hiding this 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.
|
@bytecii I just fixed the issues you mentioned, would you please review the updates again? |
|
@bitloi I don't think they are fixed |
…y, remove remember_this prompt, ruff lint
Sorry for the mistake, I didn't push the changes. |
|
@Wendong-Fan Would you please check the pr? |
…oi/eigent into feature/knowledge-base-1099
Wendong-Fan
left a comment
There was a problem hiding this 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
@Wendong-Fan, thanks for the review! I made the changes you suggested - switched from SQLite to a simple markdown file at |
thanks @bitloi for the update! |
…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
…oi/eigent into feature/knowledge-base-1099
…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
|
@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
…oi/eigent into feature/knowledge-base-1099
|
@nitpicker55555 Can you check the changes again? |
|
@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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| use_project_memory: bool = False | |
| use_long_term_memory: bool = False |
Description
Implements knowledge base for long-term memory (closes #1099).
What this PR does:
file_save_path/.eigent_knowledge/or~/.eigent). Table:project_id,content,created_at. Data persists across sessions.POST /knowledgewithproject_idandcontent. (2)remember_thistool for the developer agent (and custom agents viaknowledge_base_toolkit) so the assistant can save facts when the user asks.LIKE;get_context_for_prompt(project_id, query=...)builds a formatted string (max 4000 chars, 20 entries) for injection into prompts.build_conversation_context()prepends knowledge base context when building prompts. Used for simple-question answers, multi-turn simple path,question_confirm, and workforce context. Optionalquery(user question) filters relevant entries when available.GET /knowledge?project_id=...&query=...&limit=50,DELETE /knowledge/{id}?project_id=....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?