I have an MCP Server working successfully with Koo...
# koog-agentic-framework
j
I have an MCP Server working successfully with Koog. I'm trying now as a test to create a local annotation based tool (https://docs.koog.ai/annotation-based-tools/) to do same function but it's not being invoked for some reason. Is there any other setup needed to use that?
This is what I'm trying right now
Copy code
@LLMDescription("Tools for getting climate emission information")
class MyFirstToolSet : ToolSet {
    @Tool
    @LLMDescription("Get the emission data for a country.")
    fun getEmissions(
        @LLMDescription("The country")
        country: String,
        @LLMDescription("The year")
        year: String
    ): String {
        return "300"
    }
}
And this is my prompt (which, as mentioned, works when using my external MCP server)
Copy code
Get emisssions for France, Germany and Spain for 2023 and 2024.
The
toolRegistry
value used when constructing
AIAgent
is set to
ToolRegistry { MyFirstToolSet() }
d
Hey @John O'Reilly! Aren't you supposed to call a method of the
ToolRegistry
builder? Something like:
ToolRegistry { tools(MyFirstToolSet()) }
j
I think I had also tried something like that before but get following
d
Oh yeah, I think there was a
.asTools()
that was missing but has been added recently in the repo... What version are you using? 0.2.1 or the develop branch?
j
0.2.1
ok, updated to following and getting further now, thanks!
Copy code
val myFirstToolSetRegistry = ToolRegistry {
    tools(MyFirstToolSet().asTools())
}
❤️ 1
d
Yeah, that's it. The
ToolRegistry.Builder.tools(toolSet: ToolSet)
was missing and has been added recently (https://github.com/JetBrains/koog/commit/710f9eaac0106e2101e52807a0b6386559454adb). You have to do
.asTools()
by yourself in the 0.2.1. The doc is not fully in sync, but that will change as it is being moved inside the repository...
👍 1
j
btw I'm seeing following in logs....but still seems to work ok
Copy code
[main] ERROR ai.koog.agents.core.agent.AIAgent - Tool "getEmissions" failed to parse arguments: {"country":"France","year":2022}
kotlinx.serialization.json.internal.JsonDecodingException: String literal for key 'year' should be quoted at element: $.year.
Use 'isLenient = true' in 'Json {}' builder to accept non-compliant JSON.
this is for
Copy code
@Tool(customName = "getEmissions")
    @LLMDescription("Get the emission data for a country.")
    fun getEmissions(
        @LLMDescription("The country")
        country: String,
        @LLMDescription("The year")
        year: String
    ): String
d
Yeah, you defined the year as a string in your tool, but it seems your LLM is producing it as a number in the generated tool call. Even the best models sometimes fail to properly follow a JSON schema...
j
ah, thanks, I missed that.....if I switch to Int then it's happy
thank you color 1