MCPcopy Create free account
hub / github.com/AI45Lab/Code / observe_agent_event

Method observe_agent_event

core/src/ahp/runtime_state.rs:50–85  ·  view source on GitHub ↗
(&self, event: &AgentEvent, run_id: &str)

Source from the content-addressed store, hash-verified

48
49impl AhpRuntimeState {
50 pub(super) fn observe_agent_event(&self, event: &AgentEvent, run_id: &str) {
51 match event {
52 AgentEvent::ToolStart { id, .. } => {
53 write_or_recover(&self.active_tools).insert(id.clone());
54 }
55 AgentEvent::ToolEnd { id, .. } | AgentEvent::PermissionDenied { tool_id: id, .. } => {
56 write_or_recover(&self.active_tools).remove(id);
57 write_or_recover(&self.pending_confirmations).remove(id);
58 }
59 AgentEvent::ConfirmationRequired { tool_id, .. } => {
60 write_or_recover(&self.active_tools).remove(tool_id);
61 write_or_recover(&self.pending_confirmations).insert(tool_id.clone());
62 }
63 AgentEvent::ConfirmationReceived { tool_id, .. }
64 | AgentEvent::ConfirmationTimeout { tool_id, .. } => {
65 write_or_recover(&self.pending_confirmations).remove(tool_id);
66 }
67 AgentEvent::ExternalTaskPending { task_id, .. } => {
68 write_or_recover(&self.external_tasks).insert(task_id.clone());
69 }
70 AgentEvent::ExternalTaskCompleted { task_id, .. } => {
71 write_or_recover(&self.external_tasks).remove(task_id);
72 }
73 AgentEvent::TurnEnd { usage, .. } => {
74 self.add_runtime_turn_tokens(run_id, tokens_to_i32(usage.total_tokens));
75 }
76 AgentEvent::End { usage, .. } => {
77 self.set_runtime_run_tokens_at_least(run_id, tokens_to_i32(usage.total_tokens));
78 self.clear_runtime_actions();
79 }
80 AgentEvent::Error { .. } => {
81 self.clear_runtime_actions();
82 }
83 _ => {}
84 }
85 }
86
87 pub(super) fn observe_hook_event(&self, event: &HookEvent) {
88 if self.runtime_tokens_seen.load(Ordering::Relaxed) {

Calls 8

write_or_recoverFunction · 0.85
tokens_to_i32Function · 0.85
removeMethod · 0.80
clear_runtime_actionsMethod · 0.80
insertMethod · 0.45
cloneMethod · 0.45