Skip to content

Commit 95011fb

Browse files
committed
Normalize get_page_content tool naming
The Q&A agent had an odd naming wart: the helper in openkb.agent.tools was called get_page_content (no wiki_ prefix like its siblings read_wiki_file, list_wiki_files, read_wiki_image, write_wiki_file), so the @function_tool wrapper had to be named get_page_content_tool and do a lazy local import to avoid a name collision. The instructions template meanwhile referred to the tool as get_page_content — a third name — leaving three spellings for one concept. Rename the helper to get_wiki_page_content so it matches the wiki_ convention, rename the wrapper to get_page_content so the tool name the model sees matches what the instructions have always said, and drop the lazy-import workaround. Update the test imports, call sites, class name, and the one assertion in test_query that was still checking for the old wrapper name (that assertion was already broken by earlier work).
1 parent b50ad42 commit 95011fb

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

openkb/agent/query.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from agents import Agent, Runner, function_tool
77

88
from agents import ToolOutputImage, ToolOutputText
9-
from openkb.agent.tools import read_wiki_file, read_wiki_image
9+
from openkb.agent.tools import get_wiki_page_content, read_wiki_file, read_wiki_image
1010

1111
MAX_TURNS = 50
1212
from openkb.schema import get_agents_md
@@ -55,16 +55,15 @@ def read_file(path: str) -> str:
5555
return read_wiki_file(path, wiki_root)
5656

5757
@function_tool
58-
def get_page_content_tool(doc_name: str, pages: str) -> str:
58+
def get_page_content(doc_name: str, pages: str) -> str:
5959
"""Get text content of specific pages from a PageIndex (long) document.
6060
Only use for documents with doc_type: pageindex. For short documents,
6161
use read_file instead.
6262
Args:
6363
doc_name: Document name (e.g. 'attention-is-all-you-need').
6464
pages: Page specification (e.g. '3-5,7,10-12').
6565
"""
66-
from openkb.agent.tools import get_page_content
67-
return get_page_content(doc_name, pages, wiki_root)
66+
return get_wiki_page_content(doc_name, pages, wiki_root)
6867

6968
@function_tool
7069
def get_image(image_path: str) -> ToolOutputImage | ToolOutputText:
@@ -86,7 +85,7 @@ def get_image(image_path: str) -> ToolOutputImage | ToolOutputText:
8685
return Agent(
8786
name="wiki-query",
8887
instructions=instructions,
89-
tools=[read_file, get_page_content_tool, get_image],
88+
tools=[read_file, get_page_content, get_image],
9089
model=f"litellm/{model}",
9190
model_settings=ModelSettings(parallel_tool_calls=False),
9291
)

openkb/agent/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def parse_pages(pages: str) -> list[int]:
8989
return sorted(n for n in result if n > 0)
9090

9191

92-
def get_page_content(doc_name: str, pages: str, wiki_root: str) -> str:
92+
def get_wiki_page_content(doc_name: str, pages: str, wiki_root: str) -> str:
9393
"""Return formatted content for specified pages of a document.
9494
9595
Reads ``{wiki_root}/sources/{doc_name}.json`` which must be a JSON array of

tests/test_agent_tools.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from openkb.agent.tools import get_page_content, list_wiki_files, parse_pages, read_wiki_file, write_wiki_file
8+
from openkb.agent.tools import get_wiki_page_content, list_wiki_files, parse_pages, read_wiki_file, write_wiki_file
99

1010

1111
# ---------------------------------------------------------------------------
@@ -159,11 +159,11 @@ def test_ignores_zero_and_negative(self):
159159

160160

161161
# ---------------------------------------------------------------------------
162-
# get_page_content
162+
# get_wiki_page_content
163163
# ---------------------------------------------------------------------------
164164

165165

166-
class TestGetPageContent:
166+
class TestGetWikiPageContent:
167167
def test_reads_pages_from_json(self, tmp_path):
168168
import json
169169
wiki_root = str(tmp_path)
@@ -175,7 +175,7 @@ def test_reads_pages_from_json(self, tmp_path):
175175
{"page": 3, "content": "Page three text."},
176176
]
177177
(sources / "paper.json").write_text(json.dumps(pages), encoding="utf-8")
178-
result = get_page_content("paper", "1,3", wiki_root)
178+
result = get_wiki_page_content("paper", "1,3", wiki_root)
179179
assert "[Page 1]" in result
180180
assert "Page one text." in result
181181
assert "[Page 3]" in result
@@ -185,7 +185,7 @@ def test_reads_pages_from_json(self, tmp_path):
185185
def test_returns_error_for_missing_file(self, tmp_path):
186186
wiki_root = str(tmp_path)
187187
(tmp_path / "sources").mkdir()
188-
result = get_page_content("nonexistent", "1", wiki_root)
188+
result = get_wiki_page_content("nonexistent", "1", wiki_root)
189189
assert "not found" in result.lower()
190190

191191
def test_returns_error_for_no_matching_pages(self, tmp_path):
@@ -195,7 +195,7 @@ def test_returns_error_for_no_matching_pages(self, tmp_path):
195195
sources.mkdir()
196196
pages = [{"page": 1, "content": "Only page."}]
197197
(sources / "paper.json").write_text(json.dumps(pages), encoding="utf-8")
198-
result = get_page_content("paper", "99", wiki_root)
198+
result = get_wiki_page_content("paper", "99", wiki_root)
199199
assert "no content" in result.lower()
200200

201201
def test_includes_images_info(self, tmp_path):
@@ -205,11 +205,11 @@ def test_includes_images_info(self, tmp_path):
205205
sources.mkdir()
206206
pages = [{"page": 1, "content": "Text.", "images": [{"path": "images/p/img.png", "width": 100, "height": 80}]}]
207207
(sources / "doc.json").write_text(json.dumps(pages), encoding="utf-8")
208-
result = get_page_content("doc", "1", wiki_root)
208+
result = get_wiki_page_content("doc", "1", wiki_root)
209209
assert "img.png" in result
210210

211211
def test_path_escape_denied(self, tmp_path):
212212
wiki_root = str(tmp_path)
213213
(tmp_path / "sources").mkdir()
214-
result = get_page_content("../../etc/passwd", "1", wiki_root)
214+
result = get_wiki_page_content("../../etc/passwd", "1", wiki_root)
215215
assert "denied" in result.lower() or "not found" in result.lower()

tests/test_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_agent_tool_names(self, tmp_path):
2323
agent = build_query_agent(str(tmp_path), "gpt-4o-mini")
2424
names = {t.name for t in agent.tools}
2525
assert "read_file" in names
26-
assert "get_page_content_tool" in names
26+
assert "get_page_content" in names
2727
assert "get_image" in names
2828

2929
def test_instructions_mention_get_page_content(self, tmp_path):

0 commit comments

Comments
 (0)