Skip to content

Commit

Permalink
feat: supports override agent instructions via agent config (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Dec 14, 2024
1 parent bad5084 commit bfb87a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions config.agent.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Location `<aichat-config-dir>/agents/<agent-name>/config.yaml`

model: openai:gpt-4o # Specify the LLM to use
temperature: null # Set default temperature parameter
top_p: null # Set default top-p parameter, range (0, 1)
temperature: null # Set default temperature parameter, range (0, 1)
top_p: null # Set default top-p parameter, with a range of (0, 1) or (0, 2) depending on the model
use_tools: null # Which additional tools to use by agent. (e.g. 'fs,web_search')
agent_prelude: null # Set a session to use when starting the agent. (e.g. temp, default)

instructions: null # Override the instructions for the agent, have no effect for dynamic instructions
variables: # Custom default values for the agent variables
<key>: <value>
4 changes: 2 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ---- llm ----
model: openai:gpt-4o # Specify the LLM to use
temperature: null # Set default temperature parameter
top_p: null # Set default top-p parameter, range (0, 1)
temperature: null # Set default temperature parameter (0, 1)
top_p: null # Set default top-p parameter, with a range of (0, 1) or (0, 2) depending on the model

# ---- behavior ----
stream: true # Controls whether to use the stream-style API.
Expand Down
12 changes: 9 additions & 3 deletions src/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ 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();
if !variables.is_empty() {
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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bfb87a6

Please sign in to comment.