Skip to content

Commit 45788f4

Browse files
committed
fixup! Updated docs
1 parent dcf9ea5 commit 45788f4

21 files changed

Lines changed: 621 additions & 476 deletions

docs/docs/agents/functional-agents.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ In Kotlin, the most convenient way is to use the `functionalStrategy {...}` DSL
3434
<!--- INCLUDE
3535
import ai.koog.agents.core.agent.AIAgent
3636
import ai.koog.agents.core.agent.functionalStrategy
37+
import ai.koog.prompt.message.MessagePart
3738
import ai.koog.prompt.executor.llms.all.simpleOllamaAIExecutor
3839
import ai.koog.prompt.executor.ollama.client.OllamaModels
3940
import kotlinx.coroutines.runBlocking
4041
-->
4142
```kotlin
4243
val strategy = functionalStrategy<String, String> { input ->
4344
val response = requestLLM(input)
44-
response.asAssistantMessage().content
45+
response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text }
4546
}
4647

4748
val mathAgent = AIAgent(
@@ -98,15 +99,20 @@ You can extend the previous strategy to make multiple sequential LLM calls:
9899

99100
<!--- INCLUDE
100101
import ai.koog.agents.core.agent.functionalStrategy
102+
import ai.koog.prompt.message.Message
103+
import ai.koog.prompt.message.MessagePart
101104
-->
102105
```kotlin
106+
fun Message.Assistant.text(): String =
107+
parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text }
108+
103109
val strategy = functionalStrategy<String, String> { input ->
104110
// The first LLM call produces an initial draft based on the user input
105-
val draft = requestLLM("Draft: $input").asAssistantMessage().content
111+
val draft = requestLLM("Draft: $input").text()
106112
// The second LLM call improves the initial draft
107-
val improved = requestLLM("Improve and clarify.").asAssistantMessage().content
113+
val improved = requestLLM("Improve and clarify.").text()
108114
// The final LLM call formats the improved text and returns the result
109-
requestLLM("Format the result as bold.").asAssistantMessage().content
115+
requestLLM("Format the result as bold.").text()
110116
}
111117
```
112118
<!--- KNIT example-functional-agent-02.kt -->
@@ -181,6 +187,7 @@ Here is what you need to do:
181187
import ai.koog.agents.core.tools.annotations.LLMDescription
182188
import ai.koog.agents.core.tools.annotations.Tool
183189
import ai.koog.agents.core.tools.reflect.ToolSet
190+
import ai.koog.prompt.message.MessagePart
184191
import ai.koog.prompt.executor.llms.all.simpleOllamaAIExecutor
185192
import ai.koog.prompt.executor.ollama.client.OllamaModels
186193
import kotlinx.coroutines.runBlocking
@@ -203,20 +210,20 @@ Here is what you need to do:
203210

204211
val strategy = functionalStrategy<String, String> { input ->
205212
// Send the user input to the LLM
206-
var responses = requestLLMMultiple(input)
213+
var response = requestLLM(input)
207214

208215
// Only loop while the LLM requests tools
209-
while (responses.containsToolCalls()) {
210-
// Extract tool calls from the response
211-
val pendingCalls = extractToolCalls(responses)
216+
var toolCalls = response.parts.filterIsInstance<MessagePart.Tool.Call>()
217+
while (toolCalls.isNotEmpty()) {
212218
// Execute the tools and return the results
213-
val results = executeMultipleTools(pendingCalls)
219+
val results = executeTools(toolCalls)
214220
// Send the tool results back to the LLM. The LLM may call more tools or return a final output
215-
responses = sendMultipleToolResults(results)
221+
response = sendToolResults(results)
222+
toolCalls = response.parts.filterIsInstance<MessagePart.Tool.Call>()
216223
}
217224

218225
// When no tool calls remain, extract and return the assistant message content from the response
219-
responses.single().asAssistantMessage().content
226+
response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text }
220227
}
221228

222229
val mathAgentWithTools = AIAgent(

docs/docs/agents/graph-based-agents.md

Lines changed: 112 additions & 93 deletions
Large diffs are not rendered by default.

docs/docs/agents/planner-agents/goap-agents.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ while the LLM performs the actual content generation within each action.
5050
import ai.koog.agents.planner.goap
5151
import ai.koog.agents.planner.goap.GoapAgentState
5252
import ai.koog.prompt.dsl.prompt
53+
import ai.koog.prompt.message.MessagePart
5354
import ai.koog.prompt.executor.clients.openai.OpenAIModels
5455
import ai.koog.prompt.executor.llms.all.simpleOpenAIExecutor
5556
-->
@@ -84,7 +85,7 @@ while the LLM performs the actual content generation within each action.
8485
}
8586
requestLLM()
8687
}
87-
state.copy(hasOutline = true, outline = response.content)
88+
state.copy(hasOutline = true, outline = response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text })
8889
}
8990

9091
action(
@@ -100,7 +101,7 @@ while the LLM performs the actual content generation within each action.
100101
}
101102
requestLLM()
102103
}
103-
state.copy(hasDraft = true, draft = response.content)
104+
state.copy(hasDraft = true, draft = response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text })
104105
}
105106

106107
action(
@@ -116,7 +117,7 @@ while the LLM performs the actual content generation within each action.
116117
}
117118
requestLLM()
118119
}
119-
println("Review feedback: ${response.content}")
120+
println("Review feedback: ${response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text }}")
120121
state.copy(hasReview = true)
121122
}
122123

@@ -168,6 +169,8 @@ while the LLM performs the actual content generation within each action.
168169
import ai.koog.agents.planner.goap.GoapAgentState;
169170
import ai.koog.prompt.executor.clients.openai.OpenAIModels;
170171
import ai.koog.prompt.executor.model.PromptExecutor;
172+
import ai.koog.prompt.message.MessagePart;
173+
import java.util.stream.Collectors;
171174
class exampleGoapAgents01 {
172175
-->
173176
<!--- SUFFIX
@@ -227,7 +230,10 @@ while the LLM performs the actual content generation within each action.
227230
prompt.user("Create a detailed outline for an article about: " + state.topic);
228231
return null;
229232
});
230-
return session.requestLLM().getContent();
233+
return session.requestLLM().getParts().stream()
234+
.filter(p -> p instanceof MessagePart.Text)
235+
.map(p -> ((MessagePart.Text) p).getText())
236+
.collect(Collectors.joining());
231237
});
232238
return state.copy(true, response, state.hasDraft, state.draft,
233239
state.hasReview, state.isPublished);
@@ -243,7 +249,10 @@ while the LLM performs the actual content generation within each action.
243249
prompt.user("Write an article based on this outline:\n" + state.outline);
244250
return null;
245251
});
246-
return session.requestLLM().getContent();
252+
return session.requestLLM().getParts().stream()
253+
.filter(p -> p instanceof MessagePart.Text)
254+
.map(p -> ((MessagePart.Text) p).getText())
255+
.collect(Collectors.joining());
247256
});
248257
return state.copy(state.hasOutline, state.outline, true, response,
249258
state.hasReview, state.isPublished);
@@ -260,7 +269,10 @@ while the LLM performs the actual content generation within each action.
260269
prompt.user("Review this article and suggest improvements:\n" + state.draft);
261270
return null;
262271
});
263-
return session.requestLLM().getContent();
272+
return session.requestLLM().getParts().stream()
273+
.filter(p -> p instanceof MessagePart.Text)
274+
.map(p -> ((MessagePart.Text) p).getText())
275+
.collect(Collectors.joining());
264276
});
265277
System.out.println("Review feedback: " + response);
266278
return state.copy(state.hasOutline, state.outline, state.hasDraft,

docs/docs/custom-nodes.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ use pre-built factory methods like `AIAgentNode.llmRequest()` that handle prompt
506506
<!--- INCLUDE
507507
import ai.koog.agents.core.dsl.builder.strategy
508508
import ai.koog.agents.core.dsl.builder.node
509+
import ai.koog.prompt.message.MessagePart
509510
val strategy = strategy<String, String>("strategy_name") {
510511
-->
511512
<!--- SUFFIX
@@ -519,7 +520,7 @@ use pre-built factory methods like `AIAgentNode.llmRequest()` that handle prompt
519520
}
520521

521522
val response = requestLLMWithoutTools()
522-
response.content
523+
response.parts.filterIsInstance<MessagePart.Text>().joinToString("\n") { it.text }
523524
}
524525
}
525526
```
@@ -530,6 +531,8 @@ use pre-built factory methods like `AIAgentNode.llmRequest()` that handle prompt
530531
<!--- INCLUDE
531532
import ai.koog.agents.core.agent.entity.AIAgentNode;
532533
import ai.koog.prompt.message.Message;
534+
import ai.koog.prompt.message.MessagePart;
535+
import java.util.stream.Collectors;
533536
class exampleCustomNodesJava10 {
534537
public static void main(String[] args) {
535538
-->
@@ -542,13 +545,16 @@ use pre-built factory methods like `AIAgentNode.llmRequest()` that handle prompt
542545
// AIAgentNode.llmRequest() creates a node that sends the input string as a user
543546
// message to the LLM and returns the response. The prompt text is provided as
544547
// the node's input when it is executed in the graph.
545-
var summarizeTextNode = AIAgentNode.llmRequest(true, "node_name");
548+
var summarizeTextNode = AIAgentNode.llmRequest("node_name");
546549

547550
// To extract the text content from the LLM response, chain a separate node:
548551
var extractContent = AIAgentNode.builder("extract-content")
549-
.withInput(Message.Response.class)
552+
.withInput(Message.Assistant.class)
550553
.withOutput(String.class)
551-
.withAction((response, ctx) -> response.getContent())
554+
.withAction((response, ctx) -> response.getParts().stream()
555+
.filter(p -> p instanceof MessagePart.Text)
556+
.map(p -> ((MessagePart.Text) p).getText())
557+
.collect(Collectors.joining()))
552558
.build();
553559
```
554560
<!--- KNIT exampleCustomNodesJava10.java -->
@@ -566,9 +572,7 @@ typically use subgraphs that delegate tool orchestration to the LLM.
566572
<!--- INCLUDE
567573
import ai.koog.agents.core.dsl.builder.strategy
568574
import ai.koog.agents.core.dsl.builder.node
569-
import ai.koog.prompt.message.Message
570-
import ai.koog.prompt.message.ResponseMetaInfo
571-
import ai.koog.utils.time.KoogClock
575+
import ai.koog.prompt.message.MessagePart
572576
import kotlinx.serialization.Serializable
573577
import kotlinx.serialization.json.Json
574578
import java.util.*
@@ -585,12 +589,11 @@ typically use subgraphs that delegate tool orchestration to the LLM.
585589
val toolCall = MessagePart.Tool.Call(
586590
id = UUID.randomUUID().toString(),
587591
tool = toolName,
588-
metaInfo = ResponseMetaInfo.create(KoogClock.System),
589-
content = Json.encodeToString(ToolArgs(arg1 = input, arg2 = 42)) // Use the input as tool arguments
592+
args = Json.encodeToString(ToolArgs(arg1 = input, arg2 = 42)) // Use the input as tool arguments
590593
)
591594

592595
val result = environment.executeTool(toolCall)
593-
result.content
596+
result.output
594597
}
595598
```
596599
<!--- KNIT example-custom-nodes-11.kt -->

0 commit comments

Comments
 (0)