Skip to content

Commit e3cf013

Browse files
chore: remove duplicate and unused API code from the agent crate (#3342)
1 parent 5ea7f6a commit e3cf013

File tree

28 files changed

+36
-4813
lines changed

28 files changed

+36
-4813
lines changed

crates/agent/src/agent/agent_loop/model.rs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ use std::sync::{
66
use std::time::Duration;
77

88
use futures::Stream;
9-
use serde::{
10-
Deserialize,
11-
Serialize,
12-
};
139
use tokio::sync::mpsc;
1410
use tokio_stream::wrappers::ReceiverStream;
1511
use tokio_util::sync::CancellationToken;
@@ -27,7 +23,6 @@ use super::types::{
2723
Message,
2824
ToolSpec,
2925
};
30-
use crate::agent::rts::RtsModel;
3126

3227
/// Represents a backend implementation for a converse stream compatible API.
3328
///
@@ -51,59 +46,6 @@ pub trait Model: std::fmt::Debug + Send + Sync + 'static {
5146
}
5247
}
5348

54-
/// The supported backends
55-
#[derive(Debug, Clone)]
56-
pub enum Models {
57-
Rts(RtsModel),
58-
Test(MockModel),
59-
}
60-
61-
impl Models {
62-
pub fn state(&self) -> ModelsState {
63-
match self {
64-
Models::Rts(v) => ModelsState::Rts {
65-
conversation_id: Some(v.conversation_id().to_string()),
66-
model_id: v.model_id().map(String::from),
67-
},
68-
Models::Test(_) => ModelsState::Test,
69-
}
70-
}
71-
}
72-
73-
/// A serializable representation of the state contained within [Models].
74-
#[derive(Debug, Clone, Serialize, Deserialize)]
75-
pub enum ModelsState {
76-
Rts {
77-
conversation_id: Option<String>,
78-
model_id: Option<String>,
79-
},
80-
Test,
81-
}
82-
83-
impl Default for ModelsState {
84-
fn default() -> Self {
85-
Self::Rts {
86-
conversation_id: None,
87-
model_id: None,
88-
}
89-
}
90-
}
91-
92-
impl Model for Models {
93-
fn stream(
94-
&self,
95-
messages: Vec<Message>,
96-
tool_specs: Option<Vec<ToolSpec>>,
97-
system_prompt: Option<String>,
98-
cancel_token: CancellationToken,
99-
) -> Pin<Box<dyn Stream<Item = StreamResult> + Send + 'static>> {
100-
match self {
101-
Models::Rts(rts_model) => rts_model.stream(messages, tool_specs, system_prompt, cancel_token),
102-
Models::Test(test_model) => test_model.stream(messages, tool_specs, system_prompt, cancel_token),
103-
}
104-
}
105-
}
106-
10749
#[derive(Debug, Clone)]
10850
pub struct MockModel {
10951
inner: Arc<Mutex<mock::Inner>>,

crates/agent/src/agent/agent_loop/types.rs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ use serde_json::Map;
1414
use tracing::error;
1515
use uuid::Uuid;
1616

17-
use crate::api_client::error::{
18-
ApiClientError,
19-
ConverseStreamError,
20-
};
21-
2217
#[derive(Debug, Clone, Serialize, Deserialize)]
2318
#[serde(rename_all = "camelCase")]
2419
pub enum StreamEvent {
@@ -74,12 +69,10 @@ impl StreamError {
7469
self
7570
}
7671

77-
/// Helper for downcasting the error source to [ConverseStreamError].
78-
///
79-
/// Just defining this here for simplicity
80-
pub fn as_rts_error(&self) -> Option<&ConverseStreamError> {
72+
/// Helper for downcasting a [StreamErrorSource] to a concrete type.
73+
pub fn as_concrete_error<T: StreamErrorSource>(&self) -> Option<&T> {
8174
if let Some(source) = &self.source {
82-
(*source).as_any().downcast_ref::<ConverseStreamError>()
75+
(*source).as_any().downcast_ref::<T>()
8376
} else {
8477
None
8578
}
@@ -164,18 +157,6 @@ pub trait StreamErrorSource: std::any::Any + std::error::Error + Send + Sync {
164157
fn as_any(&self) -> &dyn std::any::Any;
165158
}
166159

167-
impl StreamErrorSource for ConverseStreamError {
168-
fn as_any(&self) -> &dyn std::any::Any {
169-
self
170-
}
171-
}
172-
173-
impl StreamErrorSource for ApiClientError {
174-
fn as_any(&self) -> &dyn std::any::Any {
175-
self
176-
}
177-
}
178-
179160
#[derive(Debug, Clone, Serialize, Deserialize)]
180161
#[serde(rename_all = "camelCase")]
181162
pub struct Message {
@@ -573,7 +554,6 @@ mod tests {
573554
use std::str::FromStr;
574555

575556
use super::*;
576-
use crate::api_client::error::ConverseStreamErrorKind;
577557

578558
macro_rules! test_ser_deser {
579559
($ty:ident, $variant:expr, $text:expr) => {
@@ -585,19 +565,6 @@ mod tests {
585565
};
586566
}
587567

588-
#[test]
589-
fn test_other_stream_err_downcasting() {
590-
let err = StreamError::new(StreamErrorKind::Interrupted).with_source(Arc::new(ConverseStreamError::new(
591-
ConverseStreamErrorKind::ModelOverloadedError,
592-
None::<aws_smithy_types::error::operation::BuildError>, /* annoying type inference
593-
* required */
594-
)));
595-
assert!(
596-
err.as_rts_error()
597-
.is_some_and(|r| matches!(r.kind, ConverseStreamErrorKind::ModelOverloadedError))
598-
);
599-
}
600-
601568
#[test]
602569
fn test_image_format_ser_deser() {
603570
test_ser_deser!(ImageFormat, ImageFormat::Gif, "gif");

crates/agent/src/agent/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod consts;
44
pub mod mcp;
55
mod permissions;
66
pub mod protocol;
7-
pub mod rts;
87
pub mod task_executor;
98
mod tool_utils;
109
pub mod tools;

0 commit comments

Comments
 (0)