Skip to content

Conversation

@nlaz
Copy link

@nlaz nlaz commented Oct 20, 2025

Background

Right now we are unable to pass documents by url back from a tool call to be processed by Anthropic. Anthropic's API handles this out of the box. Just needed to update the types on the tool result handling.

Summary

This PR updates the convertToAnthropicMessagesPrompt method to support document types in the tool results. The AnthropicDocumentContent type was already there so just needed to add it to the tool result type.

Manual Verification

Tested this locally with a script to fetch a document and used the toModelOutput to convert to this format. Example tool call. With these changes agent went from hallucinating about the document to actually analyzing it.

const fetchDocumentTool = () =>
  tool({
    name: 'fetchDocument',
    description: 'Fetch a document URL',
    inputSchema: z.object({}),
    execute: async () => {
      return [{
        type: 'media',
        data: new URL('https://arxiv.org/pdf/2410.00749'),
        mediaType: 'application/pdf',
      }, {
        type: 'text',
        text: `Successfully loaded document`,
      }];
    },
    toModelOutput: (output) => {
      return { type: 'content', value: output };
    },
  });

@nlaz nlaz force-pushed the nlaz/anthropic-pdfs branch from 4161959 to dea9134 Compare October 23, 2025 04:13
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