Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2c18d7c
feat: knowledge base for long-term memory (issue #1099)
bitloi Feb 1, 2026
d07d875
fix: use os.environ in knowledge_base for testability; add unit and A…
bitloi Feb 1, 2026
f45ca7c
Merge origin/main into feature/knowledge-base-1099
bitloi Feb 1, 2026
ece99c9
fix: resolve chat_service.py conflict with main (keep KB integration)
bitloi Feb 1, 2026
852ab43
Merge upstream/main, resolve chat_service.py (keep KB integration)
bitloi Feb 1, 2026
f678309
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 1, 2026
3b9c0e4
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 1, 2026
3d10e6d
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 2, 2026
47f4f10
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 3, 2026
fbd480b
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 3, 2026
b7af46a
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 3, 2026
7216ce8
fix: resolve merge conflicts with main (router.py, chat_service.py)
bitloi Feb 4, 2026
4e2dcb2
Merge upstream/main into feature/knowledge-base-1099, resolve conflicts
bitloi Feb 4, 2026
c363187
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 4, 2026
3d2f4b6
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 4, 2026
d328676
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 4, 2026
b2fd959
PR feedback: rename to sqlite_toolkit, FTS5/BM25 search, add tool onl…
bitloi Feb 4, 2026
70cd6df
Remove knowledge base from developer agent for now (per review)
bitloi Feb 4, 2026
b4bfc4e
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 4, 2026
e195c47
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 5, 2026
dd804f2
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 5, 2026
606533f
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 5, 2026
06d19b1
Merge branch 'main' into feature/knowledge-base-1099
Wendong-Fan Feb 5, 2026
b4fba05
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 5, 2026
1b0f125
PR feedback: remove KB from chat context, rename tool to store_projec…
bitloi Feb 6, 2026
e134793
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 6, 2026
52d06b2
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 6, 2026
3086710
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 6, 2026
a275992
Merge upstream/main into feature/knowledge-base-1099
bitloi Feb 7, 2026
ba023f5
Merge branch 'feature/knowledge-base-1099' of https://github.com/bitl…
bitloi Feb 7, 2026
8d8b573
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 7, 2026
3564835
refactor(knowledge-base): switch from SQLite to markdown file-based m…
bitloi Feb 8, 2026
60367cb
Merge branch 'main' into feature/knowledge-base-1099
nitpicker55555 Feb 8, 2026
b2d810a
refactor(memory): index-only prompt, no dedicated tools (reviewer fee…
bitloi Feb 9, 2026
3bd0880
Merge branch 'feature/knowledge-base-1099' of https://github.com/bitl…
bitloi Feb 9, 2026
0971ae6
Address nitpicker55555 review: remove unused memory helpers, wire pro…
bitloi Feb 9, 2026
4cbdaf2
chore(backend): remove ruff from dev dependencies
bitloi Feb 9, 2026
7e7991e
Merge branch 'main' into feature/knowledge-base-1099
bitloi Feb 9, 2026
516caa2
Replace knowledge_base_toolkit with use_project_memory flag
bitloi Feb 9, 2026
d000b44
Merge branch 'feature/knowledge-base-1099' of https://github.com/bitl…
bitloi Feb 9, 2026
dafac62
Revert linter-only changes in router.py (review feedback)
bitloi Feb 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/app/agent/factory/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from app.service.task import Agents
from app.utils.file_utils import get_working_directory
from app.utils.toolkit.human_toolkit import HumanToolkit
from app.utils.toolkit.knowledge_base_toolkit import KnowledgeBaseToolkit

# TODO: Remove NoteTakingToolkit and use TerminalToolkit instead
from app.utils.toolkit.note_taking_toolkit import NoteTakingToolkit
Expand Down Expand Up @@ -69,6 +70,10 @@ async def developer_agent(options: Chat):
clone_current_env=True,
)
terminal_toolkit = message_integration.register_toolkits(terminal_toolkit)
knowledge_base_toolkit = KnowledgeBaseToolkit(
api_task_id=options.project_id,
agent_name=Agents.developer_agent,
)

tools = [
*HumanToolkit.get_can_use_tools(
Expand All @@ -78,6 +83,7 @@ async def developer_agent(options: Chat):
*web_deploy_toolkit.get_tools(),
*terminal_toolkit.get_tools(),
*screenshot_toolkit.get_tools(),
*knowledge_base_toolkit.get_tools(),
]
system_message = DEVELOPER_SYS_PROMPT.format(
platform_system=platform.system(),
Expand All @@ -99,5 +105,6 @@ async def developer_agent(options: Chat):
TerminalToolkit.toolkit_name(),
NoteTakingToolkit.toolkit_name(),
WebDeployToolkit.toolkit_name(),
KnowledgeBaseToolkit.toolkit_name(),
],
)
3 changes: 3 additions & 0 deletions backend/app/agent/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@

<mandatory_instructions>
- You MUST use the `read_note` tool to read the ALL notes from other agents.
- Use the `remember_this` tool to save important facts, decisions, or preferences
to the project's long-term knowledge base when the user or task establishes
something that should be remembered for future conversations.

You SHOULD keep the user informed by providing message_title and message_description
parameters when calling tools. These optional parameters are available on all tools
Expand Down
2 changes: 2 additions & 0 deletions backend/app/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from app.utils.toolkit.google_drive_mcp_toolkit import GoogleDriveMCPToolkit
from app.utils.toolkit.google_gmail_mcp_toolkit import GoogleGmailMCPToolkit
from app.utils.toolkit.image_analysis_toolkit import ImageAnalysisToolkit
from app.utils.toolkit.knowledge_base_toolkit import KnowledgeBaseToolkit
from app.utils.toolkit.lark_toolkit import LarkToolkit
from app.utils.toolkit.linkedin_toolkit import LinkedInToolkit
from app.utils.toolkit.mcp_search_toolkit import McpSearchToolkit
Expand Down Expand Up @@ -62,6 +63,7 @@ async def get_toolkits(tools: list[str], agent_name: str, api_task_id: str):
"google_drive_mcp_toolkit": GoogleDriveMCPToolkit,
"google_gmail_mcp_toolkit": GoogleGmailMCPToolkit,
"image_analysis_toolkit": ImageAnalysisToolkit,
"knowledge_base_toolkit": KnowledgeBaseToolkit,
"linkedin_toolkit": LinkedInToolkit,
"lark_toolkit": LarkToolkit,
"mcp_search_toolkit": McpSearchToolkit,
Expand Down
88 changes: 88 additions & 0 deletions backend/app/controller/knowledge_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========

from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel, Field

from app.utils.knowledge_base import add_entry, get_entries, delete_entry

router = APIRouter(prefix="/knowledge", tags=["Knowledge Base"])


class KnowledgeAddIn(BaseModel):
"""Request body for adding a knowledge entry."""

project_id: str = Field(..., description="Project ID (scope for this entry)")
content: str = Field(..., min_length=1, description="Content to store as long-term memory")


class KnowledgeAddOut(BaseModel):
"""Response after adding a knowledge entry."""

id: int
project_id: str
message: str = "Knowledge entry added"


class KnowledgeEntryOut(BaseModel):
"""A single knowledge entry."""

id: int
project_id: str
content: str
created_at: float


@router.post("", name="add knowledge", response_model=KnowledgeAddOut)
async def knowledge_add(body: KnowledgeAddIn):
"""Add a knowledge entry for long-term memory (issue #1099)."""
try:
entry_id = add_entry(project_id=body.project_id, content=body.content)
return KnowledgeAddOut(id=entry_id, project_id=body.project_id)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))


@router.get("", name="list knowledge")
async def knowledge_list(
project_id: str = Query(..., description="Project ID"),
query: str | None = Query(None, description="Optional keyword filter"),
limit: int = Query(50, ge=1, le=200, description="Max entries to return"),
):
"""List knowledge entries for a project, optionally filtered by keyword."""
try:
entries = get_entries(project_id=project_id, query=query, limit=limit)
return {"project_id": project_id, "entries": entries}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))


@router.delete("/{entry_id}", name="delete knowledge")
async def knowledge_delete(
entry_id: int,
project_id: str = Query(..., description="Project ID"),
):
"""Delete a knowledge entry by id (scoped to project)."""
try:
deleted = delete_entry(project_id=project_id, entry_id=entry_id)
if not deleted:
raise HTTPException(
status_code=404,
detail=f"Knowledge entry {entry_id} not found for project {project_id}",
)
return {"deleted": True, "id": entry_id}
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
14 changes: 8 additions & 6 deletions backend/app/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
# ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
"""
Centralized router registration for the Eigent API.
All routers are explicitly registered here
for better visibility and maintainability.
All routers are explicitly registered here for better visibility and maintainability.
"""

import logging

from fastapi import FastAPI

from app.controller import (
chat_controller,
health_controller,
knowledge_controller,
model_controller,
task_controller,
tool_controller,
Expand Down Expand Up @@ -71,6 +70,11 @@ def register_routers(app: FastAPI, prefix: str = "") -> None:
"tags": ["tool"],
"description": "Tool installation and management",
},
{
"router": knowledge_controller.router,
"tags": ["Knowledge Base"],
"description": "Knowledge base for long-term memory (issue #1099)",
},
]

for config in routers_config:
Expand All @@ -79,9 +83,7 @@ def register_routers(app: FastAPI, prefix: str = "") -> None:
)
route_count = len(config["router"].routes)
logger.info(
f"Registered {config['tags'][0]} router:"
f" {route_count} routes -"
f" {config['description']}"
f"Registered {config['tags'][0]} router: {route_count} routes - {config['description']}"
)

logger.info(f"Total routers registered: {len(routers_config)}")
38 changes: 32 additions & 6 deletions backend/app/service/chat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@
ActionImproveData,
ActionInstallMcpData,
ActionNewAgent,
ActionTimeoutData,
Agents,
TaskLock,
delete_task_lock,
set_current_task_id,
)
from app.utils.event_loop_utils import set_main_event_loop
from app.utils.file_utils import get_working_directory
from app.utils.knowledge_base import get_context_for_prompt as get_knowledge_context
from app.utils.server.sync_step import sync_step
from app.utils.telemetry.workforce_metrics import WorkforceMetricsCallback
from app.utils.toolkit.human_toolkit import HumanToolkit
Expand Down Expand Up @@ -235,24 +237,43 @@ def check_conversation_history_length(


def build_conversation_context(
task_lock: TaskLock, header: str = "=== CONVERSATION HISTORY ==="
task_lock: TaskLock,
header: str = "=== CONVERSATION HISTORY ===",
query: str | None = None,
) -> str:
"""Build conversation context from task_lock history
with files listed only once at the end.
Prepends knowledge base (long-term memory) entries when available.

Args:
task_lock: TaskLock containing conversation history
header: Header text for the context section
query: Optional user query to filter relevant knowledge base entries

Returns:
Formatted context string with task history
and files listed once at the end
Formatted context string with knowledge base (if any),
task history and files listed once at the end
"""
context = ""
try:
kb_context = get_knowledge_context(
project_id=task_lock.id,
query=query,
max_chars=4000,
limit_entries=20,
)
if kb_context:
context = kb_context
except Exception as e:
logger.warning(
"Failed to load knowledge base context",
extra={"error": str(e)},
)

working_directories = set() # Collect all unique working directories

if task_lock.conversation_history:
context = f"{header}\n"
context += f"{header}\n"

for entry in task_lock.conversation_history:
if entry["role"] == "task_result":
Expand Down Expand Up @@ -531,7 +552,9 @@ async def step_solve(options: Chat, request: Request, task_lock: TaskLock):
"without workforce"
)
conv_ctx = build_conversation_context(
task_lock, header="=== Previous Conversation ==="
task_lock,
header="=== Previous Conversation ===",
query=question,
)
simple_answer_prompt = (
f"{conv_ctx}"
Expand Down Expand Up @@ -1222,6 +1245,7 @@ async def run_decomposition():
conv_ctx = build_conversation_context(
task_lock,
header="=== Previous Conversation ===",
query=new_task_content,
)
simple_answer_prompt = (
f"{conv_ctx}"
Expand Down Expand Up @@ -1945,7 +1969,9 @@ async def question_confirm(
context_prompt = ""
if task_lock:
context_prompt = build_conversation_context(
task_lock, header="=== Previous Conversation ==="
task_lock,
header="=== Previous Conversation ===",
query=prompt,
)

full_prompt = f"""{context_prompt}User Query: {prompt}
Expand Down
Loading