Skip to content

Commit 4d2a842

Browse files
committed
fix(memory): template cortex fallback prompts
1 parent fe05567 commit 4d2a842

5 files changed

Lines changed: 48 additions & 19 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You write daily activity summaries for the cortex.
2+
3+
Output the daily activity summary and nothing else.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
You write concise working-memory summaries for the cortex.
2+
3+
Output one narrative summary paragraph and nothing else.

src/agent/cortex.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,14 @@ impl BulletinRefreshOutcome {
372372
}
373373

374374
const CORTEX_ONE_SHOT_MAX_TURNS: usize = 1;
375-
const CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK: &str = "You write concise working-memory summaries for the cortex.\n\nOutput one narrative summary paragraph and nothing else.";
376-
const CORTEX_DAILY_SUMMARY_SYSTEM_FALLBACK: &str = "You write daily activity summaries for the cortex.\n\nOutput the daily activity summary and nothing else.";
375+
const CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK_TEMPLATE: &str =
376+
"cortex_intraday_synthesis_system_fallback";
377+
const CORTEX_DAILY_SUMMARY_SYSTEM_FALLBACK_TEMPLATE: &str = "cortex_daily_summary_system_fallback";
377378

378379
fn render_static_prompt_or_fallback(
379380
prompt_engine: &crate::prompts::engine::PromptEngine,
380381
template_name: &'static str,
381-
fallback: &'static str,
382+
fallback_template_name: &'static str,
382383
) -> String {
383384
match prompt_engine.render_static(template_name) {
384385
Ok(prompt) => prompt,
@@ -388,7 +389,9 @@ fn render_static_prompt_or_fallback(
388389
template_name,
389390
"failed to render static cortex prompt, using fallback"
390391
);
391-
fallback.to_string()
392+
prompt_engine
393+
.render_static(fallback_template_name)
394+
.expect("fallback cortex prompt template should render")
392395
}
393396
}
394397
}
@@ -3278,7 +3281,7 @@ pub async fn maybe_synthesize_intraday_batch(
32783281
let synthesis_preamble = render_static_prompt_or_fallback(
32793282
&prompt_engine,
32803283
"cortex_intraday_synthesis_system",
3281-
CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK,
3284+
CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK_TEMPLATE,
32823285
);
32833286
let prompt = prompt_engine.render_intraday_synthesis(
32843287
unsynthesized.len(),
@@ -3440,7 +3443,7 @@ pub async fn maybe_synthesize_daily_summary(
34403443
let synthesis_preamble = render_static_prompt_or_fallback(
34413444
&prompt_engine,
34423445
"cortex_daily_summary_system",
3443-
CORTEX_DAILY_SUMMARY_SYSTEM_FALLBACK,
3446+
CORTEX_DAILY_SUMMARY_SYSTEM_FALLBACK_TEMPLATE,
34443447
);
34453448
let prompt = prompt_engine.render_daily_summary(
34463449
&yesterday,
@@ -4662,17 +4665,18 @@ async fn fetch_memories_for_association(
46624665
mod tests {
46634666
use super::{
46644667
BULLETIN_REFRESH_CIRCUIT_OPEN_SECS, BULLETIN_REFRESH_CIRCUIT_OPEN_THRESHOLD, BranchTracker,
4665-
BulletinRefreshOutcome, CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK, CortexReceiverOutcome,
4666-
GatheredSections, HealthRuntimeState, MAINTENANCE_TASK_CANCEL_GRACE_SECS,
4667-
MaintenanceTimeoutAction, ReceiverClosedBehavior, Signal, SynthesisTaskBackoff,
4668-
WorkerTracker, apply_cancelled_warmup_status, build_kill_targets,
4669-
claim_detached_completion, collect_synthesis_task, detached_timeout_transition,
4670-
generate_if_dirty_under_lock, handle_cortex_receiver_result, has_completed_initial_warmup,
4671-
is_cancelled_control_result, is_terminal_control_result, maintenance_task_timeout,
4672-
maintenance_timeout_action, mark_knowledge_synthesis_version_complete,
4673-
maybe_close_bulletin_refresh_circuit, maybe_generate_bulletin_under_lock,
4674-
maybe_spawn_synthesis_task, parse_structured_success_flag, push_signal_into_buffer,
4675-
record_bulletin_refresh_failure, render_static_prompt_or_fallback, should_execute_warmup,
4668+
BulletinRefreshOutcome, CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK_TEMPLATE,
4669+
CortexReceiverOutcome, GatheredSections, HealthRuntimeState,
4670+
MAINTENANCE_TASK_CANCEL_GRACE_SECS, MaintenanceTimeoutAction, ReceiverClosedBehavior,
4671+
Signal, SynthesisTaskBackoff, WorkerTracker, apply_cancelled_warmup_status,
4672+
build_kill_targets, claim_detached_completion, collect_synthesis_task,
4673+
detached_timeout_transition, generate_if_dirty_under_lock, handle_cortex_receiver_result,
4674+
has_completed_initial_warmup, is_cancelled_control_result, is_terminal_control_result,
4675+
maintenance_task_timeout, maintenance_timeout_action,
4676+
mark_knowledge_synthesis_version_complete, maybe_close_bulletin_refresh_circuit,
4677+
maybe_generate_bulletin_under_lock, maybe_spawn_synthesis_task,
4678+
parse_structured_success_flag, push_signal_into_buffer, record_bulletin_refresh_failure,
4679+
render_static_prompt_or_fallback, should_execute_warmup,
46764680
should_generate_bulletin_from_bulletin_loop, signal_from_event, summarize_signal_text,
46774681
take_lagged_control_flag,
46784682
};
@@ -4717,10 +4721,15 @@ mod tests {
47174721
let prompt = render_static_prompt_or_fallback(
47184722
&prompt_engine,
47194723
"missing_cortex_synthesis_template",
4720-
CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK,
4724+
CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK_TEMPLATE,
47214725
);
47224726

4723-
assert_eq!(prompt, CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK);
4727+
assert_eq!(
4728+
prompt,
4729+
prompt_engine
4730+
.render_static(CORTEX_INTRADAY_SYNTHESIS_SYSTEM_FALLBACK_TEMPLATE)
4731+
.expect("fallback prompt should render")
4732+
);
47244733
}
47254734

47264735
#[test]

src/prompts/engine.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ impl PromptEngine {
6969
"cortex_intraday_synthesis_system",
7070
crate::prompts::text::get("cortex_intraday_synthesis_system"),
7171
)?;
72+
env.add_template(
73+
"cortex_intraday_synthesis_system_fallback",
74+
crate::prompts::text::get("cortex_intraday_synthesis_system_fallback"),
75+
)?;
7276
env.add_template(
7377
"cortex_daily_summary",
7478
crate::prompts::text::get("cortex_daily_summary"),
@@ -77,6 +81,10 @@ impl PromptEngine {
7781
"cortex_daily_summary_system",
7882
crate::prompts::text::get("cortex_daily_summary_system"),
7983
)?;
84+
env.add_template(
85+
"cortex_daily_summary_system_fallback",
86+
crate::prompts::text::get("cortex_daily_summary_system_fallback"),
87+
)?;
8088
env.add_template("compactor", crate::prompts::text::get("compactor"))?;
8189
env.add_template(
8290
"memory_persistence",

src/prompts/text.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ fn lookup(lang: &str, key: &str) -> &'static str {
6868
("en", "cortex_intraday_synthesis_system") => {
6969
include_str!("../../prompts/en/cortex_intraday_synthesis_system.md.j2")
7070
}
71+
("en", "cortex_intraday_synthesis_system_fallback") => {
72+
include_str!("../../prompts/en/cortex_intraday_synthesis_system_fallback.md.j2")
73+
}
7174
("en", "cortex_daily_summary") => {
7275
include_str!("../../prompts/en/cortex_daily_summary.md.j2")
7376
}
7477
("en", "cortex_daily_summary_system") => {
7578
include_str!("../../prompts/en/cortex_daily_summary_system.md.j2")
7679
}
80+
("en", "cortex_daily_summary_system_fallback") => {
81+
include_str!("../../prompts/en/cortex_daily_summary_system_fallback.md.j2")
82+
}
7783
("en", "cortex_profile") => include_str!("../../prompts/en/cortex_profile.md.j2"),
7884
("en", "compactor") => include_str!("../../prompts/en/compactor.md.j2"),
7985
("en", "memory_persistence") => include_str!("../../prompts/en/memory_persistence.md.j2"),

0 commit comments

Comments
 (0)