Files
agcore/src/engine/snapshot.rs
T
徐涛 6676322666 fix(core): 修复 v0.3.0 审查发现的 6 项警告问题
- InMemoryGraph 的 10 处 lock().unwrap() 改为错误传播,避免 Mutex poison 时 panic
- SubTaskResult 添加 Serialize/Deserialize,支持结果序列化
- dispatch_all 移除多余的 task.clone()
- truncate_total_chars 补充字节切片安全性注释
- SessionManager::children 添加 ponytail 注释标记 O(N) 扫描现状
- SessionMemoryEntry.created_at 添加 i64 类型说明注释
2026-07-17 15:59:02 +08:00

39 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! SessionSnapshot —— 见下文 doc comment。Step 3 将填充完整实现。
//! Step 2 仅占位:定义空 struct + derive,使 `engine` 模块编译通过。
use serde::{Deserialize, Serialize};
/// SessionMemory 条目的可序列化形式(保留元数据与时间戳)。
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SessionMemoryEntry {
/// 原始值(字符串)。
pub value: String,
/// 元数据(自由 JSON)。
#[serde(default)]
pub metadata: serde_json::Value,
/// 创建时间(Unix 时间戳秒;`None` 兼容旧快照)。
///
/// 类型为 `i64` 而非 `u64``time` crate 的 `OffsetDateTime::from_unix_timestamp` 接收 `i64`
/// 这里保持与 `SessionMemory::set_with_meta` 签名一致,避免来回转换。
#[serde(default)]
pub created_at: Option<i64>,
}
/// AgentSession 的可序列化快照。
///
/// Step 2 占位:字段已定义但未实装 to_snapshot/from_snapshot。
/// Step 3 将基于 `#[serde(default)]` 宽松反序列化,添加 `agent_name`/`turn_index`/slot 等字段。
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct SessionSnapshot {
pub session_id: String,
pub agent_name: String,
pub turn_index: u32,
#[serde(default)]
pub cost_so_far: crate::llm::types::usage::CostTracker,
#[serde(default)]
pub slots: std::collections::HashMap<String, crate::agent::context::ContextSlot>,
pub current_slot_id: String,
pub last_summary_turn: Option<u32>,
#[serde(default)]
pub session_memory_data: std::collections::HashMap<String, SessionMemoryEntry>,
}