huskies: merge 1143 story Decouple LLM environmental awareness from chat transport — persona-keyed sessions and a real-time event subscription

This commit is contained in:
dave
2026-05-18 16:52:45 +00:00
parent e58ff4465a
commit fb4e52dd09
15 changed files with 281 additions and 77 deletions
@@ -303,12 +303,12 @@ pub(super) async fn handle_incoming_message(
/// Build the prompt for a Discord LLM turn, prepending any pending
/// CRDT pipeline-transition events as a `<system-reminder>` block.
fn build_discord_llm_prompt(
session_id: &str,
persona: &str,
bot_name: &str,
user: &str,
user_message: &str,
) -> String {
let event_ctx = crate::llm_session::assemble_prompt_context(session_id);
let event_ctx = crate::llm_session::assemble_prompt_context(persona);
format!(
"{event_ctx}[Your name is {bot_name}. Refer to yourself as {bot_name}, not Claude.]\n\n{user}: {user_message}"
)
@@ -328,12 +328,8 @@ async fn handle_llm_message(ctx: &DiscordContext, channel: &str, user: &str, use
};
let bot_name = &ctx.services.bot_name;
let prompt = build_discord_llm_prompt(
resume_session_id.as_deref().unwrap_or(channel),
bot_name,
user,
user_message,
);
let persona = bot_name.to_lowercase();
let prompt = build_discord_llm_prompt(&persona, bot_name, user, user_message);
let provider = ClaudeCodeProvider::new();
let (_cancel_tx, mut cancel_rx) = watch::channel(false);
@@ -32,9 +32,12 @@ pub(in crate::chat::transport::matrix::bot) async fn handle_message(
};
// Pull new pipeline-transition events from the CRDT event log for this
// session and atomically advance the high-water marks so the same events
// are not re-injected on the next turn.
let event_log_ctx = crate::llm_session::assemble_prompt_context(&room_id_str);
// persona and atomically advance the high-water marks so the same events
// are not re-injected on the next turn. All transports share the same
// persona key so events are visible regardless of which transport handles
// the next turn.
let persona = ctx.services.bot_name.to_lowercase();
let event_log_ctx = crate::llm_session::assemble_prompt_context(&persona);
// The prompt is just the current message with sender attribution.
// Prior conversation context is carried by the Claude Code session.
@@ -29,9 +29,8 @@ pub(super) async fn handle_llm_message(
};
let bot_name = &ctx.services.bot_name;
let event_ctx = crate::llm_session::assemble_prompt_context(
resume_session_id.as_deref().unwrap_or(channel),
);
let persona = bot_name.to_lowercase();
let event_ctx = crate::llm_session::assemble_prompt_context(&persona);
let prompt = format!(
"{event_ctx}[Your name is {bot_name}. Refer to yourself as {bot_name}, not Claude.]\n\n{user}: {user_message}"
);
@@ -27,8 +27,8 @@ pub(super) async fn handle_llm_message(
};
let bot_name = &ctx.services.bot_name;
let event_ctx =
crate::llm_session::assemble_prompt_context(resume_session_id.as_deref().unwrap_or(sender));
let persona = bot_name.to_lowercase();
let event_ctx = crate::llm_session::assemble_prompt_context(&persona);
let prompt = format!(
"{event_ctx}[Your name is {bot_name}. Refer to yourself as {bot_name}, not Claude.]\n\n{sender}: {user_message}"
);