Skip to main content

sim_lib_agent/
roles.rs

1use sim_kernel::Symbol;
2use sim_lib_server::{FrameEnvelope, ServerFrame};
3
4/// Role an agent plays in a multi-agent exchange.
5#[derive(Clone, Debug, PartialEq, Eq)]
6pub enum AgentRole {
7    /// Decomposes goals and directs other agents.
8    Planner,
9    /// Carries out assigned work.
10    Worker,
11    /// Critiques outputs.
12    Critic,
13    /// Judges or scores outputs.
14    Judge,
15    /// Verifies correctness of outputs.
16    Verifier,
17    /// Produces user-facing voice or narration.
18    Voice,
19    /// The human or external user.
20    User,
21    /// System-level instruction source.
22    System,
23    /// A tool invocation participant.
24    Tool,
25    /// Retrieves supporting context.
26    Retriever,
27    /// Records events and traces.
28    Recorder,
29    /// A caller-defined role tagged by symbol.
30    Custom(Symbol),
31}
32
33impl AgentRole {
34    /// Returns the canonical symbol naming this role.
35    pub fn as_symbol(&self) -> Symbol {
36        match self {
37            Self::Planner => Symbol::new("planner"),
38            Self::Worker => Symbol::new("worker"),
39            Self::Critic => Symbol::new("critic"),
40            Self::Judge => Symbol::new("judge"),
41            Self::Verifier => Symbol::new("verifier"),
42            Self::Voice => Symbol::new("voice"),
43            Self::User => Symbol::new("user"),
44            Self::System => Symbol::new("system"),
45            Self::Tool => Symbol::new("tool"),
46            Self::Retriever => Symbol::new("retriever"),
47            Self::Recorder => Symbol::new("recorder"),
48            Self::Custom(symbol) => symbol.clone(),
49        }
50    }
51}
52
53/// Stamps the role onto a frame envelope and increments its hop count.
54pub fn stamp_envelope_role(envelope: &mut FrameEnvelope, role: &AgentRole) {
55    envelope.role = Some(role.as_symbol());
56    envelope.hop = envelope.hop.saturating_add(1);
57}
58
59/// Stamps the role onto a server frame's envelope.
60pub fn stamp_frame_role(frame: &mut ServerFrame, role: &AgentRole) {
61    stamp_envelope_role(&mut frame.envelope, role);
62}