mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Calvin Smith <email@cjsmith.io>
33 lines
934 B
Python
33 lines
934 B
Python
from dataclasses import dataclass, field
|
|
from typing import Any, ClassVar
|
|
|
|
from openhands.core.schema import ActionType
|
|
from openhands.events.action.action import Action, ActionSecurityRisk
|
|
|
|
|
|
@dataclass
|
|
class MCPAction(Action):
|
|
name: str
|
|
arguments: dict[str, Any] = field(default_factory=dict)
|
|
thought: str = ''
|
|
action: str = ActionType.MCP
|
|
runnable: ClassVar[bool] = True
|
|
security_risk: ActionSecurityRisk | None = None
|
|
|
|
@property
|
|
def message(self) -> str:
|
|
return (
|
|
f'I am interacting with the MCP server with name:\n'
|
|
f'```\n{self.name}\n```\n'
|
|
f'and arguments:\n'
|
|
f'```\n{self.arguments}\n```'
|
|
)
|
|
|
|
def __str__(self) -> str:
|
|
ret = '**MCPAction**\n'
|
|
if self.thought:
|
|
ret += f'THOUGHT: {self.thought}\n'
|
|
ret += f'NAME: {self.name}\n'
|
|
ret += f'ARGUMENTS: {self.arguments}'
|
|
return ret
|