Connect your own agent to PageIndex to find and read documents. Configure your framework with PageIndex’s instructions and retrieval tools, then choose the documents or folder for each question. For a ready-to-run document-QA agent, use LLM Integration.
- Set up the PageIndex client — connect your library or index a document.
- Connect your agent — configure instructions and tools for your framework.
- Choose documents or a folder — prepare the context and question.
- Add citations — choose a citation format for your agent’s answers.
Set up the PageIndex client
Only the index side needs configuring — your agent framework brings its own model.
Cloud
import os
from pageindex import PageIndexClient
os.environ["PAGEINDEX_API_KEY"] = "your-pageindex-key"
client = PageIndexClient(index="cloud")Use an existing document ID from client.list_documents(), or submit a new document. wait=True blocks until it is ready:
doc_id = client.submit_document("./2023-annual-report.pdf", wait=True)["doc_id"]See Client Configuration for the full parameter list.
Connect your agent
The system prompt — agent_instructions()
PageIndex’s default system prompt. You can also pass your own system prompt.
instructions = client.agent_instructions()Define messages as shown below.
OpenAI Agents SDK
from agents import Agent, Runner
agent = Agent(
name="PageIndex",
instructions=instructions,
tools=client.as_openai_tools(),
model="gpt-5.6-sol",
)
result = Runner.run_sync(agent, messages)
print(result.final_output)Document management tools
Tools are read-only by default (include_management=False). To also expose tools that modify the library, pass include_management=True to both agent_instructions() and your framework’s tool method, such as as_openai_tools() or agent_tools(), so the instructions match the tool set.
On cloud, the default uses the read-only MCP endpoint (/mcp?tools=read); True uses the full /mcp tool list, including upload and delete. Locally, True adds remove_document.
Shortcut: one-call configuration bundles
These helpers return the system instructions and tools together. Use the matching replacement for your framework’s configuration above:
agent = Agent(**client.openai_agent_config(model="gpt-5.6-sol"))
runner_config = client.anthropic_runner_config(model="claude-opus-5")
options = ClaudeAgentOptions(**client.claude_agent_config(), model="claude-opus-5")The Anthropic bundle also includes max_tokens, max_iterations, and cache_control defaults. Use the explicit configuration to customize instructions, tools, or servers.
Choose documents or a folder
Build the messages used in the integration examples above. First, tell the agent where to look with document_context() or folder_context(). These return text containing the selected documents’ or folder’s metadata and retrieval guidance. Choose one of the following:
Document
context = client.document_context(doc_id)Put the selected context in its own first user message, then add the question as a second message. All framework examples above use this list:
messages = [
{"role": "user", "content": context},
{"role": "user", "content": "Summarize the auditor's concerns."},
]To let the agent discover documents across your library, omit the context message and pass just the question. folder_context("root") also leaves discovery unrestricted and returns an empty string.
The context steers the agent; it does not restrict tool access to the selected documents or folder. The framework tools retain access to your library. Both context methods raise PageIndexAPIError if a selected document or folder is missing or inaccessible.
Citations
Replace instructions = client.agent_instructions() in Connect your agent with the following, before creating the agent or runner:
instructions = client.agent_instructions() + "\n\n" + client.citation_prompt(format="cite")Choose the citation format with format=:
| Format | Output |
|---|---|
"cite" (default) | <cite doc="report.pdf" page="12"/> tags, with block when available. |
"markdown" | Bracketed references such as [report.pdf, p. 12]. |
"footnote" | Numbered footnote markers with source definitions. |