-
Notifications
You must be signed in to change notification settings - Fork 488
fix: support freeform stopReason in sampling #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: support freeform stopReason in sampling #327
Conversation
Previously, sampling response parsing would fail if a stopReason was provided besides endTurn/stopSequence/maxTokens. This fixes that to map the arbitrary values to UNKNOWN instead. Spec: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/f5ccad944fdf2b7d9cc70cf817f66ca5a8aa03a4/schema/2024-11-05/schema.ts#L807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LucaButBoring, thanks for addressing this.
The UNKNOWN approach masks the original stop reason. I'm not sure how important the exact stop-reason is for downstream applications?
A better approach would be relaxing the stop reason type to String, but this would be a breaking change. What do you think?
Yes, I was thinking about this - the reason I added public sealed class StopReason permits EndTurn, StopSequence, MaxTokens, Unknown {
private String value;
public StopReason(String value) {
this.value = value;
}
public class EndTurn : StopReason {
public EndTurn() {
super("endTurn");
}
}
public class StopSequence : StopReason {
public EndTurn() {
super("stopSequence");
}
}
public class MaxTokens : StopReason {
public MaxTokens() {
super("maxTokens");
}
}
public class Unknown : StopReason {
public Unknown(String value) {
super(value);
}
public String getValue() {
return value;
}
}
} That way consumers could handle it like so: if (stopReason instanceof EndTurn) {
// ...
} /* other cases */ else if (stopReason instanceof Unknown unknownStopReason) {
log.info("Sampling stopped due to unhandled stop reason: {}", unknownStopReason)
} I'll defer to you, though - if we're willing to make a breaking change for this and prefer that it just become a |
Supports freeform stop reasons in sampling responses by mapping them to a new
UNKNOWN
value.Motivation and Context
Previously, sampling response parsing would fail if a stopReason was provided besides endTurn/stopSequence/maxTokens. This fixes that to map the arbitrary values to UNKNOWN instead.
Spec: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/f5ccad944fdf2b7d9cc70cf817f66ca5a8aa03a4/schema/2024-11-05/schema.ts#L807
How Has This Been Tested?
Unit tests
Breaking Changes
None
Types of changes
Checklist
Additional context
Closes #328