mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 06:12:49 +00:00
Rewrite the default/creative/strict presets (classic + agentic) into
structured sections: grounding and cite-by-title guidance, insufficient-
context behavior, current date, respond-in-user-language, scoped mermaid
usage, an untrusted-content guardrail, and a conditional XML-tagged
document context block. A memory directory listing is injected at render
time via the template prefetch mechanism so the model starts oriented
without burning a tool call.
Fixes along the way:
- Agentic preset swap was dead code: _get_prompt_content cached the
classic preset before create_agent's swap check ran, so agentic and
research agents always got the classic preset. The swap now happens
inside _get_prompt_content.
- Jinja autoescape corrupted document content in custom prompts
(< -> <); prompts are not HTML, autoescape is now off.
- Literal {summaries} leaked into the prompt when no docs were
retrieved; the placeholder is now stripped.
- Agentic/research prompts referenced tool names from a dropped naming
scheme (search_internal, reason_think); they now reference the real
names (search, reason).
- The strict preset told the model to "be very creative and use your
imagination" right after "never make up information".
- extract_tool_usages recorded intermediate attribute chains as
bare-tool usages, which meant "run all actions" at prefetch; only
maximal chains are recorded now.
- Headless runs retrieved docs but never rendered them into the
prompt; the prompt is now rendered like the streaming path.
- Default tools were unreachable by name in prompt templates
(prefetch results were keyed by synthetic id only); defaults now
claim the name key unless an explicit row shadows it.
Tool layer: memory/notes/todo actions are namespaced (memory_view,
note_overwrite, todo_create, ...) with legacy unprefixed names still
accepted via prefix stripping; duplicate action names across tools are
disambiguated with the owning tool's name instead of numeric suffixes;
thin tool descriptions rewritten (brave, duckduckgo, telegram, ntfy,
cryptoprice, read_webpage, internal_search, think).
Docs are now wrapped per chunk in <document index>/<source>/<content>
tags for citation-by-title support.
90 lines
2.5 KiB
Python
90 lines
2.5 KiB
Python
"""Tests for application/agents/tools/notes.py using pg_conn."""
|
|
|
|
from contextlib import contextmanager
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
@contextmanager
|
|
def _patch_db(conn):
|
|
@contextmanager
|
|
def _yield():
|
|
yield conn
|
|
|
|
with patch(
|
|
"application.storage.db.session.db_readonly", _yield
|
|
), patch(
|
|
"application.storage.db.session.db_session", _yield
|
|
):
|
|
yield
|
|
|
|
|
|
def _make_tool(tool_id="default_test", user_id="u"):
|
|
from application.agents.tools.notes import NotesTool
|
|
tool = NotesTool.__new__(NotesTool)
|
|
tool.tool_id = tool_id
|
|
tool.user_id = user_id
|
|
tool._last_artifact_id = None
|
|
return tool
|
|
|
|
|
|
class TestNotesToolPgEnabled:
|
|
def test_returns_false_no_tool_id(self):
|
|
tool = _make_tool(tool_id=None)
|
|
assert tool._pg_enabled() is False
|
|
|
|
def test_returns_false_default_prefix(self):
|
|
tool = _make_tool(tool_id="default_test")
|
|
assert tool._pg_enabled() is False
|
|
|
|
def test_returns_false_non_uuid(self):
|
|
tool = _make_tool(tool_id="not-a-uuid")
|
|
assert tool._pg_enabled() is False
|
|
|
|
def test_returns_true_for_uuid(self):
|
|
import uuid as _uuid
|
|
tool = _make_tool(tool_id=str(_uuid.uuid4()))
|
|
assert tool._pg_enabled() is True
|
|
|
|
|
|
class TestNotesToolExecuteGuards:
|
|
def test_no_user_id_returns_error(self):
|
|
tool = _make_tool()
|
|
tool.user_id = None
|
|
assert "valid user_id" in tool.execute_action("view")
|
|
|
|
def test_not_pg_enabled_returns_error(self):
|
|
tool = _make_tool(tool_id="default_abc")
|
|
msg = tool.execute_action("view")
|
|
assert "not configured" in msg
|
|
|
|
def test_unknown_action(self, pg_conn):
|
|
# Real tool_id requires a user_tools row
|
|
from application.storage.db.repositories.user_tools import (
|
|
UserToolsRepository,
|
|
)
|
|
UserToolsRepository(pg_conn).create("u", "notes_tool")
|
|
# Use a uuid that has notes_tool rows
|
|
tool_row = UserToolsRepository(pg_conn).list_for_user("u")[0]
|
|
tool = _make_tool(tool_id=str(tool_row["id"]))
|
|
with _patch_db(pg_conn):
|
|
got = tool.execute_action("bogus_action")
|
|
assert "Unknown action" in got
|
|
|
|
|
|
class TestNotesActionsMetadata:
|
|
def test_returns_list(self):
|
|
tool = _make_tool()
|
|
got = tool.get_actions_metadata()
|
|
assert isinstance(got, list)
|
|
names = {a["name"] for a in got}
|
|
assert names >= {
|
|
"note_view",
|
|
"note_overwrite",
|
|
"note_str_replace",
|
|
"note_insert",
|
|
"note_delete",
|
|
}
|
|
|
|
|