-
Notifications
You must be signed in to change notification settings - Fork 61
[agent] Optimize the agent structure by moving the confirmation logic and risk level assessment down to the security service. #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
619c0eb
b907da8
f6c4389
9759b25
6c46731
41793bf
ba03bad
14a8e71
e91af4e
8dae665
0706eb7
ec34e68
731da9e
eecb0b0
da5a48a
75924f6
a74703d
b637061
65b0a1d
178d652
8573491
6c76a1e
5e3ed91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| from openhands.sdk.logger import get_logger | ||
| from openhands.sdk.mcp import create_mcp_tools | ||
| from openhands.sdk.security import analyzer | ||
| from openhands.sdk.security.security_service import SecurityService | ||
| from openhands.sdk.tool import BUILT_IN_TOOLS, Tool, ToolDefinition, resolve_tool | ||
| from openhands.sdk.utils.models import DiscriminatedUnionMixin | ||
| from openhands.sdk.utils.pydantic_diff import pretty_pydantic_diff | ||
|
|
@@ -272,6 +273,8 @@ def _initialize(self, state: "ConversationState"): | |
|
|
||
| # Store tools in a dict for easy access | ||
| self._tools = {tool.name: tool for tool in tools} | ||
| # Build the security service based on the state. | ||
| self._security_service = SecurityService(state) | ||
|
||
|
|
||
| @abstractmethod | ||
| def step( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,86 @@ | ||||||
| from typing import TYPE_CHECKING | ||||||
|
|
||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from openhands.sdk.conversation.state import ConversationState | ||||||
|
|
||||||
| from openhands.sdk.event.llm_convertible.action import ActionEvent | ||||||
| from openhands.sdk.security import risk | ||||||
| from openhands.sdk.security.llm_analyzer import LLMSecurityAnalyzer | ||||||
| from openhands.sdk.tool.builtins.finish import FinishAction | ||||||
| from openhands.sdk.tool.builtins.think import ThinkAction | ||||||
|
|
||||||
|
|
||||||
| class SecurityService: | ||||||
| def __init__( | ||||||
| self, | ||||||
| state: "ConversationState", | ||||||
| ): | ||||||
| self._state = state | ||||||
|
|
||||||
| def requires_confirmation( | ||||||
|
||||||
| def requires_confirmation( | |
| def assess_actions( |
I think maybe we should make this a more generic name. Possibly even pass the entire event history here as well since we may develop other security policies based on prior events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, Adjusted to access_confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original method handled both decision-making and state mutation, but now they're split across classes. This split could lead to inconsistencies if the agent forgets to set the execution status, or if the logic gets out of sync. Any ideas on how we may address this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the reason for this adjustment is to avoid modifying external resources. Instead, we leave the right to make modifications to the caller, preserving the read-only nature of this method.
If needed, I think we can implement a method in DefaultSecurityService to handle the state.