Skip to content

routing: make system prompts follow answer targets #496

Description

@afourniernv

Linear: SWITCH-1253

Problem

A client calls a Switchyard route without knowing which upstream model will answer. Those models may need different standing system instructions.

Today this is only configurable through Stage and Composite route fields such as efficient_system_prompt and capable_system_prompt. Other routers do not have the same configuration surface.

Fallback also matters. If a route selects fast and that target fails, the request sent to capable must receive the capable prompt. It cannot reuse a request already prepared for fast.

Proposed interface

Allow the prompt to be configured on a target:

[targets.fast]
id = "meta/llama-small"
llm_client = "together"
system_prompt = "Be concise."

[targets.capable]
id = "meta/llama-large"
llm_client = "together"
system_prompt = "Reason carefully."

[routes.agent]
id = "switchyard/agent"
type = "stage_router"
efficient_target = "fast"
capable_target = "capable"

The prompt should follow the answer target rather than the router type. Judge, classifier, and reviewer calls should remain unchanged.

Implementation

  • Translation owns the model and prompt mutation for one request.
  • libsy marks calls that may become the client-visible answer.
  • libsy-llm-client prepares each selected or fallback candidate immediately before it is called.
  • The native runner builds the effective prompt map from [targets.*].system_prompt.

This keeps provider request mutation out of libsy and prevents one candidate's prompt from leaking into a fallback.

Compatibility

  • Existing configuration without target prompts behaves as before.
  • Legacy Stage and Composite prompt fields remain supported.
  • Target-level configuration takes precedence when both forms configure the same answer target.
  • Routing decisions, retry behavior, and fallback order do not change.

Pull requests

Done when

  • Every built-in client-visible answer path uses the selected target's prompt.
  • Each fallback is prepared independently.
  • Existing caller instructions are preserved after the target prompt.
  • Judge, classifier, and reviewer calls remain unprompted.
  • Legacy configuration remains supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions