Skip to main content

aether_evals/agents/
agent.rs

1use crate::{Task, containers::ContainerError};
2use aether_core::events::AgentMessage;
3use futures::Stream;
4use thiserror::Error;
5
6pub type AgentRunResult = Result<AgentMessage, RunError>;
7
8/// Trait for an agent under evaluation.
9///
10/// Implementors run a [`Task`] in their configured execution environment and stream the observed
11/// [`AgentMessage`]s.
12///
13/// # Example
14///
15/// ```ignore
16/// let mut messages = agent.run(Task::new("write hello.txt"));
17/// ```
18pub trait Agent: Send + Sync {
19    fn run(&self, task: Task) -> impl Stream<Item = AgentRunResult> + Send + '_;
20}
21
22/// Errors that can occur when running an agent
23#[derive(Debug, Error)]
24pub enum RunError {
25    #[error("Agent execution failed: {0}")]
26    ExecutionFailed(String),
27
28    #[error("Agent configuration error: {0}")]
29    ConfigurationError(String),
30
31    #[error("Agent command exited without emitting a terminal AgentMessage: {stderr}")]
32    CommandExitWithoutTerminal { stderr: String },
33
34    #[error("Agent command emitted invalid AgentMessage JSON line: {line}")]
35    AgentMessageJsonLine {
36        line: String,
37        #[source]
38        source: serde_json::Error,
39    },
40
41    #[error(transparent)]
42    Container(#[from] ContainerError),
43}