documentreader

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package documentreader groups the explicit, agent-invocable tools built on a document-conversion backend: read_document_url (fetch+convert a remote document) and convert_document (convert a local file that native extraction can't handle well - scanned PDFs, complex slide decks, audio). Both are opt-in: the agent reaches for them deliberately, as opposed to internal/tools/files/read's own conversion fallback, which stays in place so a scanned PDF or audio file still "just works" through plain FileRead without the agent needing to know this package exists.

Index

Constants

View Source
const (
	// ConvertToolName is the name of the convert_document tool.
	ConvertToolName = "convert_document"

	// ConvertDisplayName is the display name of the convert_document tool.
	ConvertDisplayName = "Convert Document"

	// ConvertSearchHint is a hint for tool search functionality.
	ConvertSearchHint = "OCR a scanned PDF, extract a complex slide deck, or transcribe audio through a document reader"

	// ConvertDescription is the description of the convert_document tool.
	ConvertDescription = "Convert a local file to markdown using the configured document reader: OCR, layout analysis, table structure, and audio transcription.\n\n" +
		"## When to use\n\n" +
		"- A scanned/image-only PDF that FileRead reports as having little or no extractable text\n" +
		"- A PPTX slide deck — most slide decks are mostly visual (screenshots, diagrams, charts) with only a title or two of real text, so FileRead's native extraction routinely \"succeeds\" while missing almost everything that actually matters. FileRead already auto-falls-back to the document reader for a PPTX whose extracted text is sparse relative to its slide count, but if you're unsure or FileRead returned something that looks thin, don't hesitate to call this directly rather than trying to work around it with other tools (terminal, ad-hoc scripts, per-slide image extraction, etc.) — none of that gets better OCR than a whole-document reader does in one shot\n" +
		"- Audio files (WAV, MP3) that need transcription\n" +
		"- A DOCX/PPTX/XLSX that FileRead's native extraction failed on\n\n" +
		"## When NOT to use\n\n" +
		"- Plain text-native PDFs, or text-heavy DOCX/XLSX — use FileRead instead, it extracts them natively without the network round-trip to an external document-reader service\n" +
		"- FileRead already tries the document reader automatically as a last resort for unreadable or sparse files, so you usually don't need this tool for a first read. Reach for it when you want deliberate control: forcing a reconversion, or converting a file FileRead didn't route to documentreader.\n\n" +
		"## Rules\n\n" +
		"- Requires a document reader to be configured (document_reader_url) or injected by the host.\n" +
		"- Pass the whole file in one call (`path` is the deck/document itself, e.g. \"deck.pptx\") — the document reader converts every slide/page in a single request. Never split a deck into individual slide images and OCR them one at a time: it's slower, it's more tool calls, and it throws away the layout/reading-order/table-structure analysis a whole-document reader does for a whole document at once.\n"
)
View Source
const (
	// ReadURLToolName is the name of the read_document_url tool.
	ReadURLToolName = "read_document_url"

	// ReadURLDisplayName is the display name of the read_document_url tool.
	ReadURLDisplayName = "Read Document URL"

	// ReadURLSearchHint is a hint for tool search functionality.
	ReadURLSearchHint = "fetch and convert a remote document or web page to markdown"

	// ReadURLDescription is the description of the read_document_url tool.
	ReadURLDescription = "Fetch a document at a URL and convert it to readable markdown. " +
		"Supports PDF, DOCX, PPTX, XLSX, HTML pages, and arXiv papers. " +
		"Requires a document reader to be configured. " +
		"Optionally saves the extracted markdown to a workspace path."
)
View Source
const (
	RenderPageToolName = "render_document_page"

	RenderPageDisplayName = "Render Document Page"

	RenderPageSearchHint = "render one PDF page as an image for visual inspection of diagrams, charts, tables, or scanned content"

	RenderPageDescription = "Render one page of a local document to a PNG image for visual inspection, then attach it to the conversation as an image (in the message that follows this tool's result) so you can actually see it.\n\n" +
		"Use this after reading a document when markdown extraction may miss important visual details: diagrams, charts, screenshots, equations, scanned pages, or visually structured tables.\n\n" +
		"Current local support is PDF pages through the configured native document renderer. The page number is 1-indexed."
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DocumentReaderURL is the base URL of a document-reader service. Used
	// to build the default DocumentConverter when that field is left nil.
	// When both are empty/nil, tools register but always report "not
	// configured".
	DocumentReaderURL string

	// DocumentConverter, when set, is used instead of building a
	// service client from DocumentReaderURL. Takes precedence over
	// DocumentReaderURL.
	DocumentConverter internalreader.Converter

	// DocumentPageRenderer, when set, renders a specific document page to an
	// image so multimodal agents can visually inspect diagrams, charts, and
	// scanned pages after markdown extraction.
	DocumentPageRenderer pdfsmart.PageRenderer
}

Config holds the shared configuration for every tool in this package.

type ConvertTool

type ConvertTool struct {
	// contains filtered or unexported fields
}

ConvertTool converts a local file to markdown via a document-conversion backend.

func NewConvertTool

func NewConvertTool(cfg Config, workingDir string) *ConvertTool

NewConvertTool creates a new convert_document tool.

func (*ConvertTool) BackfillInput

func (t *ConvertTool) BackfillInput(_ context.Context, input map[string]any) map[string]any

func (*ConvertTool) Call

func (t *ConvertTool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

func (*ConvertTool) CheckPermissions

func (t *ConvertTool) CheckPermissions(_ context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

func (*ConvertTool) Definition

func (t *ConvertTool) Definition() tool.Definition

func (*ConvertTool) Description

func (t *ConvertTool) Description(_ context.Context) (string, error)

func (*ConvertTool) FormatResult

func (t *ConvertTool) FormatResult(data any) string

func (*ConvertTool) IsConcurrencySafe

func (t *ConvertTool) IsConcurrencySafe(_ map[string]any) bool

func (*ConvertTool) IsEnabled

func (t *ConvertTool) IsEnabled() bool

func (*ConvertTool) IsReadOnly

func (t *ConvertTool) IsReadOnly(_ map[string]any) bool

func (*ConvertTool) ValidateInput

func (t *ConvertTool) ValidateInput(_ context.Context, input map[string]any) (map[string]any, error)

type ReadURLTool

type ReadURLTool struct {
	// contains filtered or unexported fields
}

ReadURLTool fetches a remote document and converts it to markdown via a document-conversion backend.

func NewReadURLTool

func NewReadURLTool(cfg Config) *ReadURLTool

NewReadURLTool creates a new read_document_url tool.

func (*ReadURLTool) BackfillInput

func (t *ReadURLTool) BackfillInput(_ context.Context, input map[string]any) map[string]any

func (*ReadURLTool) Call

func (t *ReadURLTool) Call(
	ctx context.Context,
	input tool.CallInput,
	permissionCheck types.CanUseToolFn,
) (tool.CallResult, error)

func (*ReadURLTool) CheckPermissions

func (t *ReadURLTool) CheckPermissions(_ context.Context, input map[string]any, _ tool.ToolUseContext) types.PermissionResult

func (*ReadURLTool) Definition

func (t *ReadURLTool) Definition() tool.Definition

func (*ReadURLTool) Description

func (t *ReadURLTool) Description(_ context.Context) (string, error)

func (*ReadURLTool) FormatResult

func (t *ReadURLTool) FormatResult(data any) string

func (*ReadURLTool) IsConcurrencySafe

func (t *ReadURLTool) IsConcurrencySafe(_ map[string]any) bool

func (*ReadURLTool) IsEnabled

func (t *ReadURLTool) IsEnabled() bool

func (*ReadURLTool) IsReadOnly

func (t *ReadURLTool) IsReadOnly(_ map[string]any) bool

func (*ReadURLTool) ValidateInput

func (t *ReadURLTool) ValidateInput(_ context.Context, input map[string]any) (map[string]any, error)

type RenderPageTool

type RenderPageTool struct {
	// contains filtered or unexported fields
}

func NewRenderPageTool

func NewRenderPageTool(cfg Config, workingDir string) *RenderPageTool

func (*RenderPageTool) BackfillInput

func (t *RenderPageTool) BackfillInput(_ context.Context, input map[string]any) map[string]any

func (*RenderPageTool) Call

func (t *RenderPageTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

func (*RenderPageTool) CheckPermissions

func (t *RenderPageTool) CheckPermissions(_ context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

func (*RenderPageTool) Definition

func (t *RenderPageTool) Definition() tool.Definition

func (*RenderPageTool) Description

func (t *RenderPageTool) Description(_ context.Context) (string, error)

func (*RenderPageTool) FormatResult

func (t *RenderPageTool) FormatResult(data any) string

func (*RenderPageTool) IsConcurrencySafe

func (t *RenderPageTool) IsConcurrencySafe(_ map[string]any) bool

func (*RenderPageTool) IsEnabled

func (t *RenderPageTool) IsEnabled() bool

func (*RenderPageTool) IsReadOnly

func (t *RenderPageTool) IsReadOnly(_ map[string]any) bool

func (*RenderPageTool) ValidateInput

func (t *RenderPageTool) ValidateInput(_ context.Context, input map[string]any) (map[string]any, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL