Skip to main content

swink_agent_patterns/pipeline/
output.rs

1//! Pipeline output and error types.
2
3use std::time::Duration;
4
5use swink_agent::Usage;
6
7use super::types::PipelineId;
8
9// ─── StepResult ─────────────────────────────────────────────────────────────
10
11/// Per-step execution telemetry.
12#[derive(Clone, Debug)]
13pub struct StepResult {
14    /// Which agent ran this step.
15    pub agent_name: String,
16    /// The agent's text output.
17    pub response: String,
18    /// Wall-clock time for this step.
19    pub duration: Duration,
20    /// Token usage for this step.
21    pub usage: Usage,
22}
23
24// ─── PipelineOutput ─────────────────────────────────────────────────────────
25
26/// Structured result from pipeline execution.
27#[derive(Clone, Debug)]
28pub struct PipelineOutput {
29    /// Which pipeline produced this output.
30    pub pipeline_id: PipelineId,
31    /// The pipeline's final text output.
32    pub final_response: String,
33    /// Per-step telemetry.
34    pub steps: Vec<StepResult>,
35    /// Wall-clock time for the entire pipeline.
36    pub total_duration: Duration,
37    /// Aggregated token usage across all steps.
38    pub total_usage: Usage,
39}
40
41// ─── PipelineError ──────────────────────────────────────────────────────────
42
43/// Typed error variants for pipeline execution failures.
44#[derive(Debug, thiserror::Error)]
45pub enum PipelineError {
46    /// Named agent not found in factory.
47    #[error("agent not found: {name}")]
48    AgentNotFound { name: String },
49    /// Pipeline ID not in registry.
50    #[error("pipeline not found: {id}")]
51    PipelineNotFound { id: PipelineId },
52    /// A step errored during execution.
53    #[error("step {step_index} ({agent_name}) failed: {source}")]
54    StepFailed {
55        step_index: usize,
56        agent_name: String,
57        source: Box<dyn std::error::Error + Send + Sync>,
58    },
59    /// Loop hit safety cap without meeting exit condition.
60    #[error("max iterations reached: {iterations}")]
61    MaxIterationsReached { iterations: usize },
62    /// Cancellation token was triggered.
63    #[error("pipeline cancelled")]
64    Cancelled,
65    /// Regex compilation or other construction failure.
66    #[error("invalid exit condition: {message}")]
67    InvalidExitCondition { message: String },
68}