Skip to content

[fix] Normalize chat workflow output to the canonical Message shape#4719

Open
jp-agenta wants to merge 1 commit into
mainfrom
normalize-chat-output-message
Open

[fix] Normalize chat workflow output to the canonical Message shape#4719
jp-agenta wants to merge 1 commit into
mainfrom
normalize-chat-output-message

Conversation

@jp-agenta

Copy link
Copy Markdown
Member

Context

The chat_v0 workflow returned the raw LiteLLM message, leaking provider-specific fields into data.outputs. So a basic chat call produced:

{"content": "...", "role": "assistant", "provider_specific_fields": {"refusal": null}, "annotations": []}

instead of the canonical message shape the rest of the platform uses.

Changes

chat_v0 now validates its result through the SDK Message model before dumping, so outputs is the canonical {role, content, name, tool_calls, tool_call_id} (provider extras dropped). This matches what a custom/hook workflow returns after validating its own output through Message.

Before: {content, role, provider_specific_fields, annotations}
After: {role, content} (plus any of name/tool_calls/tool_call_id that are set)

Tests / notes

  • Verified Message.model_validate cleanly accepts a LiteLLM message dump with extras and yields the canonical fields.
  • Single-file change in sdks/python/agenta/sdk/engines/running/handlers.py (chat_v0).

🤖 Generated with Claude Code

chat_v0 returned the raw LiteLLM message, leaking provider-specific fields
(provider_specific_fields, annotations) into outputs. Validate through the SDK
Message model so the output is the canonical {role, content, name, tool_calls,
tool_call_id}, matching what a hook/custom workflow returns.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 17, 2026
@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jun 17, 2026 10:33am

Request Review

@dosubot dosubot Bot added the python Pull requests that update Python code label Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72fae4cf-d200-4a0d-b338-f706c1ed6d0a

📥 Commits

Reviewing files that changed from the base of the PR and between 5722ff7 and 69088bd.

📒 Files selected for processing (1)
  • sdks/python/agenta/sdk/engines/running/handlers.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced message formatting and validation in chat operations for improved consistency.

Walkthrough

In chat_v0, the returned message is now routed through Message.model_validate() on the dumped provider message before being re-dumped with exclude_none=True, replacing the previous direct message.model_dump(exclude_none=True) passthrough.

Changes

Message Canonicalization in chat_v0

Layer / File(s) Summary
Canonicalize provider message via Message.model_validate
sdks/python/agenta/sdk/engines/running/handlers.py
chat_v0 now passes the provider message through Message.model_validate(message.model_dump()) and re-dumps the result with exclude_none=True, replacing the prior direct model_dump passthrough.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: normalizing chat workflow output to use the canonical Message shape, which directly addresses the core problem of provider-specific fields leaking into outputs.
Description check ✅ Passed The description provides detailed context about the issue, the solution, and verification steps. It explains the before/after behavior, the rationale for the change, and confirms alignment with platform standards.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch normalize-chat-output-message

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@junaway junaway requested a review from ardaerzin June 17, 2026 10:38
@github-actions

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-production-a721.up.railway.app/w
Project agenta-oss-pr-4719
Image tag pr-4719-51a8805
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-06-17T10:46:46.349Z

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants