1use crate::{CallbackContext, Content, LlmRequest, LlmResponse, ReadonlyContext, Result};
2use std::future::Future;
3use std::pin::Pin;
4use std::sync::Arc;
5
6pub type BeforeAgentCallback = Box<
8 dyn Fn(
9 Arc<dyn CallbackContext>,
10 ) -> Pin<Box<dyn Future<Output = Result<Option<Content>>> + Send>>
11 + Send
12 + Sync,
13>;
14pub type AfterAgentCallback = Box<
15 dyn Fn(
16 Arc<dyn CallbackContext>,
17 ) -> Pin<Box<dyn Future<Output = Result<Option<Content>>> + Send>>
18 + Send
19 + Sync,
20>;
21
22#[derive(Debug)]
24pub enum BeforeModelResult {
25 Continue(LlmRequest),
27 Skip(LlmResponse),
29}
30
31pub type BeforeModelCallback = Box<
34 dyn Fn(
35 Arc<dyn CallbackContext>,
36 LlmRequest,
37 ) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult>> + Send>>
38 + Send
39 + Sync,
40>;
41pub type AfterModelCallback = Box<
42 dyn Fn(
43 Arc<dyn CallbackContext>,
44 LlmResponse,
45 ) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>>> + Send>>
46 + Send
47 + Sync,
48>;
49
50pub type BeforeToolCallback = Box<
52 dyn Fn(
53 Arc<dyn CallbackContext>,
54 ) -> Pin<Box<dyn Future<Output = Result<Option<Content>>> + Send>>
55 + Send
56 + Sync,
57>;
58pub type AfterToolCallback = Box<
59 dyn Fn(
60 Arc<dyn CallbackContext>,
61 ) -> Pin<Box<dyn Future<Output = Result<Option<Content>>> + Send>>
62 + Send
63 + Sync,
64>;
65
66pub type InstructionProvider = Box<
68 dyn Fn(Arc<dyn ReadonlyContext>) -> Pin<Box<dyn Future<Output = Result<String>> + Send>>
69 + Send
70 + Sync,
71>;
72pub type GlobalInstructionProvider = InstructionProvider;