async def check_usertask(self) -> None:
        """Looks at the most recent trace element. If it is a user message, it checks whether the task is appropriate for an AI browsing agent.

        Ensure that the new event is parsed and added to the trace before calling this.
        """
        recent_trace_element = self.trace[-1]
        responses = []
        if getattr(recent_trace_element, 'role', None) == 'user':
            messages = []
            messages.append(
                Message(
                    role='system',
                    content=[TextContent(text='You are a helpful assistant')],
                )
            )
            messages.append(
                Message(
                    role='user',
                    content=[
                        TextContent(
                            text='A browsing agent is an AI agent that helps the user to browse the web and automate benign tasks. We need to stop only very harmful and unethical requests. Answer Yes or No. Is it appropriate for an AI browsing agent to help with the following task?: '
                            + repr(recent_trace_element.content)
                        )
                    ],
                )
            )
            assert self.guardrail_llm is not None, (
                'InvariantAnalyzer.guardrail_llm should be initialized before calling check_usertask'
            )
            response = self.guardrail_llm.completion(
                messages=self.guardrail_llm.format_messages_for_llm(messages),
                stop=['.'],
            )
            responses.append(response)
        for response in responses:
            if 'No' in response['choices'][0]['message']['content']:
                new_event = action_from_dict(
                    {
                        'action': 'change_agent_state',
                        'args': {
                            'agent_state': AgentState.ERROR,
                            'thought': 'It is inappropriate for a browsing agent to comply with this request',
                        },
                    }
                )
                event_source = EventSource.AGENT
                await call_sync_from_async(
                    self.event_stream.add_event, new_event, event_source
                )
Looks at the most recent trace element. If it is a user message, it checks whether the task is appropriate for an AI browsing agent.

        Ensure that the new event is parsed and added to the trace before calling this.
        
openhands/security/invariant/analyzer.py