Add PageIndexClient with agent-based retrieval via OpenAI Agents SDK#125
Add PageIndexClient with agent-based retrieval via OpenAI Agents SDK#125KylinMountain wants to merge 5 commits intoVectifyAI:mainfrom
Conversation
|
Test result: |
There was a problem hiding this comment.
Pull request overview
Adds a retrieval + QA layer on top of the existing PageIndex tree builders by introducing tool-style retrieval functions and a high-level PageIndexClient that uses the OpenAI Agents SDK to autonomously navigate document structure and fetch relevant page/line content for answering questions.
Changes:
- Added
pageindex/retrieve.pywith 3 JSON-returning retrieval tools: document metadata, token-efficient structure, and page/line content retrieval. - Added
pageindex/client.pyimplementingPageIndexClient(indexing, workspace persistence, and agent-driven querying). - Added a runnable demo script (
test_client.py) and updated exports/dependencies (pageindex/__init__.py,requirements.txt).
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
test_client.py |
Demo script that downloads a PDF, indexes it, and runs agent queries including workspace reload. |
requirements.txt |
Adds openai-agents dependency for the agent-based client. |
pageindex/utils.py |
Adds streaming helper and tree/node printing/mapping utilities. |
pageindex/retrieve.py |
Implements the 3 retrieval tool functions (metadata, structure, page/line content). |
pageindex/client.py |
Introduces PageIndexClient with indexing, persistence, and OpenAI Agents SDK integration. |
pageindex/__init__.py |
Exposes retrieval tools and PageIndexClient at package top-level. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code reviewFound 2 issues:
🤖 Generated with Claude Code If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Code reviewFound 1 issue:
PageIndex/pageindex/retrieve.py Lines 58 to 79 in 72afe8b 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
|
The new output with tool calling reasoning. |
38fffc6 to
80581be
Compare
What this PR adds
The upstream library provides
page_index()andmd_to_tree()for building document tree structures, but has no retrieval or QA layer. This PR adds that layer.New:
pageindex/retrieve.py— 3 retrieval tool functionsThree functions that expose structured document access:
tool_get_document(documents, doc_id)— metadata (name, description, type, page count)tool_get_document_structure(documents, doc_id)— full tree JSON without text (token-efficient)tool_get_page_content(documents, doc_id, pages)— page text by range ("5-7","3,8","12")Works with both PDF (page numbers) and Markdown (line numbers).
New:
pageindex/client.py—PageIndexClientHigh-level SDK client:
index(file_path)— index a PDF or Markdown file, returnsdoc_idquery_agent(doc_id, prompt, verbose=False)— runs an OpenAI Agents SDK agent that calls the 3 tools autonomously to answer the questionquery(doc_id, prompt)/query_stream(doc_id, prompt)— convenience wrappersworkspaceparameter for JSON-based persistence across sessionsDemo: OpenAI Agents SDK
The agent navigates the document structure itself — no manual retrieval logic needed:
With
verbose=True, each tool call (name, args, result preview) is printed in real time.Test plan
pip install openai-agentspython test_client.py— downloads DeepSeek-R1 PDF, indexes it, runs agent queryclient.query_agent(doc_id, "...", verbose=True)— observe tool call sequencePageIndexClient(workspace=...)— query works without re-indexing