rs_adk/plugin/
context_filter.rs1use async_trait::async_trait;
8
9use super::{Plugin, PluginResult};
10use crate::context::InvocationContext;
11
12pub struct ContextFilterPlugin {
20 max_turns: Option<usize>,
22 exclude_tool_turns: bool,
24}
25
26impl ContextFilterPlugin {
27 pub fn new() -> Self {
29 Self {
30 max_turns: None,
31 exclude_tool_turns: false,
32 }
33 }
34
35 pub fn with_max_turns(mut self, max_turns: usize) -> Self {
37 self.max_turns = Some(max_turns);
38 self
39 }
40
41 pub fn with_exclude_tool_turns(mut self, exclude: bool) -> Self {
43 self.exclude_tool_turns = exclude;
44 self
45 }
46
47 pub fn max_turns(&self) -> Option<usize> {
49 self.max_turns
50 }
51
52 pub fn exclude_tool_turns(&self) -> bool {
54 self.exclude_tool_turns
55 }
56}
57
58impl Default for ContextFilterPlugin {
59 fn default() -> Self {
60 Self::new()
61 }
62}
63
64#[async_trait]
65impl Plugin for ContextFilterPlugin {
66 fn name(&self) -> &str {
67 "context_filter"
68 }
69
70 async fn before_model(
71 &self,
72 _request: &crate::llm::LlmRequest,
73 _ctx: &InvocationContext,
74 ) -> PluginResult {
75 PluginResult::Continue
80 }
81}
82
83#[cfg(test)]
84mod tests {
85 use super::*;
86
87 #[test]
88 fn default_config() {
89 let plugin = ContextFilterPlugin::new();
90 assert!(plugin.max_turns().is_none());
91 assert!(!plugin.exclude_tool_turns());
92 }
93
94 #[test]
95 fn custom_config() {
96 let plugin = ContextFilterPlugin::new()
97 .with_max_turns(10)
98 .with_exclude_tool_turns(true);
99 assert_eq!(plugin.max_turns(), Some(10));
100 assert!(plugin.exclude_tool_turns());
101 }
102
103 #[test]
104 fn plugin_name() {
105 let plugin = ContextFilterPlugin::new();
106 assert_eq!(plugin.name(), "context_filter");
107 }
108}