feat(agent): inject current datetime into every user message
Prepends [YYYY-MM-DD HH:MM:SS TZ] to each user message before it reaches the model. This gives the agent accurate temporal context on every turn, not just session start. Previously DateTimeSection only injected the time once when the system prompt was built. Long conversations or cron jobs had stale timestamps. Now every message carries the real time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
77a3b39ff7
commit
baa01dab66
@ -485,10 +485,11 @@ impl Agent {
|
||||
.await
|
||||
.unwrap_or_default();
|
||||
|
||||
let now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S %Z");
|
||||
let enriched = if context.is_empty() {
|
||||
user_message.to_string()
|
||||
format!("[{now}] {user_message}")
|
||||
} else {
|
||||
format!("{context}{user_message}")
|
||||
format!("{context}[{now}] {user_message}")
|
||||
};
|
||||
|
||||
self.history
|
||||
|
||||
@ -2992,10 +2992,11 @@ pub async fn run(
|
||||
.map(|r| build_hardware_context(r, &msg, &board_names, rag_limit))
|
||||
.unwrap_or_default();
|
||||
let context = format!("{mem_context}{hw_context}");
|
||||
let now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S %Z");
|
||||
let enriched = if context.is_empty() {
|
||||
msg.clone()
|
||||
format!("[{now}] {msg}")
|
||||
} else {
|
||||
format!("{context}{msg}")
|
||||
format!("{context}[{now}] {msg}")
|
||||
};
|
||||
|
||||
let mut history = vec![
|
||||
@ -3116,10 +3117,11 @@ pub async fn run(
|
||||
.map(|r| build_hardware_context(r, &user_input, &board_names, rag_limit))
|
||||
.unwrap_or_default();
|
||||
let context = format!("{mem_context}{hw_context}");
|
||||
let now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S %Z");
|
||||
let enriched = if context.is_empty() {
|
||||
user_input.clone()
|
||||
format!("[{now}] {user_input}")
|
||||
} else {
|
||||
format!("{context}{user_input}")
|
||||
format!("{context}[{now}] {user_input}")
|
||||
};
|
||||
|
||||
history.push(ChatMessage::user(&enriched));
|
||||
@ -3347,10 +3349,11 @@ pub async fn process_message(config: Config, message: &str) -> Result<String> {
|
||||
.map(|r| build_hardware_context(r, message, &board_names, rag_limit))
|
||||
.unwrap_or_default();
|
||||
let context = format!("{mem_context}{hw_context}");
|
||||
let now = chrono::Local::now().format("%Y-%m-%d %H:%M:%S %Z");
|
||||
let enriched = if context.is_empty() {
|
||||
message.to_string()
|
||||
format!("[{now}] {message}")
|
||||
} else {
|
||||
format!("{context}{message}")
|
||||
format!("{context}[{now}] {message}")
|
||||
};
|
||||
|
||||
let mut history = vec![
|
||||
|
||||
Loading…
Reference in New Issue
Block a user