Skip to main content

cpex_core/extensions/
agent.rs

1// Location: ./crates/cpex-core/src/extensions/agent.rs
2// Copyright 2025
3// SPDX-License-Identifier: Apache-2.0
4// Authors: Teryl Taylor
5//
6// AgentExtension — session, conversation, agent lineage.
7// Mirrors cpex/framework/extensions/agent.py.
8
9use serde::{Deserialize, Serialize};
10
11/// Conversation history context.
12#[derive(Debug, Clone, Default, Serialize, Deserialize)]
13pub struct ConversationContext {
14    /// Recent conversation history (lightweight summaries).
15    #[serde(default)]
16    pub history: Vec<serde_json::Value>,
17
18    /// LLM-generated summary of the conversation.
19    #[serde(default, skip_serializing_if = "Option::is_none")]
20    pub summary: Option<String>,
21
22    /// Detected topics in the conversation.
23    #[serde(default)]
24    pub topics: Vec<String>,
25}
26
27/// Agent execution context extension.
28///
29/// Carries session tracking, conversation context, multi-agent
30/// lineage, and the original user/agent input.
31#[derive(Debug, Clone, Default, Serialize, Deserialize)]
32pub struct AgentExtension {
33    /// Original user/agent input that triggered this action.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub input: Option<String>,
36
37    /// Broad user/agent session identifier.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub session_id: Option<String>,
40
41    /// Specific dialogue/task identifier within a session.
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub conversation_id: Option<String>,
44
45    /// Position within the conversation (0-indexed).
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub turn: Option<u32>,
48
49    /// Identifier of the agent that produced this message.
50    #[serde(default, skip_serializing_if = "Option::is_none")]
51    pub agent_id: Option<String>,
52
53    /// If spawned by another agent, the parent's ID.
54    #[serde(default, skip_serializing_if = "Option::is_none")]
55    pub parent_agent_id: Option<String>,
56
57    /// Optional conversation context with history.
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub conversation: Option<ConversationContext>,
60}