Skip to content

Commit 64199c9

Browse files
committed
refactor(agent): move AgentStateService to separate file #259
Extracted AgentStateService from AgentState.kt into its own file for better code organization. Also moved AgentProcessor interface and HistoryMessageProcessor class to a new file, AgentProcessor.kt.
1 parent 58614f0 commit 64199c9

File tree

3 files changed

+51
-45
lines changed

3 files changed

+51
-45
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cc.unitmesh.devti.observer.agent
2+
3+
interface AgentProcessor {
4+
fun process()
5+
}
6+
7+
class HistoryMessageProcessor : AgentProcessor {
8+
override fun process() {
9+
TODO("Not yet implemented")
10+
}
11+
}
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package cc.unitmesh.devti.observer.agent
22

33
import cc.unitmesh.devti.agent.tool.AgentTool
4-
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
54
import cc.unitmesh.devti.llms.custom.Message
6-
import com.intellij.openapi.components.Service
7-
import com.intellij.openapi.diagnostic.logger
85
import com.intellij.util.diff.Diff.Change
96
import java.util.UUID
107

@@ -15,45 +12,3 @@ data class AgentState(
1512
var usedTools: List<AgentTool> = emptyList(),
1613
)
1714

18-
@Service(Service.Level.PROJECT)
19-
class AgentStateService {
20-
var state: AgentState = AgentState()
21-
22-
fun resetState() {
23-
state = AgentState()
24-
}
25-
26-
fun addTools(tools: List<BuiltinCommand>) {
27-
state.usedTools = tools.map {
28-
AgentTool(it.commandName, it.description, "")
29-
}
30-
31-
logger<AgentStateService>().info("Called agent tools:\n ${state.usedTools.joinToString("\n")}")
32-
}
33-
34-
fun addChanges(fileName: String) {
35-
// todo changeList.add()
36-
}
37-
38-
fun resetMessages() {
39-
state.messages = emptyList()
40-
}
41-
42-
/**
43-
* Call some LLM to compress it or use some other method to compress the history
44-
*/
45-
fun preprocessMessages(messages: List<Message>): List<Message> {
46-
state.messages = messages
47-
return messages
48-
}
49-
}
50-
51-
interface AgentProcessor {
52-
fun process()
53-
}
54-
55-
class HistoryMessageProcessor : AgentProcessor {
56-
override fun process() {
57-
TODO("Not yet implemented")
58-
}
59-
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cc.unitmesh.devti.observer.agent
2+
3+
import cc.unitmesh.devti.agent.tool.AgentTool
4+
import cc.unitmesh.devti.devin.dataprovider.BuiltinCommand
5+
import cc.unitmesh.devti.llms.custom.Message
6+
import com.intellij.openapi.components.Service
7+
import com.intellij.openapi.diagnostic.logger
8+
9+
@Service(Service.Level.PROJECT)
10+
class AgentStateService {
11+
var state: AgentState = AgentState()
12+
13+
fun resetState() {
14+
state = AgentState()
15+
}
16+
17+
fun addTools(tools: List<BuiltinCommand>) {
18+
state.usedTools = tools.map {
19+
AgentTool(it.commandName, it.description, "")
20+
}
21+
22+
logger<AgentStateService>().info("Called agent tools:\n ${state.usedTools.joinToString("\n")}")
23+
}
24+
25+
fun addChanges(fileName: String) {
26+
// todo changeList.add()
27+
}
28+
29+
fun resetMessages() {
30+
state.messages = emptyList()
31+
}
32+
33+
/**
34+
* Call some LLM to compress it or use some other method to compress the history
35+
*/
36+
fun preprocessMessages(messages: List<Message>): List<Message> {
37+
state.messages = messages
38+
return messages
39+
}
40+
}

0 commit comments

Comments
 (0)