fix(channel): merge delivery instructions into initial system message
Some models (e.g. Qwen 3.5) enforce that all system messages must appear at the beginning of the conversation. The Telegram delivery instructions were appended as a separate system message after the user message, causing a Jinja template error. Merge them into the first system message instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6a69b47b8a
commit
a7590f9fdc
1 changed files with 14 additions and 5 deletions
|
|
@ -626,14 +626,14 @@ async fn process_channel_message(ctx: Arc<ChannelRuntimeContext>, msg: traits::C
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut history = vec![ChatMessage::system(ctx.system_prompt.as_str())];
|
let system_prompt = match channel_delivery_instructions(&msg.channel) {
|
||||||
|
Some(instructions) => format!("{}\n\n{instructions}", ctx.system_prompt),
|
||||||
|
None => ctx.system_prompt.to_string(),
|
||||||
|
};
|
||||||
|
let mut history = vec![ChatMessage::system(&system_prompt)];
|
||||||
history.append(&mut prior_turns);
|
history.append(&mut prior_turns);
|
||||||
history.push(ChatMessage::user(&enriched_message));
|
history.push(ChatMessage::user(&enriched_message));
|
||||||
|
|
||||||
if let Some(instructions) = channel_delivery_instructions(&msg.channel) {
|
|
||||||
history.push(ChatMessage::system(instructions));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if this channel supports streaming draft updates
|
// Determine if this channel supports streaming draft updates
|
||||||
let use_streaming = target_channel
|
let use_streaming = target_channel
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
@ -2304,6 +2304,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2356,6 +2357,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2417,6 +2419,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2499,6 +2502,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2557,6 +2561,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2610,6 +2615,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -2714,6 +2720,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
let (tx, rx) = tokio::sync::mpsc::channel::<traits::ChannelMessage>(4);
|
let (tx, rx) = tokio::sync::mpsc::channel::<traits::ChannelMessage>(4);
|
||||||
|
|
@ -2784,6 +2791,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
@ -3174,6 +3182,7 @@ mod tests {
|
||||||
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
reliability: Arc::new(crate::config::ReliabilityConfig::default()),
|
||||||
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
provider_runtime_options: providers::ProviderRuntimeOptions::default(),
|
||||||
workspace_dir: Arc::new(std::env::temp_dir()),
|
workspace_dir: Arc::new(std::env::temp_dir()),
|
||||||
|
channel_message_timeout_secs: 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
process_channel_message(
|
process_channel_message(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue