pe_core/macros.rs
1//! Declarative macros for pe-core.
2//!
3//! `core_state_fields!()` — convenience macro that embeds the standard
4//! `CoreState` fields into a user's state struct.
5
6/// Embeds the standard CoreState fields into a state struct.
7///
8/// These fields are required for any state that implements `CoreState`.
9/// The `#[core]` attribute signals to `#[derive(State)]` that it should
10/// generate the `CoreState` trait impl.
11///
12/// # Usage
13///
14/// ```ignore
15/// use pe_core::core_state_fields;
16///
17/// #[derive(State, Clone, Debug, Serialize, Deserialize)]
18/// struct MyAgentState {
19/// core_state_fields!(),
20///
21/// // Your custom fields here
22/// topic: String,
23/// }
24/// ```
25///
26/// # Expands to
27///
28/// ```ignore
29/// #[core]
30/// messages: Vec<Message>,
31/// #[core]
32/// iterations: u32,
33/// #[core]
34/// thread_id: String,
35/// #[core]
36/// context: ExecutionContext,
37/// ```
38#[macro_export]
39macro_rules! core_state_fields {
40 () => {
41 /// Message history — uses add_messages reducer (append + dedup by id)
42 #[core]
43 pub messages: Vec<$crate::message::Message>,
44
45 /// Current iteration count — LastValue channel
46 #[core]
47 pub iterations: u32,
48
49 /// Thread identifier — LastValue channel
50 #[core]
51 pub thread_id: String,
52
53 /// Execution context injected by runtime — LastValue channel
54 #[core]
55 pub context: $crate::state::ExecutionContext,
56 };
57}