Skip to content

Commit 692aa7f

Browse files
committed
update agent builder
1 parent fd3d5fe commit 692aa7f

35 files changed

Lines changed: 221 additions & 461 deletions

File tree

agent-components/planner/planner-executor/src/main/kotlin/io/github/llmagentbuilder/planner/executor/LLMPlanExecutor.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.github.llmagentbuilder.planner.executor
22

3-
import io.github.llmagentbuilder.core.AgentFinish
4-
import io.github.llmagentbuilder.core.IntermediateAgentStep
5-
import io.github.llmagentbuilder.core.Planner
3+
import io.github.llmagentbuilder.core.*
64
import io.github.llmagentbuilder.core.executor.ActionPlanningResult
75
import io.github.llmagentbuilder.core.observation.AgentPlanningObservationContext
86
import io.github.llmagentbuilder.core.observation.AgentPlanningObservationDocumentation
@@ -17,7 +15,7 @@ open class LLMPlanExecutor(
1715
private val observationRegistry: ObservationRegistry? = null,
1816
) : Planner {
1917
override fun plan(
20-
inputs: Map<String, Any>,
18+
inputs: ChatAgentRequest,
2119
intermediateSteps: List<IntermediateAgentStep>
2220
): ActionPlanningResult {
2321
val action = { internalPlan(inputs, intermediateSteps) }
@@ -27,11 +25,13 @@ open class LLMPlanExecutor(
2725
}
2826

2927
private fun internalPlan(
30-
inputs: Map<String, Any>,
28+
inputs: ChatAgentRequest,
3129
intermediateSteps: List<IntermediateAgentStep>
3230
): ActionPlanningResult {
3331
val userInput =
34-
(inputs["input"] as? String)
32+
inputs.messages.filterIsInstance<ThreadUserMessage>()
33+
.lastOrNull()?.content?.filterIsInstance<TextContentPart>()
34+
?.joinToString("\n") { it.text }
3535
?: throw RuntimeException("Invalid input")
3636
val thoughts = constructScratchpad(intermediateSteps)
3737
val response = chatClient.prompt()
@@ -52,7 +52,7 @@ open class LLMPlanExecutor(
5252
}
5353

5454
private fun instrumentedPlan(
55-
input: Map<String, Any>,
55+
input: ChatAgentRequest,
5656
action: () -> ActionPlanningResult,
5757
registry: ObservationRegistry
5858
): ActionPlanningResult {

agent-components/tool/src/main/kotlin/io/github/llmagentbuilder/agent/tool/AgentToolInfoAdvisor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.llmagentbuilder.agent.tool
22

3-
import io.github.llmagentbuilder.core.tool.AgentTool
3+
import com.javaaidev.easyllmtools.llmtoolspec.Tool
44
import org.springframework.ai.chat.client.advisor.api.AdvisedRequest
55
import org.springframework.ai.chat.client.advisor.api.AdvisedResponse
66
import org.springframework.ai.chat.client.advisor.api.CallAroundAdvisor
@@ -10,7 +10,7 @@ import org.springframework.core.Ordered
1010
const val SYSTEM_PARAM_TOOL_NAMES = "tool_names"
1111
const val SYSTEM_PARAM_TOOLS = "tools"
1212

13-
class AgentToolInfoAdvisor(private val tools: Map<String, AgentTool<*, *>>) :
13+
class AgentToolInfoAdvisor(private val tools: Map<String, Tool<*, *>>) :
1414
CallAroundAdvisor {
1515
override fun getName(): String {
1616
return javaClass.simpleName
@@ -38,9 +38,9 @@ class AgentToolInfoAdvisor(private val tools: Map<String, AgentTool<*, *>>) :
3838
return chain.nextAroundCall(request)
3939
}
4040

41-
private fun renderTools(tools: Collection<AgentTool<*, *>>): String {
41+
private fun renderTools(tools: Collection<Tool<*, *>>): String {
4242
return tools.joinToString("\n") {
43-
"${it.name()}: ${it.description()}"
43+
"${it.name}: ${it.description}"
4444
}
4545
}
4646
}

bootstrap/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>com.javaaidev</groupId>
5353
<artifactId>chat-agent-ui</artifactId>
54-
<version>0.5.1</version>
54+
<version>0.6.0</version>
5555
</dependency>
5656
<dependency>
5757
<groupId>org.slf4j</groupId>

cli/sample-config/sample-agent.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,13 @@ profile:
77
system: You are a helpful assistant.
88
memory:
99
inMemory:
10-
enabled: true
10+
enabled: false
1111
planner:
12-
reActJson:
12+
simple:
1313
enabled: true
1414
tools:
15-
- id: writeLocalFile
16-
config:
17-
basePath: "file-output"
18-
dependency:
19-
groupId: "io.github.llmagentbuilder"
20-
artifactId: "tool-write-local-file"
21-
version: "0.2.2"
22-
- id: readLocalFile
23-
config:
24-
basePath: "file-input"
15+
- id: GetWeather
2516
dependency:
26-
groupId: "io.github.llmagentbuilder"
27-
artifactId: "tool-read-local-file"
28-
version: "0.2.2"
17+
groupId: "com.javaaidev.easyllmtools.tools"
18+
artifactId: "get-weather"
19+
version: "0.1.5"

cli/src/main/kotlin/io/github/llmagentbuilder/cli/Dependencies.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.llmagentbuilder.cli
22

33
data class MavenCoordinate(
4-
val groupId: String = "io.github.llmagentbuilder",
4+
val groupId: String = "com.javaaidev.llmagentbuilder",
55
val artifactId: String,
66
val version: String = "\${llmagentbuilder.version}",
77
)

cli/src/main/kotlin/io/github/llmagentbuilder/cli/MavenFilesGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object MavenFilesGenerator {
2626
"artifactId" to (config.artifactId
2727
?: "app_${UUID.randomUUID().toString().replace("-", "")}"),
2828
"springAiVersion" to (config.springAiVersion
29-
?: "1.0.0-SNAPSHOT"),
29+
?: "1.0.0-M5"),
3030
"llmAgentBuilderVersion" to (config.llmAgentBuilderVersion
3131
?: VERSION),
3232
"dependencies" to collectDependencies(agentConfig),

core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const val VERSION = "${project.version}"
9999
<groupId>com.github.jknack</groupId>
100100
<artifactId>handlebars</artifactId>
101101
</dependency>
102+
<dependency>
103+
<groupId>com.javaaidev.easyllmtools</groupId>
104+
<artifactId>llm-tool-spec</artifactId>
105+
</dependency>
102106

103107
<dependency>
104108
<groupId>uk.org.webcompere</groupId>

core/src/main/kotlin/io/github/llmagentbuilder/core/Agent.kt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data class IntermediateAgentStep(
3535

3636
interface Planner {
3737
fun plan(
38-
inputs: Map<String, Any>,
38+
inputs: ChatAgentRequest,
3939
intermediateSteps: List<IntermediateAgentStep>
4040
): ActionPlanningResult
4141

@@ -61,7 +61,7 @@ interface AgentRequest {
6161
/**
6262
* LLM based agent
6363
*/
64-
interface Agent<in REQUEST : AgentRequest, out RESPONSE> {
64+
interface Agent<in REQUEST, out RESPONSE> {
6565
/**
6666
* ID of the agent
6767
*
@@ -91,23 +91,4 @@ interface Agent<in REQUEST : AgentRequest, out RESPONSE> {
9191
fun call(request: REQUEST): RESPONSE
9292
}
9393

94-
data class ChatAgentRequest(
95-
val input: String,
96-
val conversationId: String? = null
97-
) :
98-
AgentRequest {
99-
override fun toMap(): Map<String, Any> {
100-
return mapOf("input" to input) + (conversationId?.let { mapOf("conversation_id" to it) }
101-
?: mapOf())
102-
}
103-
}
104-
105-
data class ChatAgentResponse(val output: String) {
106-
companion object {
107-
fun fromMap(map: Map<String, Any>): ChatAgentResponse {
108-
return ChatAgentResponse(map["output"]?.toString() ?: "")
109-
}
110-
}
111-
}
112-
11394
interface ChatAgent : Agent<ChatAgentRequest, ChatAgentResponse>

core/src/main/kotlin/io/github/llmagentbuilder/core/AgentFactory.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.github.llmagentbuilder.core
33
import io.github.llmagentbuilder.core.executor.AgentExecutor
44
import io.github.llmagentbuilder.core.tool.AgentToolWrappersProvider
55
import io.github.llmagentbuilder.core.tool.AgentToolsProvider
6-
import io.github.llmagentbuilder.core.tool.AutoDiscoveredAgentToolsProvider
76
import io.micrometer.observation.ObservationRegistry
87
import org.slf4j.LoggerFactory
98

@@ -15,15 +14,15 @@ object AgentFactory {
1514
name: String? = null,
1615
description: String? = null,
1716
usageInstruction: String? = null,
18-
agentToolsProvider: AgentToolsProvider? = null,
17+
agentToolsProvider: AgentToolsProvider,
1918
id: String? = null,
2019
observationRegistry: ObservationRegistry? = null,
2120
): ChatAgent {
2221
val agentName = name ?: "ChatAgent"
2322
val executor = createAgentExecutor(
2423
agentName,
2524
planner,
26-
agentToolsProvider ?: AutoDiscoveredAgentToolsProvider,
25+
agentToolsProvider,
2726
observationRegistry
2827
)
2928
return ExecutableChatAgent(
@@ -42,16 +41,16 @@ object AgentFactory {
4241
}
4342
}
4443

45-
fun <REQUEST : AgentRequest, RESPONSE> create(
44+
fun <RESPONSE> create(
4645
name: String,
4746
description: String,
4847
usageInstruction: String,
4948
planner: Planner,
5049
responseFactory: (Map<String, Any>) -> RESPONSE,
51-
agentToolsProvider: AgentToolsProvider = AutoDiscoveredAgentToolsProvider,
50+
agentToolsProvider: AgentToolsProvider,
5251
id: String? = null,
5352
observationRegistry: ObservationRegistry? = null,
54-
): Agent<REQUEST, RESPONSE> {
53+
): Agent<ChatAgentRequest, RESPONSE> {
5554
val executor = createAgentExecutor(
5655
name,
5756
planner,
@@ -86,7 +85,7 @@ object AgentFactory {
8685
)
8786
}
8887

89-
private open class ExecutableAgent<REQUEST : AgentRequest, RESPONSE>(
88+
private open class ExecutableAgent<RESPONSE>(
9089
private val name: String,
9190
private val description: String,
9291
private val usageInstruction: String,
@@ -95,7 +94,7 @@ object AgentFactory {
9594
private val id: String? = null,
9695
private val observationRegistry: ObservationRegistry? = null,
9796
) :
98-
Agent<REQUEST, RESPONSE> {
97+
Agent<ChatAgentRequest, RESPONSE> {
9998
private val logger = LoggerFactory.getLogger("AgentExecutor")
10099

101100
override fun id(): String {
@@ -114,13 +113,13 @@ object AgentFactory {
114113
return usageInstruction
115114
}
116115

117-
override fun call(request: REQUEST): RESPONSE {
116+
override fun call(request: ChatAgentRequest): RESPONSE {
118117
logger.info(
119118
"Start executing agent [{}] with request [{}]",
120119
name(),
121120
request
122121
)
123-
val response = responseFactory(executor.call(request.toMap()))
122+
val response = responseFactory(executor.call(request))
124123
logger.info(
125124
"Finished executing agent [{}] with response [{}]",
126125
name(),
@@ -138,7 +137,7 @@ object AgentFactory {
138137
usageInstruction: String,
139138
id: String? = null,
140139
observationRegistry: ObservationRegistry? = null,
141-
) : ExecutableAgent<ChatAgentRequest, ChatAgentResponse>(
140+
) : ExecutableAgent<ChatAgentResponse>(
142141
name,
143142
description,
144143
usageInstruction,

core/src/main/kotlin/io/github/llmagentbuilder/core/AgentInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ object AgentInfoBuilder {
2727
agent.usageInstruction(),
2828
agentToolsProvider.get().values.map { tool ->
2929
AgentToolInfo(
30-
tool.name(),
31-
tool.description(),
30+
tool.name,
31+
tool.description,
3232
)
3333
}
3434
)

0 commit comments

Comments
 (0)