Compare commits

...

2 commits

Author SHA1 Message Date
32f8a10825 fix: normalize episodic/compact roles to system in all LLM providers
All checks were successful
BotServer CI/CD / build (push) Successful in 4m1s
2026-04-14 13:47:18 -03:00
d6527a438b fix: normalize roles to system for bedrock and vertex LLM providers 2026-04-14 13:44:12 -03:00
4 changed files with 26 additions and 4 deletions

View file

@ -59,7 +59,17 @@ impl BedrockClient {
let mut messages_limited = Vec::new();
if let Some(msg_array) = raw_messages.as_array() {
for msg in msg_array {
messages_limited.push(msg.clone());
let role = msg.get("role").and_then(|r| r.as_str()).unwrap_or("user");
let normalized_role = match role {
"user" | "assistant" | "system" | "developer" | "tool" => role,
"episodic" | "compact" => "system",
_ => "user",
};
let mut new_msg = msg.clone();
if let Some(obj) = new_msg.as_object_mut() {
obj.insert("role".to_string(), serde_json::json!(normalized_role));
}
messages_limited.push(new_msg);
}
}
Value::Array(messages_limited)

View file

@ -207,8 +207,13 @@ impl LLMProvider for GLMClient {
let role = m.get("role")?.as_str()?;
let content = m.get("content")?.as_str()?;
let sanitized = Self::sanitize_utf8(content);
let normalized_role = match role {
"user" | "assistant" | "system" | "tool" => role,
"episodic" | "compact" => "system",
_ => "user",
};
Some(GLMMessage {
role: role.to_string(),
role: normalized_role.to_string(),
content: Some(sanitized),
tool_calls: None,
})

View file

@ -211,8 +211,13 @@ impl LLMProvider for KimiClient {
let role = m.get("role")?.as_str()?;
let content = m.get("content")?.as_str()?;
let sanitized = Self::sanitize_utf8(content);
let normalized_role = match role {
"user" | "assistant" | "system" | "tool" => role,
"episodic" | "compact" => "system",
_ => "user",
};
Some(KimiMessage {
role: role.to_string(),
role: normalized_role.to_string(),
content: Some(sanitized),
tool_calls: None,
})

View file

@ -231,8 +231,10 @@ impl VertexClient {
let content = msg.get("content").and_then(|c| c.as_str()).unwrap_or("");
let gemini_role = match role {
"user" => "user",
"assistant" => "model",
"system" => "user", // Gemini doesn't have system role in 'contents' by default, often wrapped in systemInstruction
"system" | "episodic" | "compact" => "user",
"tool" => "user",
_ => "user",
};