Skip to content

Refactor tool results to typed output models - #96

Open
gekinci wants to merge 8 commits into
mainfrom
refactor-tool-result
Open

gekinci wants to merge 8 commits into
mainfrom
refactor-tool-result

Conversation

@gekinci

@gekinci gekinci commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

This PR standardizes how code interpreter and generic tool results are represented across streaming, tool execution, and OpenAI message serialization. The motivation is to replace loosely shaped dict/string payloads with typed result models, making tool output handling more predictable, preserving backwards compatibility for legacy streamed content, and avoiding accidental leakage of internal metadata into LLM-facing payloads.
It closes #74.

Changes:

  • Added shared Pydantic models for CodeInterpreterResult, CreatedFile, and GenericToolResult.
  • Updated code interpreter execution, file detection, and server responses to return typed result objects.
  • Updated web search responses to use GenericToolResult.
  • Changed streaming variants so CodeOutput and ToolOutput carry typed result models instead of raw dicts/strings.
  • Extended normalization helpers for legacy code output and generic tool output payloads.
  • Centralized LLM payload serialization for code results, excluding preview_url and url_sent_to_model.
  • Preserved image URL forwarding behavior for production while ensuring each created image URL is only sent to the model once.
  • Updated tool result parsing to validate typed outputs and set preview URLs on created files.
  • Expanded unit tests for typed streaming outputs, legacy normalization, created file handling, OpenAI message conversion, and generic tool result serialization.

@gekinci
gekinci requested a review from felio92 September 9, 2026 14:07
@gekinci gekinci self-assigned this Sep 9, 2026
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.

Chatbot: refactor tool outputs, define Pydantic models to verify output shapes

1 participant