-
Notifications
You must be signed in to change notification settings - Fork 3k
/
agent.py
94 lines (69 loc) 路 2.38 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Dict
from opendevin.observation import (
AgentRecallObservation,
AgentMessageObservation,
NullObservation,
Observation,
)
from opendevin.schema import ActionType
from .base import ExecutableAction, NotExecutableAction
if TYPE_CHECKING:
from opendevin.controller import AgentController
@dataclass
class AgentRecallAction(ExecutableAction):
query: str
action: str = ActionType.RECALL
async 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 = ActionType.THINK
async 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'
async 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 = ActionType.SUMMARIZE
@property
def message(self) -> str:
return self.summary
@dataclass
class AgentFinishAction(NotExecutableAction):
outputs: Dict = field(default_factory=dict)
action: str = ActionType.FINISH
async def run(self, controller: 'AgentController') -> 'Observation':
raise NotImplementedError
@property
def message(self) -> str:
return "All done! What's next on the agenda?"
@dataclass
class AgentDelegateAction(ExecutableAction):
agent: str
inputs: dict
action: str = ActionType.DELEGATE
async def run(self, controller: 'AgentController') -> 'Observation':
await controller.start_delegate(self)
return NullObservation('')
@property
def message(self) -> str:
return f"I'm asking {self.agent} for help with this task."