summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/agent.rs17
-rw-r--r--src/config/mod.rs3
-rw-r--r--src/config/session.rs4
3 files changed, 18 insertions, 6 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs
index 5f36097..5f78e4b 100644
--- a/src/config/agent.rs
+++ b/src/config/agent.rs
@@ -11,8 +11,6 @@ use std::{
use serde::{Deserialize, Serialize};
-const TOOLS_PLACEHOLDER: &str = "__TOOLS__";
-
#[derive(Debug, Clone, Serialize)]
pub struct Agent {
name: String,
@@ -94,7 +92,9 @@ impl Agent {
}
pub fn export(&self) -> Result<String> {
- let mut value = serde_json::json!(self);
+ let mut agent = self.clone();
+ agent.definition.instructions = self.interpolated_instructions();
+ let mut value = serde_json::json!(agent);
value["functions_dir"] = Config::agent_functions_dir(&self.name)?
.display()
.to_string()
@@ -135,6 +135,10 @@ impl Agent {
&self.definition.conversation_starters
}
+ pub fn interpolated_instructions(&self) -> String {
+ self.definition.interpolated_instructions()
+ }
+
pub fn variables(&self) -> &[AgentVariable] {
&self.definition.variables
}
@@ -154,7 +158,7 @@ impl Agent {
impl RoleLike for Agent {
fn to_role(&self) -> Role {
- let prompt = self.definition.interpolated_instructions();
+ let prompt = self.interpolated_instructions();
let mut role = Role::new("", &prompt);
role.sync(self);
role
@@ -286,7 +290,8 @@ impl AgentDefinition {
}
fn replace_tools_placeholder(&mut self, functions: &Functions) {
- if self.instructions.contains(TOOLS_PLACEHOLDER) {
+ let tools_placeholder: &str = "{{__tools__}}";
+ if self.instructions.contains(tools_placeholder) {
let tools = functions
.declarations()
.iter()
@@ -300,7 +305,7 @@ impl AgentDefinition {
})
.collect::<Vec<String>>()
.join("\n");
- self.instructions = self.instructions.replace(TOOLS_PLACEHOLDER, &tools);
+ self.instructions = self.instructions.replace(tools_placeholder, &tools);
}
}
}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index c9a4a73..8f719f4 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -861,6 +861,9 @@ impl Config {
pub fn clear_session_messages(&mut self) -> Result<()> {
if let Some(session) = self.session.as_mut() {
session.clear_messages();
+ if let Some(prompt) = self.agent.as_ref().map(|v| v.interpolated_instructions()) {
+ session.update_role_prompt(&prompt);
+ }
} else {
bail!("No session")
}
diff --git a/src/config/session.rs b/src/config/session.rs
index fe94aee..eccffa9 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -249,6 +249,10 @@ impl Session {
self.dirty = true;
}
+ pub fn update_role_prompt(&mut self, prompt: &str) {
+ self.role_prompt = prompt.to_string();
+ }
+
pub fn clear_role(&mut self) {
self.role_name.clear();
self.role_prompt.clear();