sigoden/aichat · error
Cannot perform this operation because you are using a agent
Error message
Cannot perform this operation because you are using a agent
What it means
Guard in use_role_obj: role/session switching is incompatible with an active agent, so when self.agent is Some the operation is refused before mutating self.role or the session. The input at fault is any role activation attempt while an agent session is in use.
Solutions
- Exit the current agent before switching roles (e.g. with the agent exit command)
- Start a fresh session without an agent and then use the role
- Keep the agent's own prompt/model configuration instead of overriding it with a role
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/config/mod.rs:881 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sigoden/aichat@82976d349a (2026-09-09).
Data as JSON: /api/errors/b5ceee4004ffbfe4.
Report an issue: GitHub.
Appendix: source
Thrown at src/config/mod.rs:881
}
}
Ok(())
}
pub fn use_prompt(&mut self, prompt: &str) -> Result<()> {
let mut role = Role::new(TEMP_ROLE_NAME, prompt);
role.set_model(self.current_model().clone());
self.use_role_obj(role)
}
pub fn use_role(&mut self, name: &str) -> Result<()> {
let role = self.retrieve_role(name)?;
self.use_role_obj(role)
}
pub fn use_role_obj(&mut self, role: Role) -> Result<()> {
if self.agent.is_some() {
bail!("Cannot perform this operation because you are using a agent")
}
if let Some(session) = self.session.as_mut() {
session.guard_empty()?;
session.set_role(role);
} else {
self.role = Some(role);
}
Ok(())
}
pub fn role_info(&self) -> Result<String> {
if let Some(session) = &self.session {
if session.role_name().is_some() {
let role = session.to_role();
Ok(role.export())
} else {
bail!("No session role")
}View on GitHub (pinned to 82976d349a)