refactor(flows): migrate agent-node completion to crate ChatModel (#4727)#4750
refactor(flows): migrate agent-node completion to crate ChatModel (#4727)#4750senamakel wants to merge 1 commit into
Conversation
…tion B) tinyhumansai#4727 straggler: tinyflows/caps.rs llm.complete now drives a crate ChatModel (create_chat_model_with_model_id + a create_chat_model_pinned rebuild for the node raw/BYOK override, tinyhumansai#4598) via ModelRequest/invoke, instead of create_chat_provider + provider.chat. Adds two reusable seam converters — chat_messages_to_model_messages (host history -> crate messages) and model_response_to_chat_response (crate response -> host {text, tool_calls, usage, reasoning_content}) — so the flows node's JSON output envelope is byte-identical. Core lib green; convert/factory/caps test modules clean. Claude-Session: https://claude.ai/code/session_018MnMVgnzxchtcs1DDUxTfF
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16ae696494
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let response = crate::openhuman::tinyagents::model_response_to_chat_response( | ||
| &chat | ||
| .invoke(&(), model_request) |
There was a problem hiding this comment.
Preserve literal tool-call markup in no-tools completions
Routing this no-tools completion through ProviderModel::invoke makes the adapter run the harness tool-call parser on every text response before model_response_to_chat_response sees it. Because llm.complete does not populate ModelRequest.tools (old ChatRequest.tools was None), prompts that legitimately ask the agent node to emit examples such as <tool_call>{"name":"x","arguments":{}}</tool_call> now have that text removed and surfaced as tool_calls, so the structured parser below sees truncated/empty text instead of the model's answer. The direct provider path returned that text verbatim; skip tool parsing for this one-shot/no-tools path or preserve the raw text.
Useful? React with 👍 / 👎.
Summary
agentnode completion (caps.rsllm.complete) off the rawcreate_chat_provider+provider.chatpath onto the crateChatModelinterface (ModelRequest/invoke).chat_messages_to_model_messages(host history → crate messages) andmodel_response_to_chat_response(crate response → host{text, tool_calls, usage, reasoning_content}) — so the flows node's JSON output envelope is byte-identical.factory::create_chat_model_pinnedto honor a node-pinned raw/BYOK model id verbatim (issue Agent-node raw BYOK model overrides silently collapse to the chat model #4598) on theChatModelpath.Problem
tinyflows/caps.rswas one of the last one-shot callers still on openhuman's in-houseProvidertrait +ChatRequest/provider.chat. It is a straggler in the tinyagents inference migration (Motion B of #4727 / #4249): every fix to the provider path had to account for this bespoke caller, and it blocked shrinking thecreate_chat_providersurface.Solution
llm.completenow builds a crateChatModelviacreate_chat_model_with_model_id(role default) and rebuilds it pinned viacreate_chat_model_pinnedwhen a node overrides with a raw/BYOK model id (the existingresolve_completion_modellogic is preserved, incl. its unit tests). Messages are converted through the new seam helper, the model is invoked, and the response is converted back into the exact hostChatResponseshape the node serializes into its JSON output — so structured-output parsing,tool_calls,usage, andreasoning_contentbehavior are unchanged.This is independent of the larger Motion A harness refactor (PR #4726) — it uses only the pre-existing
create_chat_model_*factory plus the new converters — so it lands standalone.Submission Checklist
caps.rsresolve_completion_modelunit tests preserved; the two new seam converters are exercised via the flows completion path. No behavior assertions changed (parity-preserving refactor).N/A (author env): full local coverage run not performed (pre-existing unrelated full---testsbreakage in unrelated modules). Core libcargo checkgreen;convert/factory/capsmodules compile clean. Please rely on CI for the gate.N/A: behaviour-only refactor.N/A(internal refactor).N/A(no release-cut surface change; the flows node's output envelope is byte-parity).## Related.Impact
ChatModelwraps it), byte-identical JSON output envelope.Related
TurnModelSource).https://claude.ai/code/session_018MnMVgnzxchtcs1DDUxTfF