summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/agent.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs
index 7d1a43b..139b02d 100644
--- a/src/config/agent.rs
+++ b/src/config/agent.rs
@@ -11,6 +11,8 @@ use std::{
use serde::{Deserialize, Serialize};
+const TOOLS_PLACEHOLDER: &str = "__TOOLS__";
+
#[derive(Debug, Clone, Serialize)]
pub struct Agent {
name: String,
@@ -45,6 +47,7 @@ impl Agent {
} else {
Functions::default()
};
+ definition.replace_tools_placeholder(&functions);
let agent_config = config
.read()
.agents
@@ -279,6 +282,25 @@ impl AgentDefinition {
}
output
}
+
+ fn replace_tools_placeholder(&mut self, functions: &Functions) {
+ if self.instructions.contains(TOOLS_PLACEHOLDER) {
+ let tools = functions
+ .declarations()
+ .iter()
+ .enumerate()
+ .map(|(i, v)| {
+ let description = match v.description.split_once('\n') {
+ Some((v, _)) => v,
+ None => &v.description,
+ };
+ format!("{}. {}: {description}", i + 1, v.name)
+ })
+ .collect::<Vec<String>>()
+ .join("\n");
+ self.instructions = self.instructions.replace(TOOLS_PLACEHOLDER, &tools);
+ }
+ }
}
#[derive(Debug, Clone, Default, Deserialize, Serialize)]