Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
fix(go): preserve candidate-specific requests in outcomes (#1299)
Alex Fournier6a924d55e36d
diff --git a/bindings/go/switchyard.go b/bindings/go/switchyard.goindex eddcbdf47..b86289471 100644--- a/bindings/go/switchyard.go+++ b/bindings/go/switchyard.go@@ -110,8 +110,10 @@ type Outcome struct {SelectedModelIDs []string `json:"selected_model_ids"`Request json.RawMessage `json:"request"`FallbackRequest *json.RawMessage `json:"fallback_request"`- Response *json.RawMessage `json:"response"`- Metadata json.RawMessage `json:"metadata"`+ // CandidateRequests overrides Request and FallbackRequest by model ID.+ CandidateRequests map[string]json.RawMessage `json:"candidate_requests"`+ Response *json.RawMessage `json:"response"`+ Metadata json.RawMessage `json:"metadata"`}// New constructs an algorithm from {"algorithm": AlgorithmSpec, "targets": {alias: modelID}}.diff --git a/bindings/go/switchyard_test.go b/bindings/go/switchyard_test.goindex f6c0d9b81..9c3cbb16e 100644--- a/bindings/go/switchyard_test.go+++ b/bindings/go/switchyard_test.go@@ -69,6 +69,28 @@ func TestOutcomeFallbackRequest(t *testing.T) {}}+// Stage's fallback keeps its execution prompt instead of reusing the planning prompt.+func TestCandidateRequestPreservesFallbackPrompt(t *testing.T) {+ router := newRouter(t, `{"type":"stage_router","picker":"capable_first",`+stage+`,"capable_system_prompt":"Plan the change","efficient_system_prompt":"Execute the change"}`)+ outcome, err := router.Route(context.Background(), input(), nil)+ if err != nil {+ t.Fatal(err)+ }+ wire, err := EncodeRequest("openai_chat", outcome.CandidateRequests["weak-model"], "weak-model")+ if err != nil {+ t.Fatal(err)+ }+ var encoded struct {+ Messages []struct{ Role, Content string }+ }+ if err := json.Unmarshal(wire, &encoded); err != nil {+ t.Fatal(err)+ }+ if len(encoded.Messages) == 0 || encoded.Messages[0].Role != "system" || encoded.Messages[0].Content != "Execute the change" {+ t.Fatalf("fallback request=%s, want execution prompt", wire)+ }+}+// Selection retains eligible targets and Stage's prepared request across the codecs.func TestSelectionAndTranslation(t *testing.T) {type chatRequest struct {