Skip to content

feat: document agent calibration, structure anchoring, and probe metrics - #257

Merged
EricNGOntos merged 8 commits into
mainfrom
feat/wuchengke/2026-08-11-2
Aug 12, 2026
Merged

feat: document agent calibration, structure anchoring, and probe metrics#257
EricNGOntos merged 8 commits into
mainfrom
feat/wuchengke/2026-08-11-2

Conversation

@EricNGOntos

Copy link
Copy Markdown
Contributor

Summary

  • Rebase onto latest main and sync document-agent work: text probe metrics, remove inspect.pages from the agent tool surface, structure anchoring/TOC handling, and calibration stage/budgeting.
  • Includes a small lint fix for an unused import introduced in the retrieval contract test.
  • Local WIP under document_agent/page_memory remains uncommitted and is not in this PR.

Test plan

  • Confirm PR CI Lint / Typecheck / Test are green
  • Spot-check document agent profiling path on a multi-page PDF (probe + calibration + shard plan)
  • Confirm structure anchoring / TOC offset path still produces sane shard plans
  • Verify retrieval contract tests still pass in CI

Made with Cursor

EricNGOntos and others added 5 commits August 12, 2026 17:49
- Added support for tracking invisible text length in document agent features.
- Updated the `probe_page_features` and related functions to include metrics for both visible and invisible text.
- Improved documentation for clarity on text rendering modes and their impact on text metrics.

This change enhances the accuracy of text extraction and analysis in document processing.
- Deleted the `inspect.pages` tool from the document agent, streamlining the toolset.
- Updated prompts and decision-making logic to reflect the removal of the inspect action.
- Adjusted the planner and executor to handle legacy actions appropriately, ensuring compatibility with the new structure.
- Enhanced the sampling logic in the planner to include optional random page selection when extrema are not available.

This change simplifies the document profiling process and improves overall clarity in tool usage.
- Replaced the offset calibration method in `propose_shard_plan` with a new implementation from `structure_anchoring`.
- Consolidated TOC node extraction and hierarchy handling by integrating new functions for anchoring and offset calibration.
- Removed obsolete pruning logic for out-of-scope nodes, streamlining the skeleton extraction process.
- Enhanced the handling of TOC ranges and improved the overall clarity of the document agent's structure.

These changes improve the maintainability and efficiency of the document agent's processing logic.
- Updated budget parameters in `.env.example` files for both API and worker to support increased visual and calibration budgets.
- Introduced a new calibration stage in the `BudgetStage` and updated the `BudgetTracker` to accommodate the new calibration budget logic.
- Enhanced the `calibration` phase in various modules, including `loop.py`, `procedure.py`, and `service.py`, to improve the handling of offsets and visual stages.
- Refactored the `inspect_pages` tool to clarify budget limits and ensure proper handling of visual stages during inspections.

These changes improve the efficiency and accuracy of the calibration process within the document agent, allowing for better handling of visual budgets and offsets.
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment on lines +17 to +20
from app.services.document_agent.agents.calibration.procedure import (
build_calibration_payload,
finalize_calibration_result,
)
Comment on lines +28 to +31
from app.services.document_agent.structure.structure_anchoring import (
deserialize_skeleton_anchor,
serialize_skeleton_anchor,
)
Comment on lines +34 to +40
from app.services.document_agent.structure.structure_anchoring import (
SkeletonAnchor,
locate_null_page_parent_overrides,
offset_guided_anchoring,
prune_unanchored_toc_leaves,
serialize_skeleton_anchor,
)
Comment on lines +301 to +303
from app.services.document_agent.structure.structure_anchoring import (
bulk_offset_matches,
)

from loguru import logger

from app.services.document_agent.agents.calibration.loop import run_calibration_phase1
Comment on lines +813 to +816
from app.services.document_agent.agents.calibration.procedure import (
finalize_calibration_result,
flat_toc_entries,
)
Comment on lines +817 to +819
from app.services.document_agent.agents.calibration.service import (
calibrate_offset,
)
Comment thread apps/worker/app/services/page_memory/skeleton_extractor.py Fixed
Comment thread apps/worker/app/services/page_memory/skeleton_extractor.py Fixed
EricNGOntos and others added 3 commits August 12, 2026 17:52
Drop arithmetic offset fallback and legacy page_locate budget so shard
planning only uses VLM-calibrated offsets, and reuse one collapse helper
across calibration and page_memory.

Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid early Timestamp/NaT stringification in postprocess_tb so sparse
datetime columns still render clean HTML without NaT leakage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Patch verify on the live anchoring globals and drop brittle SkeletonAnchor
isinstance checks so contract autouse rebinds cannot miss the mock.

Co-authored-by: Cursor <cursoragent@cursor.com>
@EricNGOntos
EricNGOntos merged commit 3a6aef6 into main Aug 12, 2026
6 checks passed
@EricNGOntos
EricNGOntos deleted the feat/wuchengke/2026-08-11-2 branch August 13, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants