MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / swap_agent

Method swap_agent

crates/chat-cli/src/cli/chat/conversation.rs:942–962  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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
965pub fn format_tool_spec(tool_spec: HashMap<String, ToolSpec>) -> HashMap<ToolOrigin, Vec<Tool>> {

Callers 1

executeMethod · 0.45

Calls 5

CustomClass · 0.85
switchMethod · 0.80
update_stateMethod · 0.80
as_refMethod · 0.45

Tested by

no test coverage detected