Swapping agent involves the following: - Reinstantiate the context manager - Swap agent on tool manager
(
&mut self,
os: &mut Os,
output: &mut impl Write,
agent_name: &str,
)
| 940 | /// - Reinstantiate the context manager |
| 941 | /// - Swap agent on tool manager |
| 942 | pub async fn swap_agent( |
| 943 | &mut self, |
| 944 | os: &mut Os, |
| 945 | output: &mut impl Write, |
| 946 | agent_name: &str, |
| 947 | ) -> Result<(), ChatError> { |
| 948 | let agent = self.agents.switch(agent_name).map_err(ChatError::AgentSwapError)?; |
| 949 | self.context_manager.replace({ |
| 950 | ContextManager::from_agent(agent, calc_max_context_files_size(self.model_info.as_ref())) |
| 951 | .map_err(|e| ChatError::Custom(format!("Context manager has failed to instantiate: {e}").into()))? |
| 952 | }); |
| 953 | |
| 954 | self.tool_manager |
| 955 | .swap_agent(os, output, agent) |
| 956 | .await |
| 957 | .map_err(ChatError::AgentSwapError)?; |
| 958 | |
| 959 | self.update_state(true).await; |
| 960 | |
| 961 | Ok(()) |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | pub fn format_tool_spec(tool_spec: HashMap<String, ToolSpec>) -> HashMap<ToolOrigin, Vec<Tool>> { |
no test coverage detected