Skip to content

Conversation

@AyushKarupakula
Copy link

@AyushKarupakula AyushKarupakula commented Oct 9, 2025

Add PDF document support


Note

Adds PDF/document handling in tool results and logs Anthropic API requests/responses to a file with robust serialization.

  • Claude Agent:
    • Document/PDF support: Handle types.EmbeddedResource (e.g., PDFs) in format_tool_results, emitting document blocks via BetaDocumentBlock (with fallback type).
    • Extend tool_use_content_block to accept BetaDocumentBlock; add document_to_content_block helper.
  • Logging:
    • Log Anthropic API request/response JSON around beta.messages.create.
    • Add _serialize_for_json, _serialize_content, _serialize_usage utilities and file logging helpers _log_anthropic_request/_log_anthropic_response.
    • Configurable log file via ANTHROPIC_API_LOG_FILE (defaults to anthropic_api_logs.txt).

Written by Cursor Bugbot for commit ef92791. This will update automatically on new commits. Configure here.

cursor[bot]

This comment was marked as outdated.

@promptless
Copy link
Contributor

promptless bot commented Oct 9, 2025

📝 Documentation updates detected!

New suggestion: Add comprehensive Claude agent documentation with PDF support for PR #165

The agent now handles EmbeddedResource and converts it to Claude's BetaDocumentBlock format. Also fixed a small bug where the URI needed to be converted from Pydantic AnyUrl to string before processing
"media_type": mime_type,
"data": base64_data
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Document Blocks Missing Crucial Filename

The document_to_content_block function accepts a filename parameter but never includes it in the returned document block dictionary. The filename is extracted and passed to this function at line 339 but is silently discarded, which likely breaks PDF document handling since Claude's document blocks typically require the filename field to properly identify the document.

Fix in Cursor Fix in Web

Copy link
Contributor

@Parth220 Parth220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to how the model ingests the data is reasonable, but I won't add the logging since the telemetry tracks it.

Comment on lines +518 to +546
def _log_anthropic_request(request_kwargs: dict[str, Any]) -> None:
"""Log Anthropic API request JSON to file."""
try:
# Serialize the request data
log_data = _serialize_for_json(request_kwargs)

# Remove API key if present (for security)
if "api_key" in log_data:
log_data["api_key"] = "***REDACTED***"

request_json = json.dumps(log_data, indent=2, ensure_ascii=False, default=str)

with open(_ANTHROPIC_LOG_FILE, "a", encoding="utf-8") as f:
f.write("=" * 80 + "\n")
f.write("ANTHROPIC API REQUEST\n")
f.write("=" * 80 + "\n")
f.write(request_json + "\n")
f.write("\n")
except Exception as e:
logger.warning(f"Failed to log Anthropic request: {e}")
import traceback
logger.debug(traceback.format_exc())


def _log_anthropic_response(response: Any) -> None:
"""Log Anthropic API response JSON to file."""
try:
# Convert response to dict
response_dict = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this?

This info is already tracked via the telemetry through the trace decorator.

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