Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: init agent variables #977

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/config/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ impl Agent {
None
};

let shared_variables = agent_config.variables.clone();

Ok(Self {
name: name.to_string(),
config: agent_config,
definition,
shared_variables,
shared_variables: Default::default(),
session_variables: None,
functions,
rag,
Expand Down Expand Up @@ -229,6 +227,10 @@ impl Agent {
}
}

pub fn config_variables(&self) -> &IndexMap<String, String> {
&self.config.variables
}

pub fn shared_variables(&self) -> &IndexMap<String, String> {
&self.shared_variables
}
Expand Down
16 changes: 11 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,8 @@ impl Config {
session.exit(&sessions_dir, self.working_mode.is_repl())?;
self.last_message = None;
}
if self.agent.is_some() {
self.init_agent_shared_variables()?;
if let Some(agent) = self.agent.as_mut() {
agent.set_session_variables(None);
}
Ok(())
}
Expand Down Expand Up @@ -1863,9 +1863,8 @@ impl Config {
None => return Ok(()),
};
let new_variables =
Agent::init_agent_variables(agent.defined_variables(), agent.shared_variables())?;
Agent::init_agent_variables(agent.defined_variables(), agent.config_variables())?;
agent.set_shared_variables(new_variables);
agent.set_session_variables(None);
Ok(())
}

Expand All @@ -1875,9 +1874,16 @@ impl Config {
_ => return Ok(()),
};
let shared_variables = agent.shared_variables();
let mut all_variables = shared_variables.clone();
let mut all_variables = if shared_variables.is_empty() {
agent.config_variables().clone()
} else {
shared_variables.clone()
};
all_variables.extend(session.agent_variables().clone());
let new_variables = Agent::init_agent_variables(agent.defined_variables(), &all_variables)?;
if shared_variables.is_empty() {
agent.set_shared_variables(new_variables.clone());
}
agent.set_session_variables(Some(new_variables));
session.sync_agent(agent, false);
Ok(())
Expand Down