11package ai.koog.agents.core.tools
22
3+ import ai.koog.prompt.params.LLMParams
4+
35/* *
46 * Represents a descriptor for a tool that contains information about the tool's name, description, required parameters,
57 * and optional parameters.
@@ -10,12 +12,18 @@ package ai.koog.agents.core.tools
1012 * @property description The description of the tool.
1113 * @property requiredParameters A list of ToolParameterDescriptor representing the required parameters for the tool.
1214 * @property optionalParameters A list of ToolParameterDescriptor representing the optional parameters for the tool.
15+ * @property cacheControl Optional cache control setting for this tool definition.
16+ * When set, signals to LLM providers (like Anthropic) that tool definitions up to and including
17+ * this tool should be cached. This is useful for reducing latency and cost when the same tools
18+ * are used across multiple requests. Cache control is applied per-tool, allowing fine-grained
19+ * control over which tools act as cache breakpoints.
1320 */
1421public open class ToolDescriptor (
1522 public val name : String ,
1623 public val description : String ,
1724 public val requiredParameters : List <ToolParameterDescriptor > = emptyList(),
1825 public val optionalParameters : List <ToolParameterDescriptor > = emptyList(),
26+ public val cacheControl : LLMParams .CacheControl ? = null ,
1927) {
2028 /* *
2129 * Creates a copy of the current ToolDescriptor with the option to modify specific attributes.
@@ -26,19 +34,22 @@ public open class ToolDescriptor(
2634 * Defaults to the current required parameters if not provided.
2735 * @param optionalParameters A list of ToolParameterDescriptor representing the optional parameters for the tool.
2836 * Defaults to the current optional parameters if not provided.
37+ * @param cacheControl Optional cache control setting for this tool. Defaults to the current cache control if not provided.
2938 * @return A new instance of ToolDescriptor with the updated attributes.
3039 */
3140 public fun copy (
3241 name : String = this.name,
3342 description : String = this.description,
3443 requiredParameters : List <ToolParameterDescriptor > = this.requiredParameters.toList(),
3544 optionalParameters : List <ToolParameterDescriptor > = this.optionalParameters.toList(),
45+ cacheControl : LLMParams .CacheControl ? = this.cacheControl,
3646 ): ToolDescriptor {
3747 return ToolDescriptor (
3848 name = name,
3949 description = description,
4050 requiredParameters = requiredParameters,
4151 optionalParameters = optionalParameters,
52+ cacheControl = cacheControl,
4253 )
4354 }
4455
@@ -50,19 +61,34 @@ public open class ToolDescriptor(
5061 if (description != other.description) return false
5162 if (requiredParameters != other.requiredParameters) return false
5263 if (optionalParameters != other.optionalParameters) return false
64+ if (cacheControl != other.cacheControl) return false
5365
5466 return true
5567 }
5668
5769 override fun toString (): String {
58- return " ToolDescriptor(name=$name , description=$description , requiredParameters=$requiredParameters , optionalParameters=$optionalParameters )"
70+ return " ToolDescriptor(name=$name , description=$description , requiredParameters=$requiredParameters , optionalParameters=$optionalParameters , cacheControl= $cacheControl )"
5971 }
6072
6173 override fun hashCode (): Int {
6274 var result = name.hashCode()
6375 result = 31 * result + description.hashCode()
6476 result = 31 * result + requiredParameters.hashCode()
6577 result = 31 * result + optionalParameters.hashCode()
78+ result = 31 * result + (cacheControl?.hashCode() ? : 0 )
6679 return result
6780 }
6881}
82+
83+ /* *
84+ * Creates a copy of this ToolDescriptor with the specified cache control setting.
85+ *
86+ * This is a convenience extension function for setting cache control on tool definitions.
87+ * When cache control is set, LLM providers like Anthropic will cache tool definitions
88+ * up to and including this tool, reducing latency and cost for repeated requests.
89+ *
90+ * @param cacheControl The cache control setting to apply to this tool.
91+ * @return A new ToolDescriptor with the cache control setting applied.
92+ */
93+ public fun ToolDescriptor.withCacheControl (cacheControl : LLMParams .CacheControl ): ToolDescriptor =
94+ copy(cacheControl = cacheControl)
0 commit comments