diff options
| author | sigoden <sigoden@gmail.com> | 2024-12-14 13:01:55 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-14 13:01:55 +0800 |
| commit | bfb87a6669f61eaa80c6822c88a4a60efae106b7 (patch) | |
| tree | f6e73338560c7e7b8b71f2d6528a94415b4ca061 /src/config | |
| parent | bad5084e148ae1a392e3ac1ea96a6217f7f02844 (diff) | |
| download | aichat-bfb87a6669f61eaa80c6822c88a4a60efae106b7.tar.gz | |
feat: supports override agent instructions via agent config (#1057)
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/agent.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs index d3f248e..a666bdf 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -173,8 +173,6 @@ impl Agent { } pub fn export(&self) -> Result<String> { - let mut agent = self.clone(); - agent.definition.instructions = self.interpolated_instructions(); let mut value = json!({}); value["name"] = json!(self.name()); let variables = self.variables(); @@ -182,7 +180,9 @@ impl Agent { value["variables"] = serde_json::to_value(variables)?; } value["config"] = json!(self.config); - value["definition"] = json!(self.definition); + let mut definition = self.definition.clone(); + definition.instructions = self.interpolated_instructions(); + value["definition"] = json!(definition); value["functions_dir"] = Config::agent_functions_dir(&self.name) .display() .to_string() @@ -224,6 +224,7 @@ impl Agent { .session_dynamic_instructions .clone() .or_else(|| self.shared_dynamic_instructions.clone()) + .or_else(|| self.config.instructions.clone()) .unwrap_or_else(|| self.definition.instructions.clone()); for (k, v) in self.variables() { output = output.replace(&format!("{{{{{k}}}}}"), v) @@ -398,6 +399,8 @@ pub struct AgentConfig { pub use_tools: Option<String>, #[serde(skip_serializing_if = "Option::is_none")] pub agent_prelude: Option<String>, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub instructions: Option<String>, #[serde(default, skip_serializing_if = "IndexMap::is_empty")] pub variables: AgentVariables, } @@ -437,6 +440,9 @@ impl AgentConfig { if let Some(v) = read_env_value::<String>(&with_prefix("agent_prelude")) { self.agent_prelude = v; } + if let Some(v) = read_env_value::<String>(&with_prefix("instructions")) { + self.instructions = v; + } if let Ok(v) = env::var(with_prefix("variables")) { if let Ok(v) = serde_json::from_str(&v) { self.variables = v; |
