|
| 1 | +package agents_engine.model |
| 2 | + |
| 3 | +import agents_engine.core.agent |
| 4 | +import kotlin.test.Test |
| 5 | +import kotlin.test.assertEquals |
| 6 | + |
| 7 | +/** |
| 8 | + * #1016 — `Skill.tools(...)` accepts typed `Tool<*, *>` handles in addition to |
| 9 | + * the legacy stringly-typed form. The two forms produce identical |
| 10 | + * `Skill.toolNames` and dispatch identically through the agentic loop. |
| 11 | + * |
| 12 | + * The string form stays — typed and string overloads coexist; #1017 will |
| 13 | + * deprecate the string form (warning level), but not yet. |
| 14 | + */ |
| 15 | +class TypedToolRefsTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + fun `typed tool refs produce same toolNames as string form`() { |
| 19 | + val typedAgent = agent<String, String>("typed-form") { |
| 20 | + lateinit var fetch: Tool<Map<String, Any?>, Any?> |
| 21 | + lateinit var compile: Tool<Map<String, Any?>, Any?> |
| 22 | + tools { |
| 23 | + fetch = tool("fetch", "Fetch") { _ -> "fetched" } |
| 24 | + compile = tool("compile", "Compile") { _ -> "compiled" } |
| 25 | + } |
| 26 | + skills { |
| 27 | + skill<String, String>("build") { |
| 28 | + tools(fetch, compile) |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + val stringAgent = agent<String, String>("string-form") { |
| 34 | + tools { |
| 35 | + tool("fetch", "Fetch") { _ -> "fetched" } |
| 36 | + tool("compile", "Compile") { _ -> "compiled" } |
| 37 | + } |
| 38 | + skills { |
| 39 | + skill<String, String>("build") { |
| 40 | + tools("fetch", "compile") |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + val typedSkill = typedAgent.skills["build"]!! |
| 46 | + val stringSkill = stringAgent.skills["build"]!! |
| 47 | + |
| 48 | + assertEquals(stringSkill.toolNames, typedSkill.toolNames) |
| 49 | + assertEquals(true, typedSkill.isAgentic) |
| 50 | + assertEquals(listOf("fetch", "compile"), typedSkill.toolNames) |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + fun `typed refs survive validate() — agent constructs without unknown-tool error`() { |
| 55 | + val a = agent<String, String>("typed-validate") { |
| 56 | + lateinit var ping: Tool<Map<String, Any?>, Any?> |
| 57 | + tools { |
| 58 | + ping = tool("ping", "Ping") { _ -> "pong" } |
| 59 | + } |
| 60 | + skills { |
| 61 | + skill<String, String>("respond") { |
| 62 | + tools(ping) |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + assertEquals(listOf("ping"), a.skills["respond"]!!.toolNames) |
| 67 | + } |
| 68 | +} |
0 commit comments