A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
//! Structured diagnostics attached to assistant messages on failures and recoveries; the types are
//! the shared [`AssistantMessageDiagnostic`] / [`DiagnosticErrorInfo`] from `pa-types`.
pub use crate::types::{AssistantMessage, AssistantMessageDiagnostic, DiagnosticErrorInfo};
#[must_use]
// Epoch millis fit u64 for ~584 million years; the u128 duration's millis are the timestamp's convention.
#[allow(clippy::cast_possible_truncation)]
pub fn now_ms() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(0, |d| d.as_millis() as u64)
}
#[must_use]
pub fn create_assistant_message_diagnostic(
diagnostic_type: &str,
error: Option<DiagnosticErrorInfo>,
details: Option<serde_json::Value>,
) -> AssistantMessageDiagnostic {
AssistantMessageDiagnostic {
type_: diagnostic_type.to_string(),
timestamp: now_ms(),
error,
details: details.and_then(|value| value.as_object().cloned()),
}
}
/// Append a diagnostic to a message, preserving existing entries.
pub fn append_assistant_message_diagnostic(
message: &mut AssistantMessage,
diagnostic: AssistantMessageDiagnostic,
) {
message
.diagnostics
.get_or_insert_with(Vec::new)
.push(diagnostic);
}