artifactize-harness 0.27.2

The Agent evaluation harness for Artifactize.
Documentation
//! Agent eval policy and execution, independent of project declarations and session storage.

pub mod api;
pub mod backend;
pub mod budgets;
pub mod claude;
pub mod error;
mod http;
mod platform;
mod stdio_mcp;
pub mod verdict;

use std::future::Future;

use artifactize_provider::{llm::delivery::Delivery, names::ModelId};
use rig_core::{completion::ToolDefinition, message::Message};
use serde_json::Value;
use tokio_util::sync::CancellationToken;

use budgets::Limits;
use error::Attempt;
use verdict::Priority;

pub use http::{FollowUp, follow_up as follow_up_http, review as review_http};

/// The prepared inputs for a review. The engine builds the prompt and tool definitions.
pub struct Review<'a> {
    pub model: &'a ModelId,
    pub reasoning: Option<&'a str>,
    pub cache_key: &'a str,
    pub system: String,
    pub prompt: String,
    pub tools: Vec<ToolDefinition>,
    pub red_at: Option<Priority>,
    pub limits: Limits,
    pub cancellation: &'a CancellationToken,
}

/// Observations of one eval, independent of how the engine records them.
pub enum Event<'a> {
    Started {
        parameters: Value,
        tools: &'a [ToolDefinition],
    },
    Message {
        turn: usize,
        message: &'a Message,
        repair: bool,
    },
    ToolResults {
        turn: usize,
        results: &'a Message,
        failed: &'a [bool],
    },
    Delivery(Delivery),
    Attempt(Attempt),
}

/// The only access an eval has to the engine: an event sink and the offered tool invoker.
pub trait Io: Send {
    fn event(&mut self, event: Event<'_>);

    fn invoke(
        &mut self,
        name: &str,
        arguments: Value,
        cancellation: CancellationToken,
    ) -> impl Future<Output = ToolOutput> + Send;
}

/// A tool result in the shared input vocabulary of the two eval adapters.
pub struct ToolOutput {
    pub failed: bool,
    pub content: Vec<Content>,
}

impl ToolOutput {
    fn error(message: impl Into<String>) -> Self {
        Self {
            failed: true,
            content: vec![Content::Text(message.into())],
        }
    }
}

pub enum Content {
    Text(String),
    Json(Value),
    Image { data: String, mime: ImageMime },
}

#[derive(Clone, Copy)]
pub enum ImageMime {
    Png,
    Jpeg,
    Webp,
}