The client is not the source of truth (#7438)
Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Jack Amadeo <jackamadeo@block.xyz>
This commit is contained in:
@@ -79,8 +79,11 @@ fn track_tool_telemetry(content: &MessageContent, all_messages: &[Message]) {
|
|||||||
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Debug, Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct ChatRequest {
|
pub struct ChatRequest {
|
||||||
user_message: Message,
|
user_message: Message,
|
||||||
|
/// Override the server's conversation history. Only use this when you need absolute control
|
||||||
|
/// over the conversation state (e.g., administrative tools). For normal operations, the server
|
||||||
|
/// is the source of truth - use truncate/fork endpoints to modify conversation history instead.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
conversation_so_far: Option<Vec<Message>>,
|
override_conversation: Option<Vec<Message>>,
|
||||||
session_id: String,
|
session_id: String,
|
||||||
recipe_name: Option<String>,
|
recipe_name: Option<String>,
|
||||||
recipe_version: Option<String>,
|
recipe_version: Option<String>,
|
||||||
@@ -240,7 +243,7 @@ pub async fn reply(
|
|||||||
let cancel_token = CancellationToken::new();
|
let cancel_token = CancellationToken::new();
|
||||||
|
|
||||||
let user_message = request.user_message;
|
let user_message = request.user_message;
|
||||||
let conversation_so_far = request.conversation_so_far;
|
let override_conversation = request.override_conversation;
|
||||||
|
|
||||||
let task_cancel = cancel_token.clone();
|
let task_cancel = cancel_token.clone();
|
||||||
let task_tx = tx.clone();
|
let task_tx = tx.clone();
|
||||||
@@ -285,7 +288,7 @@ pub async fn reply(
|
|||||||
retry_config: None,
|
retry_config: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut all_messages = match conversation_so_far {
|
let mut all_messages = match override_conversation {
|
||||||
Some(history) => {
|
Some(history) => {
|
||||||
let conv = Conversation::new_unvalidated(history);
|
let conv = Conversation::new_unvalidated(history);
|
||||||
if let Err(e) = state
|
if let Err(e) = state
|
||||||
@@ -489,7 +492,7 @@ mod tests {
|
|||||||
.body(Body::from(
|
.body(Body::from(
|
||||||
serde_json::to_string(&ChatRequest {
|
serde_json::to_string(&ChatRequest {
|
||||||
user_message: Message::user().with_text("test message"),
|
user_message: Message::user().with_text("test message"),
|
||||||
conversation_so_far: None,
|
override_conversation: None,
|
||||||
session_id: "test-session".to_string(),
|
session_id: "test-session".to_string(),
|
||||||
recipe_name: None,
|
recipe_name: None,
|
||||||
recipe_version: None,
|
recipe_version: None,
|
||||||
|
|||||||
@@ -3898,11 +3898,12 @@
|
|||||||
"session_id"
|
"session_id"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"conversation_so_far": {
|
"override_conversation": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/components/schemas/Message"
|
"$ref": "#/components/schemas/Message"
|
||||||
},
|
},
|
||||||
|
"description": "Override the server's conversation history. Only use this when you need absolute control\nover the conversation state (e.g., administrative tools). For normal operations, the server\nis the source of truth - use truncate/fork endpoints to modify conversation history instead.",
|
||||||
"nullable": true
|
"nullable": true
|
||||||
},
|
},
|
||||||
"recipe_name": {
|
"recipe_name": {
|
||||||
|
|||||||
@@ -60,7 +60,12 @@ export type CallToolResponse = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ChatRequest = {
|
export type ChatRequest = {
|
||||||
conversation_so_far?: Array<Message> | null;
|
/**
|
||||||
|
* Override the server's conversation history. Only use this when you need absolute control
|
||||||
|
* over the conversation state (e.g., administrative tools). For normal operations, the server
|
||||||
|
* is the source of truth - use truncate/fork endpoints to modify conversation history instead.
|
||||||
|
*/
|
||||||
|
override_conversation?: Array<Message> | null;
|
||||||
recipe_name?: string | null;
|
recipe_name?: string | null;
|
||||||
recipe_version?: string | null;
|
recipe_version?: string | null;
|
||||||
session_id: string;
|
session_id: string;
|
||||||
|
|||||||
@@ -590,7 +590,6 @@ export function useChatStream({
|
|||||||
body: {
|
body: {
|
||||||
session_id: sessionId,
|
session_id: sessionId,
|
||||||
user_message: newMessage,
|
user_message: newMessage,
|
||||||
...(hasExistingMessages && { conversation_so_far: currentState.messages }),
|
|
||||||
},
|
},
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
signal: abortControllerRef.current.signal,
|
signal: abortControllerRef.current.signal,
|
||||||
@@ -771,7 +770,6 @@ export function useChatStream({
|
|||||||
body: {
|
body: {
|
||||||
session_id: targetSessionId,
|
session_id: targetSessionId,
|
||||||
user_message: updatedUserMessage,
|
user_message: updatedUserMessage,
|
||||||
conversation_so_far: truncatedMessages,
|
|
||||||
},
|
},
|
||||||
throwOnError: true,
|
throwOnError: true,
|
||||||
signal: abortControllerRef.current.signal,
|
signal: abortControllerRef.current.signal,
|
||||||
|
|||||||
Reference in New Issue
Block a user