mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-12-04 01:18:39 +00:00
The document_query tool logs its message as its own `document_query` type with an `icon://manage_search Querying: <document>` headline when queries are supplied and `Reading: <document>` without them, naming the first document and appending `+ N more` for multi-document queries. A plugin message handler renders it as a DOC badge with blue and blue-violet accents across modes, each clearly bluer than the a2a chat family so document queries read like the other dedicated tool surfaces. Agent-facing failure messages render from plugin prompt files, and the Q&A answer streams into the tool log while the model writes it; helpers built without the streaming callback still answer without streaming. Regression tests cover the log entry, headline words, and empty-query reading mode. Validation: pytest tests/test_document_query_tool_ui.py tests/test_document_query_fallback.py
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
from plugins._document_query.tools.document_query import DocumentQueryTool
|
|
|
|
PROMPTS = Path("plugins/_document_query/prompts")
|
|
|
|
|
|
class _FakeLog:
|
|
def log(self, **kwargs) -> dict:
|
|
return kwargs
|
|
|
|
|
|
class _FakeAgent:
|
|
def __init__(self) -> None:
|
|
self.context = SimpleNamespace(log=_FakeLog())
|
|
|
|
def read_prompt(self, name: str, **kwargs) -> str:
|
|
text = (PROMPTS / name).read_text(encoding="utf-8")
|
|
for key, value in kwargs.items():
|
|
text = text.replace("{{" + key + "}}", str(value))
|
|
return text.strip()
|
|
|
|
|
|
def _make_tool(args: dict) -> DocumentQueryTool:
|
|
return DocumentQueryTool(
|
|
agent=_FakeAgent(), name="document_query", method="execute", args=args, message="", loop_data=None
|
|
)
|
|
|
|
|
|
def test_log_object_passes_document_through():
|
|
tool = _make_tool({"document": "https://example.com/docs/report.pdf", "query": "summary"})
|
|
|
|
entry = tool.get_log_object()
|
|
|
|
assert entry["type"] == "document_query"
|
|
assert entry["heading"] == "icon://manage_search Querying: report.pdf"
|
|
assert entry["kvps"]["document"] == "https://example.com/docs/report.pdf"
|
|
assert entry["kvps"]["query"] == "summary"
|
|
|
|
|
|
def test_get_heading_lists_first_document_and_count():
|
|
assert _make_tool({}).get_heading() == "icon://manage_search Reading"
|
|
assert _make_tool({"document": ["https://example.com/a.pdf", "https://example.com/b.pdf"]}).get_heading() == "icon://manage_search Reading: a.pdf + 1 more"
|
|
assert _make_tool({"document": ["https://example.com/a.pdf", "https://example.com/b.pdf"], "queries": ["total"]}).get_heading() == "icon://manage_search Querying: a.pdf + 1 more"
|
|
|
|
|
|
def test_empty_queries_read_documents():
|
|
assert _make_tool({"document": "https://example.com/a.pdf", "queries": []}).get_heading() == "icon://manage_search Reading: a.pdf"
|
|
assert _make_tool({"document": "https://example.com/a.pdf", "query": ""}).get_heading() == "icon://manage_search Reading: a.pdf"
|