forked from All-Hands-AI/OpenHands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagent.py
68 lines (51 loc) · 1.79 KB
/
agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from dataclasses import dataclass
from typing import TYPE_CHECKING
from opendevin.observation import AgentRecallObservation, AgentMessageObservation, Observation
from .base import ExecutableAction, NotExecutableAction
if TYPE_CHECKING:
from opendevin.controller import AgentController
@dataclass
class AgentRecallAction(ExecutableAction):
query: str
action: str = "recall"
def run(self, controller: "AgentController") -> AgentRecallObservation:
return AgentRecallObservation(
content="Recalling memories...",
memories=controller.agent.search_memory(self.query)
)
@property
def message(self) -> str:
return f"Let me dive into my memories to find what you're looking for! Searching for: '{self.query}'. This might take a moment."
@dataclass
class AgentThinkAction(NotExecutableAction):
thought: str
action: str = "think"
def run(self, controller: "AgentController") -> "Observation":
raise NotImplementedError
@property
def message(self) -> str:
return self.thought
@dataclass
class AgentEchoAction(ExecutableAction):
content: str
action: str = "echo"
def run(self, controller: "AgentController") -> "Observation":
return AgentMessageObservation(self.content)
@property
def message(self) -> str:
return self.content
@dataclass
class AgentSummarizeAction(NotExecutableAction):
summary: str
action: str = "summarize"
@property
def message(self) -> str:
return self.summary
@dataclass
class AgentFinishAction(NotExecutableAction):
action: str = "finish"
def run(self, controller: "AgentController") -> "Observation":
raise NotImplementedError
@property
def message(self) -> str:
return "All done! What's next on the agenda?"