def is_generation_confident(
        self,
        history: ChatMessageHistory,
        agent_output: Union[AgentAction, AgentFinish],
        min_confidence: int = 3,
    ) -> bool:
        """
        Estimate the confidence of the generation
        Args:
            history: history of the conversation
            agent_output: the output from the agent
            min_confidence: minimum confidence score to be considered as confident
        """

        def _format_assistant_message(action_output: Union[AgentAction, AgentFinish]):
            if isinstance(action_output, AgentFinish):
                assistant_message = f"Assistant: {action_output.message}"
            elif isinstance(action_output, AgentAction):
                assistant_message = f"Action: {action_output.tool} with input: {action_output.tool_input}"
            else:
                raise ValueError("Unsupported action for estimating confidence score")

            return assistant_message

        prompt = Template(ESTIMATE_CONFIDENCE_PROMPT).substitute(
            policy=self.prompt,
            conversation_history=history.format_message(),
            assistant_message=_format_assistant_message(agent_output),
        )
        logger.info(f"\nEstimate confidence prompt: {prompt} \n")

        message = UserMessage(content=prompt)

        full_output: Generation = self.llm.generate([message], self.tools).generations[
            0
        ]

        estimated_confidence = self.output_parser.parse_estimated_confidence(
            full_output.message
        )

        return estimated_confidence >= min_confidence

        Estimate the confidence of the generation
        Args:
            history: history of the conversation
            agent_output: the output from the agent
            min_confidence: minimum confidence score to be considered as confident
        
autochain/agent/openai_functions_agent/openai_functions_agent.py