refactor(libsy): use conversation IR request and response types#58
Conversation
fcdc0ad to
eab29f6
Compare
|
#17 is merged can you rebase? @nachiketb-nvidia |
e4e241c to
55aa536
Compare
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Signed-off-by: nachiketb <nachiketb@nvidia.com>
55aa536 to
836e153
Compare
WalkthroughThe workspace adds ChangesShared protocol foundation
libsy API migration
Routing and examples
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
crates/libsy-examples/examples/research_agent.rs (1)
81-105: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the duplicated response-text extraction into a shared helper. Both examples reimplement the identical
filter_mapoveroutput.content(Text/Refusal/Reasoning → text, Unknown → raw, else dropped) to build notes;libsyalready offersLlmMessage::text_content(sep)for the request side but nothing symmetric for response outputs, so this logic is hand-rolled at every call site (also seen inllm_class.rs/ensemble.rs).
crates/libsy-examples/examples/research_agent.rs#L81-L105: replace the inlinefilter_map/collect/joinwith a call to a sharedresponse_text(&response)helper.crates/libsy-examples/examples/research_agent_core.rs#L92-L109: replace the identical inline block with the same shared helper call.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/libsy-examples/examples/research_agent.rs` around lines 81 - 105, Extract the duplicated LlmContentBlock text/unknown extraction into a shared response_text(&response) helper, preserving the existing newline-joined output and omission of unsupported blocks. Replace the inline filter_map/collect/join logic in crates/libsy-examples/examples/research_agent.rs lines 81-105 and crates/libsy-examples/examples/research_agent_core.rs lines 92-109 with calls to that helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/libsy-examples/src/ensemble.rs`:
- Around line 297-311: Reuse the existing text-extraction helper used by the
earlier response-processing code and build_judge_prompt instead of duplicating
the closure in the judge_text construction. Update the judge_text path to call
that shared helper, preserving the current handling of Text, Refusal, Reasoning,
and Unknown content blocks.
- Around line 205-225: Consolidate the repeated LlmContentBlock text extraction
into a shared helper, covering Text, Refusal, Reasoning, and Unknown raw
content, then update this user_prompt construction and the corresponding sites
in ensemble.rs and llm_class.rs to reuse it instead of duplicating the match
closure.
In `@crates/libsy-examples/src/llm_class.rs`:
- Around line 155-169: Replace the duplicated content-extraction logic in the
classifier score parsing flow with the existing shared text-extraction closure
or helper used elsewhere in the diff. Use it to build score_text from
classify_response, preserving the current handling of text, refusal, reasoning,
and unknown blocks before parsing the trimmed result as f64.
- Around line 109-129: Consolidate the duplicated LlmContentBlock text
extraction used by the user_prompt construction and ensemble.rs into one shared
helper, covering Text, Refusal, Reasoning, and Unknown::raw while excluding
other variants. Replace the local filter_map logic with that helper and preserve
the existing newline-joined output.
In `@crates/libsy/README.md`:
- Around line 81-87: Update the client example before constructing the Response
and nested LlmResponse to define completion by extracting the provider response
value, so the existing LlmContentBlock::Text usage compiles when copied.
- Around line 180-187: Update the classifier example around classify_response
and score to match the extraction logic in llm_class.rs: scan all response
outputs and content blocks and support the same text-like block variants before
parsing the classifier score. Do not retain the first-output/first-content-only
behavior unless the example explicitly documents that assumption.
---
Nitpick comments:
In `@crates/libsy-examples/examples/research_agent.rs`:
- Around line 81-105: Extract the duplicated LlmContentBlock text/unknown
extraction into a shared response_text(&response) helper, preserving the
existing newline-joined output and omission of unsupported blocks. Replace the
inline filter_map/collect/join logic in
crates/libsy-examples/examples/research_agent.rs lines 81-105 and
crates/libsy-examples/examples/research_agent_core.rs lines 92-109 with calls to
that helper.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 434057d8-6307-487b-bdb1-7e1cc7eb85ef
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (20)
Cargo.tomlcrates/libsy-examples/examples/research_agent.rscrates/libsy-examples/examples/research_agent_core.rscrates/libsy-examples/src/ensemble.rscrates/libsy-examples/src/llm_class.rscrates/libsy-examples/src/rand.rscrates/libsy/Cargo.tomlcrates/libsy/README.mdcrates/libsy/src/lib.rscrates/libsy/src/types.rscrates/switchyard-protocol/Cargo.tomlcrates/switchyard-protocol/src/format.rscrates/switchyard-protocol/src/ir.rscrates/switchyard-protocol/src/lib.rscrates/switchyard-translation/Cargo.tomlcrates/switchyard-translation/src/codecs/anthropic/buffered.rscrates/switchyard-translation/src/codecs/common.rscrates/switchyard-translation/src/codecs/openai_chat/buffered.rscrates/switchyard-translation/src/codecs/responses/buffered.rscrates/switchyard-translation/src/lib.rs
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Signed-off-by: nachiketb <nachiketb@nvidia.com>
messiaen
left a comment
There was a problem hiding this comment.
Couple of minor naming comments otherwise LGTM
Signed-off-by: nachiketb <nachiketb@nvidia.com>
There was a problem hiding this comment.
Should this type also be move to libsy-protocol?
Can be separate PR.
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Linear: SWITCH-620 - Run a 24 hr stress test on Switchyard server
Why
PR #17 introduced libsy with bespoke
LlmRequest/LlmResponsestructs that only carried a text prompt and completion. That makes libsy look like it owns a new LLM wire abstraction, when Switchyard already has a shared provider-neutral conversation IR inswitchyard-translation.This change makes libsy align with that direction now:
LlmRequestandLlmResponseare semantic aliases overConversationRequestandConversationResponse, while provider-specific details stay in clients/hosts rather than in router algorithms.What
LlmRequestandLlmResponsestructs with aliases toConversationRequestandConversationResponse.text_request,text_response,request_text, andresponse_text.llm_class,ensemble, andrandto inspect conversation IR via the helpers instead of oldprompt/completionfields.Step::ReturnToAgentso the larger conversation response does not inflate the stream enum.Algorithm/Request/ResponseAPI and compiles it against the shared router builder.How
The algorithms still operate on plain text where their current logic requires text, but that text is now extracted from the shared IR. Generated subcalls are built as text-only
ConversationRequests with the inbound model preserved inmodel; routed target selection remains onDecision::selected_model().The proxy demo still lets libsy make routing decisions and Switchyard own HTTP/profile serving. The demo now creates a text-only libsy request from inbound prompt text, runs the classifier algorithm directly, and returns a chat-completion response for Switchyard to translate back to the inbound format.
What to Review
LlmRequest/LlmResponseto the translation IR is the right libsy contract for this PR.Step::ReturnToAgentis acceptable for the stream API after the response type becomes larger.Validation
cargo test -p libsycargo check -p libsy --examplescargo check -p libsy-proxycargo test -p libsy-proxycargo fmt,cargo clippySummary by CodeRabbit
New Features
Documentation
Refactor