feat: agent instructions support `__TOOLS__` placeholder (#711)

pull/712/head
sigoden 2 months ago committed by GitHub
parent e349b6bb02
commit 80d3edbd43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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)]

Loading…
Cancel
Save