summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-07-13 13:02:23 +0800
committerGitHub <noreply@github.com>2024-07-13 13:02:23 +0800
commit80d3edbd43e874bb30decf1c5d13834a9a896007 (patch)
treece342eeac98353f85255834b5955b8542cab8683 /src
parente349b6bb0242d64967a7e163fe7a948ded5220eb (diff)
downloadaichat-80d3edbd43e874bb30decf1c5d13834a9a896007.tar.gz
feat: agent instructions support `__TOOLS__` placeholder (#711)
Diffstat (limited to 'src')
-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)]