Skip to content

Commit c93cfb0

Browse files
Add inspection for missing KDocs in public API (#270)
1 parent 4456976 commit c93cfb0

File tree

76 files changed

+2989
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2989
-10
lines changed

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/AIAgent.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public open class AIAgent(
134134
* This makes the API a bit stricter and clear.
135135
*/
136136
public class FeatureContext internal constructor(private val agent: AIAgent) {
137+
/**
138+
* Installs and configures a feature into the current AI agent context.
139+
*
140+
* @param feature the feature to be added, defined by an implementation of [AIAgentFeature], which provides specific functionality
141+
* @param configure an optional lambda to customize the configuration of the feature, where the provided [Config] can be modified
142+
*/
137143
public fun <Config : FeatureConfig, Feature : Any> install(
138144
feature: AIAgentFeature<Config, Feature>,
139145
configure: Config.() -> Unit = {}
@@ -209,6 +215,15 @@ public open class AIAgent(
209215
}
210216
}
211217

218+
/**
219+
* Executes the AI agent using a builder to construct the textual input.
220+
*
221+
* This method allows for constructing a complex input by utilizing the functionalities
222+
* of [TextContentBuilder]. The builder is applied to create the structured input which
223+
* is then used to initiate the agent's execution.
224+
*
225+
* @param builder a lambda function applied to a [TextContentBuilder] instance to build the input text for the agent
226+
*/
212227
public suspend fun run(builder: suspend TextContentBuilder.() -> Unit) {
213228
run(agentInput = TextContentBuilder().apply { this.builder() }.build())
214229
}

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/AIAgentTool.kt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,21 @@ public class AIAgentTool(
4747
agentDescription: String,
4848
requestDescription: String = "Input for the task"
4949
) : Tool<AgentToolArgs, AgentToolResult>() {
50+
/**
51+
* Represents the arguments required for the execution of an agent tool.
52+
*
53+
* @property request The input data or parameters needed for the agent tool to perform its operation.
54+
*/
5055
@Serializable
5156
public data class AgentToolArgs(val request: String) : Args
5257

58+
/**
59+
* Represents the result of executing an agent tool operation.
60+
*
61+
* @property successful Indicates whether the operation was successful.
62+
* @property errorMessage An optional error message describing the failure, if any.
63+
* @property result An optional string representing the result produced by the tool operation.
64+
*/
5365
@Serializable
5466
public data class AgentToolResult(
5567
val successful: Boolean,
@@ -74,13 +86,13 @@ public class AIAgentTool(
7486
)
7587

7688
override suspend fun execute(args: AgentToolArgs): AgentToolResult {
77-
try {
78-
return AgentToolResult(
89+
return try {
90+
AgentToolResult(
7991
successful = true,
8092
result = agent.runAndGetResult(args.request)
8193
)
8294
} catch (e: Throwable) {
83-
return AgentToolResult(
95+
AgentToolResult(
8496
successful = false,
8597
errorMessage = "Error happened: ${e::class.simpleName}(${e.message})\n" +
8698
e.stackTraceToString().take(100)

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/config/AIAgentConfig.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@ public class AIAgentConfig(
2626
)
2727
): AIAgentConfigBase {
2828

29+
/**
30+
* Companion object for providing utility methods related to `AIAgentConfig`.
31+
*/
2932
public companion object {
3033

34+
/**
35+
* Creates an AI agent configuration with a specified system prompt.
36+
*
37+
* This function initializes an instance of `AIAgentConfig` using the provided system-level prompt
38+
* and other optional parameters, such as the language model, configuration ID, and maximum agent iterations.
39+
*
40+
* @param prompt The content of the system prompt to define the context and instructions for the AI agent.
41+
* @param llm The Large Language Model (LLM) to be used for the AI agent. Defaults to OpenAIModels.Chat.GPT4o.
42+
* @param id The identifier for the agent configuration. Defaults to "code-engine-agents".
43+
* @param maxAgentIterations The maximum number of iterations the agent can perform to avoid infinite loops. Defaults to 3.
44+
* @return An instance of `AIAgentConfigBase` representing the AI agent configuration with the specified parameters.
45+
*/
3146
public fun withSystemPrompt(
3247
prompt: String,
3348
llm: LLModel = OpenAIModels.Chat.GPT4o,

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/config/AIAgentConfigBase.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,44 @@ import ai.koog.prompt.llm.LLModel
88
*/
99
public interface AIAgentConfigBase {
1010

11+
/**
12+
* Defines the `Prompt` to be utilized in the AI agent's configuration.
13+
*
14+
* The `prompt` serves as the input structure for generating outputs from the language model and consists
15+
* of a list of messages, a unique identifier, and optional parameters. This property plays a role
16+
* in managing conversational state, input prompts, and configurations for the language model.
17+
*/
1118
public val prompt: Prompt
1219

20+
/**
21+
* Specifies the Large Language Model (LLM) used by the AI agent for generating responses.
22+
*
23+
* The model defines configurations such as the specific LLM provider, its identifier,
24+
* and supported capabilities (e.g., temperature control, tool usage). It plays a
25+
* vital role in determining how the AI agent processes and generates outputs
26+
* in response to user prompts and tasks.
27+
*/
1328
public val model: LLModel
1429

30+
/**
31+
* Specifies the maximum number of iterations an AI agent is allowed to perform during its operation.
32+
*
33+
* This value acts as a safeguard to prevent infinite loops in scenarios where the agent's logic
34+
* might otherwise continue indefinitely. It determines the number of steps the agent can take
35+
* while executing its task, and exceeding this limit will halt the agent's processing.
36+
*/
1537
public val maxAgentIterations: Int
1638

39+
/**
40+
* Strategy used to determine how tool calls, present in the prompt but lacking definitions,
41+
* are handled during agent execution.
42+
*
43+
* This property provides a mechanism to convert or format missing tool call and result messages when they occur,
44+
* typically due to differences in tool sets between steps or subgraphs while the same history is reused. This ensures
45+
* the prompt remains consistent and readable for the model, even with undefined tools.
46+
*
47+
* The specific behavior is determined by the selected `MissingToolsConversionStrategy`, which may either replace
48+
* all tool-related messages or only those corresponding to missing tool definitions.
49+
*/
1750
public val missingToolsConversionStrategy: MissingToolsConversionStrategy
1851
}

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/config/MissingToolsConversionStrategy.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,23 @@ import ai.koog.prompt.message.Message
1414
* @property format Formatter used to convert tool calls
1515
*/
1616
public abstract class MissingToolsConversionStrategy(private val format: ToolCallDescriber) {
17+
/**
18+
* Converts a given [Prompt] by applying modifications based on the provided list of [ToolDescriptor].
19+
*
20+
* @param prompt The original [Prompt] to be converted.
21+
* @param tools The list of [ToolDescriptor] used to modify or adapt the [Prompt].
22+
* @return A new [Prompt] instance with applied changes based on the provided tools.
23+
*/
1724
public abstract fun convertPrompt(prompt: Prompt, tools: List<ToolDescriptor>): Prompt
1825

26+
/**
27+
* Converts the given message by formatting specific types of tool-related messages
28+
* (e.g., `Message.Tool.Call` and `Message.Tool.Result`) into descriptive messages.
29+
* If the message is not a tool-related message, it remains unchanged.
30+
*
31+
* @param message The input message to be converted.
32+
* @return The converted message, either modified if it's a tool-related message, or unchanged otherwise.
33+
*/
1934
public fun convertMessage(message: Message): Message {
2035
return when (message) {
2136
is Message.Tool.Call -> format.describeToolCall(message)

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/entity/AIAgentNode.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import ai.koog.agents.core.annotation.InternalAgentsApi
1111
* @param Output The type of output data this node produces.
1212
*/
1313
public abstract class AIAgentNodeBase<Input, Output> internal constructor() {
14+
/**
15+
* The name of the AI agent node.
16+
* This property serves as a unique identifier for the node within the strategy graph
17+
* and is used to distinguish and reference nodes in the graph structure.
18+
*/
1419
public abstract val name: String
1520

1621
/**
@@ -122,7 +127,24 @@ internal class AIAgentNode<Input, Output> internal constructor(
122127
override suspend fun execute(context: AIAgentContextBase, input: Input): Output = context.execute(input)
123128
}
124129

130+
/**
131+
* Represents the base node for starting a subgraph in an AI agent strategy graph.
132+
* Derived from [AIAgentNodeBase], this node acts as an entry point for executing subgraphs
133+
* identified by a unique name.
134+
*
135+
* @param Input The type of input data this node processes and produces as output.
136+
*/
125137
public open class StartAIAgentNodeBase<Input>() : AIAgentNodeBase<Input, Input>() {
138+
/**
139+
* The name of the subgraph associated with the AI agent's starting node.
140+
*
141+
* This property serves as an identifier or label for the subgraph, helping to distinguish
142+
* and reference specific AI workflows or strategies. It can be null if no subgraph
143+
* name has been assigned.
144+
*
145+
* Internal changes to this property are restricted to ensure controlled modification, as the setter
146+
* is marked internal. Its value may influence how the AI agent node generates its unique name.
147+
*/
126148
public var subgraphName: String? = null
127149
internal set
128150

@@ -131,7 +153,23 @@ public open class StartAIAgentNodeBase<Input>() : AIAgentNodeBase<Input, Input>(
131153
override suspend fun execute(context: AIAgentContextBase, input: Input): Input = input
132154
}
133155

156+
/**
157+
* Represents a specialized node within an AI agent strategy graph that marks the endpoint
158+
* of a subgraph. This node serves as a "finish" node and directly passes its input
159+
* to its output without modification, acting as an identity operation.
160+
*
161+
* @param Output The type of data this node processes and produces.
162+
*/
134163
public open class FinishAIAgentNodeBase<Output>() : AIAgentNodeBase<Output, Output>() {
164+
/**
165+
* Stores the name of the subgraph associated with the node.
166+
*
167+
* This variable is used to identify or tag subgraphs in AI agent strategies.
168+
* If `subgraphName` is set, it will be integrated into the node's identity or behavior,
169+
* such as forming a unique name for the node.
170+
*
171+
* This property is mutable within the internal scope, but read-only from external scopes.
172+
*/
135173
public var subgraphName: String? = null
136174
internal set
137175

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/entity/AIAgentState.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ internal class AIAgentState internal constructor(
1717
}
1818
}
1919

20+
/**
21+
* Manages the state of an AI agent by providing thread-safe access and mechanisms
22+
* to update the internal state using a locking mechanism.
23+
*
24+
* This class ensures consistency across state modifications by using a mutual exclusion
25+
* lock, allowing only one coroutine to access or modify the state at a time.
26+
*
27+
* @constructor Creates a new instance of AIAgentStateManager with the initial state,
28+
* defaulting to a new `AIAgentState` if not provided.
29+
*/
2030
public class AIAgentStateManager internal constructor(
2131
private var state: AIAgentState = AIAgentState()
2232
) {

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/entity/AIAgentStorage.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ package ai.koog.agents.core.agent.entity
33
import kotlinx.coroutines.sync.Mutex
44
import kotlinx.coroutines.sync.withLock
55

6+
/**
7+
* Represents a storage key used for identifying and accessing data associated with an AI agent.
8+
*
9+
* The generic type parameter [T] specifies the type of data associated with this key, ensuring
10+
* type safety when storing and retrieving data in the context of an AI agent.
11+
*
12+
* @param name The string identifier that uniquely represents the storage key.
13+
*/
614
public data class AIAgentStorageKey<T : Any>(val name: String)
715

16+
/**
17+
* Creates a storage key for a specific type, allowing identification and retrieval of values associated with it.
18+
*
19+
* @param name The name of the storage key, used to uniquely identify it.
20+
* @return A new instance of [AIAgentStorageKey] for the specified type.
21+
*/
822
public inline fun <reified T : Any> createStorageKey(name: String): AIAgentStorageKey<T> = AIAgentStorageKey<T>(name)
923

1024
/**

agents/agents-core/src/commonMain/kotlin/ai/koog/agents/core/agent/session/AIAgentLLMSession.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ public sealed class AIAgentLLMSession(
115115
executeMultiple(prompt, tools).first()
116116

117117

118+
/**
119+
* Sends a request to the language model without utilizing any tools and returns the response.
120+
*
121+
* This method validates the session state before proceeding with the operation. If tool usage
122+
* is disabled (i.e., the tools list is empty), the tool choice parameter will be set to null
123+
* to ensure compatibility with the underlying LLM client's behavior. It then executes the request
124+
* and retrieves the response from the LLM.
125+
*
126+
* @return The response message from the language model after executing the request, represented
127+
* as a [Message.Response] instance.
128+
*/
118129
public open suspend fun requestLLMWithoutTools(): Message.Response {
119130
validateSession()
120131
/*
@@ -128,6 +139,14 @@ public sealed class AIAgentLLMSession(
128139
return executeSingle(promptWithDisabledTools, tools)
129140
}
130141

142+
/**
143+
* Sends a request to the language model that enforces the usage of tools and retrieves the response.
144+
*
145+
* This method updates the session's prompt configuration to mark tool usage as required before
146+
* executing the request. Additionally, it ensures the session is active before proceeding.
147+
*
148+
* @return The response from the language model after executing the request with enforced tool usage.
149+
*/
131150
public open suspend fun requestLLMOnlyCallingTools(): Message.Response {
132151
validateSession()
133152
val promptWithOnlyCallingTools = prompt.withUpdatedParams {
@@ -136,6 +155,20 @@ public sealed class AIAgentLLMSession(
136155
return executeSingle(promptWithOnlyCallingTools, tools)
137156
}
138157

158+
/**
159+
* Sends a request to the language model while enforcing the use of a specific tool,
160+
* and returns the response.
161+
*
162+
* This method validates that the session is active and checks if the specified tool
163+
* exists within the session's set of available tools. It updates the prompt configuration
164+
* to enforce the selection of the specified tool before executing the request.
165+
*
166+
* @param tool The tool to be used for the request, represented by a [ToolDescriptor] instance.
167+
* This parameter ensures that the language model utilizes the specified tool
168+
* during the interaction.
169+
* @return The response from the language model as a [Message.Response] instance after
170+
* processing the request with the enforced tool.
171+
*/
139172
public open suspend fun requestLLMForceOneTool(tool: ToolDescriptor): Message.Response {
140173
validateSession()
141174
check(tools.contains(tool)) { "Unable to force call to tool `${tool.name}` because it is not defined" }
@@ -145,6 +178,18 @@ public sealed class AIAgentLLMSession(
145178
return executeSingle(promptWithForcingOneTool, tools)
146179
}
147180

181+
/**
182+
* Sends a request to the language model while enforcing the use of a specific tool, and returns the response.
183+
*
184+
* This method ensures the session is active and updates the prompt configuration to enforce the selection of the
185+
* specified tool before executing the request. It uses the provided tool as a focus for the language model to process
186+
* the interaction.
187+
*
188+
* @param tool The tool to be used for the request, represented as an instance of [Tool]. This parameter ensures
189+
* the specified tool is utilized during the LLM interaction.
190+
* @return The response from the language model as a [Message.Response] instance after processing the request with the
191+
* enforced tool.
192+
*/
148193
public open suspend fun requestLLMForceOneTool(tool: Tool<*, *>): Message.Response {
149194
return requestLLMForceOneTool(tool.descriptor)
150195
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
package ai.koog.agents.core.annotation
22

3+
/**
4+
* Indicates that the annotated API is internal to agent-related implementations and not intended for public use.
5+
*
6+
* Classes, functions, or members marked with this annotation are part of the internal functionality of the AI agents infrastructure
7+
* and are not guaranteed to maintain backwards compatibility. They are subject to change, removal, or modification without notice.
8+
*
9+
* This annotation is primarily used to signal to developers that the API is not designed for general application development
10+
* and should only be used with caution in specialized scenarios, such as extending or modifying internal agent behavior.
11+
*/
312
@RequiresOptIn
413
public annotation class InternalAgentsApi

0 commit comments

Comments
 (0)