AI providers: tool results cannot carry images because non-string results are JSON.stringify'd
Maintainers usually reply within 1 day
@nmnmcc is already working on this.
Since Oct 23, 2026.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript
- Domain
- ai, backend-api-design
Research direction
Read packages/effect/src/ai/Toolkit.ts and Prompt.ts, then trace tool result serialization in packages/ai/anthropic/src/AnthropicLanguageModel.ts, packages/ai/openai/src/OpenAiLanguageModel.ts, and packages/ai/openai-compat/src/OpenAiLanguageModel.ts. Compare the Anthropic and OpenAI Responses content formats described in the issue and decide how model-facing content should be represented. Done means supported rich results reach compatible APIs in their native form, with text-only providers retaining current behavior or reporting a clear error.
Written by the indexing model from the issue text.
Description
What is the problem?
A tool result cannot carry an image (or other content blocks) to the model. The provider packages turn every non-string tool result into a string with JSON.stringify, so the model gets the image as plain text.
Both provider APIs support rich tool results:
- Anthropic Messages:
tool_result.contentcan be a string or an array of content blocks, includingimage(base64 or URL) anddocumentblocks. - OpenAI Responses:
function_call_output.outputcan be a string or an array ofinput_text,input_image, andinput_fileitems.
Where it happens
The path from a tool handler to the request (on main, 4d24a11; the same in 4.0.5 and 4.0.6):
Toolkitencodes the handler result with the tool's success schema. There is no hook to map it to model content:
https://github.com/Effect-TS/effect/blob/4d24a11217edda68e8c4c72cdc1cff025afa19d6/packages/effect/src/ai/Toolkit.ts#L527Prompt.ToolResultPart.resultisunknown, and it getsencodedResult:
https://github.com/Effect-TS/effect/blob/4d24a11217edda68e8c4c72cdc1cff025afa19d6/packages/effect/src/ai/Prompt.ts#L2268- The providers stringify anything that is not a string:
@effect/ai-anthropic: https://github.com/Effect-TS/effect/blob/4d24a11217edda68e8c4c72cdc1cff025afa19d6/packages/ai/anthropic/src/AnthropicLanguageModel.ts#L1045@effect/ai-openai: https://github.com/Effect-TS/effect/blob/4d24a11217edda68e8c4c72cdc1cff025afa19d6/packages/ai/openai/src/OpenAiLanguageModel.ts#L1373@effect/ai-openai-compat: https://github.com/Effect-TS/effect/blob/4d24a11217edda68e8c4c72cdc1cff025afa19d6/packages/ai/openai-compat/src/OpenAiLanguageModel.ts#L923
content: typeof part.result === "string" ? part.result : JSON.stringify(part.result),
Example
A tool (for example, a screenshot tool) returns this success value:
[{ type: "image", source: { type: "base64", media_type: "image/png", data: "iVBORw0..." } }]
@effect/ai-anthropic sends:
{ "type": "tool_result", "tool_use_id": "...", "content": "[{\"type\":\"image\",\"source\":{...}}]" }
The API treats the string as one text block. So:
- The model cannot see the image. It only reads base64 characters.
- The base64 text uses a very large number of tokens. A 500 KB PNG is about 670,000 characters, which can be more than the whole context window. A real image block costs about
width * height / 750tokens on Claude.
The same thing happens with function_call_output.output on OpenAI.
Expected behavior
A tool should be able to return model-facing content parts (text, image, file), and each provider should send them in its native form:
- Anthropic:
tool_result.contentas an array oftext/image/documentblocks. - OpenAI Responses:
function_call_output.outputas an array ofinput_text/input_image/input_file. - Providers or APIs that only accept text tool results (for example, Chat Completions
toolmessages) can keep the current string behavior, or fail with a clear error.
Possible API
Two ideas (I am open to others):
- An optional mapping on the tool, like
toModelOutputin the Vercel AI SDK. It maps the decoded result to content parts that use the existingPromptpart types (TextPart,FilePart). Theresultthat the program sees stays typed as today. - A known shape for
ToolResultPart.result, such as{ type: "content", value: Array<TextPart | FilePart> }, that providers check for before they fall back toJSON.stringify.
Workaround today
Put the image in a separate user message after the tool result. This works, but it moves the image out of the tool call that made it, and it does not fit well with LanguageModel.generateText tool loops.
Versions
The problem is in 4.0.5 and in the latest release, 4.0.6. The reproduction in the comment below gives the same output on both.
effect4.0.5, 4.0.6@effect/ai-anthropic4.0.5, 4.0.6@effect/ai-openai4.0.5, 4.0.6@effect/ai-openai-compat4.0.5, 4.0.6
- Dominant language
- TypeScript
- Stars
- 16.7k
- Forks
- 808
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 848
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Effect-TS/effect
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
`Schema.Literals`: add `omit`, the complement of `pick`Possibly taken @effect-bot claimed this 1 day ago. Openenhancement Needs Evaluation
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Support the `openapi-3.0` target in `Schema.toStandardJSONSchemaV1`Possibly taken @MichaelDeBoey claimed this 1 day ago. Openenhancement Needs Evaluation
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Effect-TS/effect#9764 · 3 comments ·
Maintainers usually reply within 1 day
-
RpcClient.layerProtocolWorker: what's the equivalent of Piscina's abortable tasks? (terminate a stuck worker on interrupt, control respawn)Possibly taken @effect-bot claimed this 8 days ago. Open
Effect-TS/effect#9332 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in Effect-TS/effect
Similar issues
-
[Bug]: REST API URL starting with "http" but no scheme (e.g. httpbin.org/get) is not given an http:// prefixPossibly taken @ItsDeadlyProgrammer claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
appsmithorg/appsmith#42471 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ehmpathy/rhachet-roles-bhrain#705 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Status: Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
mermaid-js/mermaid#8546 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
braintrustdata/braintrust-sdk-javascript#2659 ·
Maintainers usually reply within 1 day