Skip to main content

SgrAgent

Trait SgrAgent 

Source
pub trait SgrAgent {
    type Action: Send + Sync;
    type Msg: AgentMessage + Send + Sync;
    type Error: Display + Send;

    // Required methods
    fn decide(
        &self,
        messages: &[Self::Msg],
    ) -> impl Future<Output = Result<StepDecision<Self::Action>, Self::Error>> + Send;
    fn execute(
        &self,
        action: &Self::Action,
    ) -> impl Future<Output = Result<ActionResult, Self::Error>> + Send;
    fn action_signature(action: &Self::Action) -> String;

    // Provided method
    fn action_category(action: &Self::Action) -> String { ... }
}
Expand description

Base SGR Agent trait — implement per project.

Covers the non-streaming case (va-agent, simple CLIs). For streaming, implement SgrAgentStream on top.

§Stateful executors

If execute needs mutable state (e.g. MCP connections), use interior mutability (Mutex, RwLock). The trait takes &self to allow concurrent action execution in the future.

Required Associated Types§

Source

type Action: Send + Sync

The action union type (BAML-generated, project-specific).

Source

type Msg: AgentMessage + Send + Sync

The message type (implements AgentMessage).

Source

type Error: Display + Send

Error type.

Required Methods§

Source

fn decide( &self, messages: &[Self::Msg], ) -> impl Future<Output = Result<StepDecision<Self::Action>, Self::Error>> + Send

Call LLM to decide next actions.

Source

fn execute( &self, action: &Self::Action, ) -> impl Future<Output = Result<ActionResult, Self::Error>> + Send

Execute a single action. Returns tool output + done flag. Does NOT push to session — the loop handles that.

Source

fn action_signature(action: &Self::Action) -> String

String signature for loop detection (exact match).

Provided Methods§

Source

fn action_category(action: &Self::Action) -> String

Coarse category for semantic loop detection.

Default: normalize the signature (strips bash flags, quotes, fallbacks). Override for project-specific normalization.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§