Publish durable AHP contract events derived from runtime AgentEvents.
(&self, event: &AgentEvent, run_id: &str, session_id: &str)
| 502 | |
| 503 | /// Publish durable AHP contract events derived from runtime AgentEvents. |
| 504 | pub async fn publish_agent_event(&self, event: &AgentEvent, run_id: &str, session_id: &str) { |
| 505 | self.record_event(); |
| 506 | self.record_runtime_agent_event(event, run_id); |
| 507 | |
| 508 | let mut events = crate::ahp::agent_event_to_ahp_events( |
| 509 | event, |
| 510 | run_id, |
| 511 | session_id, |
| 512 | &self.agent_id, |
| 513 | self.depth, |
| 514 | ); |
| 515 | if events.is_empty() { |
| 516 | return; |
| 517 | } |
| 518 | let context = self.build_context(); |
| 519 | for event in &mut events { |
| 520 | event.context = context.clone(); |
| 521 | } |
| 522 | |
| 523 | let should_flush = matches!(event, AgentEvent::End { .. } | AgentEvent::Error { .. }); |
| 524 | |
| 525 | if self.batch_enabled { |
| 526 | for event in events { |
| 527 | self.add_to_batch(event).await; |
| 528 | } |
| 529 | if should_flush { |
| 530 | self.flush_batch().await; |
| 531 | } |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | for event in events { |
| 536 | if let Err(e) = self.client.send_event_full(&event).await { |
| 537 | warn!("AHP runtime contract event failed: {}", e); |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /// Publish an explicit run cancellation lifecycle event. |
| 543 | pub async fn publish_run_cancelled( |