Add document context for edit agent (#6152)

# Description of Changes
Adds the ability for the Edit agent to request the content of the
document before it decides which parameters it needs. This makes it able
to process requests like `Split the document after the page containing
the "My Section" section`, allowing for document context-based requests
for all[^1] tools.

I had to make a few changes elsewhere to make this work, including:
- Moving the requesting of content out of the Question Agent and into a
common location
- Added specific API docs for the Split param because the generic ones
were not specific enough for the AI to be able to reliably perform the
correct operation
- Fixed an issue in the tool models generator which caused the Redact
params to only be half-generated (causing Pydantic to crash when the AI
tried to run Redact)
- Added missing logging to a bunch of tools and hooked it up properly so
it'll print to stderr
- Made the limits for the max pages/chars to extract from PDFs
configurable via env var

[^1]: Many of the tools can't actually do anything useful with the
context at this stage, but will just need the tool API to be extended
with new features like page-specific operations to be automatically able
to do smart operations without needing to change the Edit agent itself.
This commit is contained in:
James Brunton
2026-04-23 13:19:27 +00:00
committed by GitHub
parent e087b54cf0
commit 3e94157137
23 changed files with 462 additions and 108 deletions
+10 -6
View File
@@ -5,7 +5,6 @@
from __future__ import annotations
from enum import Enum, IntEnum, StrEnum
from typing import Any
from pydantic import Field, RootModel, SecretStr
@@ -756,6 +755,15 @@ class RearrangePagesParams(ApiModel):
)
class RedactionArea(ApiModel):
color: str | None = Field(None, description="The color used to redact the specified area.")
height: float | None = Field(None, description="The height of the area to be redacted.")
page: int | None = Field(None, description="The page on which the area should be redacted.")
width: float | None = Field(None, description="The width of the area to be redacted.")
x: float | None = Field(None, description="The left edge point of the area to be redacted.")
y: float | None = Field(None, description="The top edge point of the area to be redacted.")
class RemoveBlanksParams(ApiModel):
threshold: int | None = Field(10, description="The threshold value to determine blank pages", ge=0, le=255)
white_percent: float | None = Field(
@@ -949,7 +957,7 @@ class SplitForPosterPrintParams(ApiModel):
class SplitPagesParams(ApiModel):
page_numbers: str | None = Field(
"all",
description="The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a constant (e.g., '2n+1', '3n', '6n-5')",
description='Split points - page numbers after which the PDF will be cut. For example, `"2"` produces two documents (pages 1-2 and pages 3+); `"2,5"` produces three (pages 1-2, 3-5, 6+). Supports ranges (e.g. `"1,3,5-9"` splits after pages 1, 3, 5, 6, 7, 8, 9, yielding 8 documents), `"all"` (split after every page), or functions like `"2n+1"`, `"3n"`, `"6n-5"`.',
)
@@ -1041,10 +1049,6 @@ class VectorToPdfParams(ApiModel):
prepress: Prepress | None = Field(Prepress.boolean_false, description="Apply Ghostscript prepress settings")
class RedactionArea(RootModel[Any]):
root: Any
class RedactParams(ApiModel):
convert_pdf_to_image: bool | None = Field(False, description="Convert the redacted PDF to an image")
page_numbers: str | None = Field(