summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/agent.rs8
-rw-r--r--src/config/mod.rs19
2 files changed, 21 insertions, 6 deletions
diff --git a/src/config/agent.rs b/src/config/agent.rs
index 0025095..b20e108 100644
--- a/src/config/agent.rs
+++ b/src/config/agent.rs
@@ -139,6 +139,10 @@ impl Agent {
self.definition.interpolated_instructions()
}
+ pub fn agent_prelude(&self) -> Option<&str> {
+ self.config.agent_prelude.as_deref()
+ }
+
pub fn variables(&self) -> &[AgentVariable] {
&self.definition.variables
}
@@ -211,7 +215,9 @@ pub struct AgentConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
- use_tools: Option<String>,
+ pub use_tools: Option<String>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub agent_prelude: Option<String>,
}
impl AgentConfig {
diff --git a/src/config/mod.rs b/src/config/mod.rs
index bd02ec3..7cd5a17 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -464,7 +464,7 @@ impl Config {
if role.top_p().is_none() && self.top_p.is_some() {
role.set_top_p(self.top_p);
}
- if role.use_tools().is_none() && self.use_tools.is_some() && self.agent.is_none() {
+ if role.use_tools().is_none() && self.use_tools.is_some() {
role.set_use_tools(self.use_tools.clone())
}
role
@@ -1028,11 +1028,15 @@ impl Config {
bail!("Already in a agent, please run '.exit agent' first to exit the current agent.");
}
let agent = Agent::init(config, name, abort_signal).await?;
+ let session = session.map(|v| v.to_string()).or_else(|| {
+ agent
+ .agent_prelude()
+ .map(|v| v.to_string())
+ .or_else(|| config.read().agent_prelude.clone())
+ .and_then(|v| if v.is_empty() { None } else { Some(v) })
+ });
config.write().rag = agent.rag();
config.write().agent = Some(agent);
- let session = session
- .map(|v| v.to_string())
- .or_else(|| config.read().agent_prelude.clone());
if let Some(session) = session {
config.write().use_session(Some(&session))?;
}
@@ -1085,7 +1089,12 @@ impl Config {
WorkingMode::Serve => return Ok(()),
};
let prelude = match prelude {
- Some(v) => v.to_string(),
+ Some(v) => {
+ if v.is_empty() {
+ return Ok(());
+ }
+ v.to_string()
+ }
None => return Ok(()),
};