33package dev.johnoreilly.climatetrace.agent
44
55import ai.koog.agents.core.tools.SimpleTool
6- import ai.koog.agents.core.tools.ToolDescriptor
7- import ai.koog.agents.core.tools.ToolParameterDescriptor
8- import ai.koog.agents.core.tools.ToolParameterType
96import ai.koog.agents.core.tools.annotations.LLMDescription
107import dev.johnoreilly.climatetrace.data.ClimateTraceRepository
118import dev.johnoreilly.climatetrace.remote.Country
@@ -17,19 +14,20 @@ import kotlin.time.Clock
1714import kotlin.time.ExperimentalTime
1815
1916
20- class GetCountryTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetCountryTool.Args>() {
17+ class GetCountryTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetCountryTool.Args>(
18+ argsSerializer = Args .serializer(),
19+ name = " GetCountryTool" ,
20+ description = " Look up country code using country name"
21+ ) {
2122 @Serializable
2223 data class Args (
2324 @property:LLMDescription("Country name")
2425 val countryName : String
2526 )
2627
27- override val argsSerializer = Args .serializer()
28- override val description = " Look up country code using country name"
29-
3028 private var countryList: List <Country >? = null
3129
32- override suspend fun doExecute (args : Args ): String {
30+ override suspend fun execute (args : Args ): String {
3331 try {
3432 if (countryList == null ) {
3533 countryList = climateTraceRepository.fetchCountries()
@@ -43,57 +41,55 @@ class GetCountryTool(val climateTraceRepository: ClimateTraceRepository) : Simpl
4341}
4442
4543
46- class GetEmissionsTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetEmissionsTool.Args>() {
44+ class GetEmissionsTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetEmissionsTool.Args>(
45+ argsSerializer = Args .serializer(),
46+ name = " GetEmissionsTool" ,
47+ description = " Get the emission data for a country for a particular year."
48+ ) {
4749 @Serializable
4850 data class Args (
4951 @property:LLMDescription("ISO country code list (e.g., 'USA ', 'GBR ', 'FRA ')")
5052 val countryCodeList : List <String >,
5153 @property:LLMDescription("Year for which emissions occurred")
5254 val year : String
5355 )
54- override val argsSerializer = Args .serializer()
55- override val description = " Get the emission data for a country for a particular year."
5656
57- override suspend fun doExecute (args : Args ): String {
57+ override suspend fun execute (args : Args ): String {
5858 return climateTraceRepository.fetchCountryEmissionsInfo(args.countryCodeList, args.year).joinToString {
5959 it.emissions.co2.toString()
6060 }
6161 }
6262}
6363
6464
65- class GetAssetEmissionsTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetAssetEmissionsTool.Args>() {
65+ class GetAssetEmissionsTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetAssetEmissionsTool.Args>(
66+ argsSerializer = Args .serializer(),
67+ name = " GetAssetEmissionsTool" ,
68+ description = " Get the asset emission data for a country."
69+ ) {
6670 @Serializable
6771 data class Args (
6872 @property:LLMDescription("ISO country code list (e.g., 'USA ', 'GBR ', 'FRA ')")
6973 val countryCodeList : List <String >,
7074 )
71- override val argsSerializer = Args .serializer()
72- override val description = " Get the asset emission data for a country."
7375
74- override suspend fun doExecute (args : Args ): String {
76+ override suspend fun execute (args : Args ): String {
7577 return climateTraceRepository.fetchCountryAssetEmissionsInfo(args.countryCodeList).toString()
7678 }
7779}
7880
79- class GetPopulationTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetPopulationTool.Args>() {
81+ class GetPopulationTool (val climateTraceRepository : ClimateTraceRepository ) : SimpleTool<GetPopulationTool.Args>(
82+ argsSerializer = Args .serializer(),
83+ name = " GetPopulationTool" ,
84+ description = " Get population data for a country by its country code"
85+ ) {
8086 @Serializable
81- data class Args (val countryCode : String )
82-
83- override val argsSerializer = Args .serializer()
84- override val description = " Get population data for a country by its country code"
85-
86- override val descriptor = ToolDescriptor (
87- name = " GetPopulationTool" ,
88- description = " Get population data for a country by its country code" ,
89- requiredParameters = listOf (
90- ToolParameterDescriptor (
91- name = " countryCode" , description = " ISO country code (e.g., 'USA', 'GBR', 'FRA')" , type = ToolParameterType .String
92- )
93- ),
87+ data class Args (
88+ @property:LLMDescription("ISO country code (e.g., 'USA ', 'GBR ', 'FRA ')")
89+ val countryCode : String
9490 )
9591
96- override suspend fun doExecute (args : Args ): String {
92+ override suspend fun execute (args : Args ): String {
9793 println (" Getting population for ${args.countryCode} " )
9894 try {
9995 val population = climateTraceRepository.getPopulation(args.countryCode)
@@ -112,19 +108,18 @@ class GetPopulationTool(val climateTraceRepository: ClimateTraceRepository) : Si
112108class CurrentDatetimeTool (
113109 val defaultTimeZone : TimeZone = TimeZone .UTC ,
114110 val clock : Clock = Clock .System ,
115- ) : SimpleTool<CurrentDatetimeTool.Args>() {
111+ ) : SimpleTool<CurrentDatetimeTool.Args>(
112+ argsSerializer = Args .serializer(),
113+ name = " current_datetime" ,
114+ description = " Get the current date and time in the specified timezone"
115+ ) {
116116 @Serializable
117117 data class Args (
118118 @property:LLMDescription("The timezone to get the current date and time in (e.g., 'UTC ', 'America /New_York ', 'Europe /London '). Defaults to UTC .")
119119 val timezone : String = " UTC"
120120 )
121121
122- override val argsSerializer = Args .serializer()
123-
124- override val name = " current_datetime"
125- override val description = " Get the current date and time in the specified timezone"
126-
127- override suspend fun doExecute (args : Args ): String {
122+ override suspend fun execute (args : Args ): String {
128123 val zoneId = try {
129124 TimeZone .of(args.timezone)
130125 } catch (_: Exception ) {
0 commit comments