gemini_adk_rs/code_executors/
base.rs1use super::types::{CodeExecutionInput, CodeExecutionResult};
2use async_trait::async_trait;
3
4#[derive(Debug, thiserror::Error)]
6pub enum CodeExecutorError {
7 #[error("Code execution failed: {0}")]
9 ExecutionFailed(String),
10 #[error("Unsupported model: {0}")]
12 UnsupportedModel(String),
13 #[error("Execution timed out after {0}s")]
15 Timeout(u64),
16 #[error("{0}")]
18 Other(String),
19}
20
21#[async_trait]
23pub trait CodeExecutor: Send + Sync {
24 fn code_block_delimiters(&self) -> Vec<(String, String)> {
26 vec![
27 ("```tool_code\n".into(), "\n```".into()),
28 ("```python\n".into(), "\n```".into()),
29 ]
30 }
31
32 fn execution_result_delimiters(&self) -> (String, String) {
34 ("```tool_output\n".into(), "\n```".into())
35 }
36
37 fn error_retry_attempts(&self) -> u32 {
39 2
40 }
41
42 fn stateful(&self) -> bool {
44 false
45 }
46
47 async fn execute_code(
49 &self,
50 input: CodeExecutionInput,
51 ) -> Result<CodeExecutionResult, CodeExecutorError>;
52}