1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Run and job execution management API endpoints.
use crate::client::LettaClient;
use crate::error::LettaResult;
use crate::types::{LettaId, LettaMessageUnion, Run, Step};
/// Run API operations.
#[derive(Debug)]
pub struct RunApi<'a> {
client: &'a LettaClient,
}
impl<'a> RunApi<'a> {
/// Create a new run API instance.
pub fn new(client: &'a LettaClient) -> Self {
Self { client }
}
/// List all runs.
///
/// # Arguments
///
/// * `agent_ids` - The agent IDs associated with the run
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn list(&self, agent_ids: &[LettaId]) -> LettaResult<Vec<Run>> {
let id_list = agent_ids.iter().map(|id| id.as_str()).collect::<Vec<_>>();
self.client
.get_with_query(&format!("v1/runs"), &[("agent_ids", id_list.join(","))])
.await
}
/// Get a specific run.
///
/// # Arguments
///
/// * `run_id` - The ID of the run to retrieve
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn get(&self, run_id: &LettaId) -> LettaResult<Run> {
self.client.get(&format!("v1/runs/{}", run_id)).await
}
/// Get messages for a run.
///
/// # Arguments
///
/// * `run_id` - The ID of the run whose messages to retrieve
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn get_messages(&self, run_id: &LettaId) -> LettaResult<Vec<LettaMessageUnion>> {
self.client
.get(&format!("v1/runs/{}/messages", run_id))
.await
}
/// Get steps for a run.
///
/// # Arguments
///
/// * `run_id` - The ID of the run whose steps to retrieve
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn get_steps(&self, run_id: &LettaId) -> LettaResult<Vec<Step>> {
self.client.get(&format!("v1/runs/{}/steps", run_id)).await
}
/// List active runs for an agent.
///
/// # Arguments
///
/// * `agent_ids` - The IDs of the agents whose runs to list
///
/// # Errors
///
/// Returns a [crate::error::LettaError] if the request fails or if the response cannot be parsed.
pub async fn list_active(&self, agent_ids: &[LettaId]) -> LettaResult<Vec<Run>> {
let id_list = agent_ids.iter().map(|id| id.as_str()).collect::<Vec<_>>();
self.client
.get_with_query(
&format!("v1/runs/active"),
&[("agent_ids", id_list.join(","))],
)
.await
}
}
/// Convenience methods for agent-specific run operations.
impl LettaClient {
/// Get the run API for this client.
pub fn runs(&self) -> RunApi {
RunApi::new(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::client::ClientConfig;
#[test]
fn test_run_api_creation() {
let config = ClientConfig::new("http://localhost:8283").unwrap();
let client = LettaClient::new(config).unwrap();
let _api = RunApi::new(&client);
}
}