Skip to content

Cannot easily remove security analyzer from agent mid conversation #668

@malhotra5

Description

@malhotra5

This issue is related to OpenHands/OpenHands#11256

We want the ability to remove the security analyzer from the agent because it adds a system prompt which requires the LLM model to return field for risk, something that weaker llm models struggle to do.

There are two ways to implement this

Method 1: update conversation's agent

conversation.agent = conversation.agent.model_copy(
                update={"security_analyzer": None}
)

The problem here is updating the security analyzer as so doesn't update the system prompt causing the error

RuntimeError: LLM provided a security_risk but no security analyzer is configured - THIS SHOULD NOT HAPPEN!

Method 2 Reload conversation from persistent state with a new agent that doesn't contain security analyzer

conversation = Conversation(convo_id='resuming-id', agent=Agent(security_analyzer=None, ...))

The problem here is that reconcilliation fails against the current agent and the one being restored from the persistent copy

ValueError: The Agent provided is different from the one in persisted state.
Diff: security_analyzer: '<missing>' -> {'kind': 'LLMSecurityAnalyzer'}

Current workaround

The current solution is to explicitly save the agent without a security analyzer and load it into the conversation. This is a lot of overhead for sdk clients

agent_without_security_analyzer = conversation.agent.model_copy(
                update={"security_analyzer": None}
)
agent_without_security_analyzer.to_json(settings_file)
conversation = Conversation(agent=Agent.from_json(settings_file))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions