fix(kernel): message_count 始终为 0 的 bug
- AgentRegistry 新增 message_counts: DashMap<AgentId, u64> 跟踪字段 - 添加 increment_message_count() 方法 - Kernel.send_message() 和 send_message_stream() 中递增计数 - get_info() 返回实际计数值而非硬编码 0
This commit is contained in:
@@ -534,6 +534,9 @@ impl Kernel {
|
||||
// Run the loop
|
||||
let result = loop_runner.run(session_id, message).await?;
|
||||
|
||||
// Track message count
|
||||
self.registry.increment_message_count(agent_id);
|
||||
|
||||
Ok(MessageResponse {
|
||||
content: result.response,
|
||||
input_tokens: result.input_tokens,
|
||||
@@ -624,6 +627,7 @@ impl Kernel {
|
||||
let loop_runner = loop_runner.with_system_prompt(&system_prompt);
|
||||
|
||||
// Run with streaming
|
||||
self.registry.increment_message_count(agent_id);
|
||||
loop_runner.run_streaming(session_id, message).await
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ pub struct AgentRegistry {
|
||||
agents: DashMap<AgentId, AgentConfig>,
|
||||
states: DashMap<AgentId, AgentState>,
|
||||
created_at: DashMap<AgentId, chrono::DateTime<Utc>>,
|
||||
message_counts: DashMap<AgentId, u64>,
|
||||
}
|
||||
|
||||
impl AgentRegistry {
|
||||
@@ -17,6 +18,7 @@ impl AgentRegistry {
|
||||
agents: DashMap::new(),
|
||||
states: DashMap::new(),
|
||||
created_at: DashMap::new(),
|
||||
message_counts: DashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +35,7 @@ impl AgentRegistry {
|
||||
self.agents.remove(id);
|
||||
self.states.remove(id);
|
||||
self.created_at.remove(id);
|
||||
self.message_counts.remove(id);
|
||||
}
|
||||
|
||||
/// Get an agent by ID
|
||||
@@ -53,7 +56,7 @@ impl AgentRegistry {
|
||||
model: config.model.model.clone(),
|
||||
provider: config.model.provider.clone(),
|
||||
state,
|
||||
message_count: 0, // TODO: Track this
|
||||
message_count: self.message_counts.get(id).map(|c| *c as usize).unwrap_or(0),
|
||||
created_at,
|
||||
updated_at: Utc::now(),
|
||||
})
|
||||
@@ -83,6 +86,11 @@ impl AgentRegistry {
|
||||
pub fn count(&self) -> usize {
|
||||
self.agents.len()
|
||||
}
|
||||
|
||||
/// Increment message count for an agent
|
||||
pub fn increment_message_count(&self, id: &AgentId) {
|
||||
self.message_counts.entry(*id).and_modify(|c| *c += 1).or_insert(1);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AgentRegistry {
|
||||
|
||||
Reference in New Issue
Block a user