diff options
Diffstat (limited to 'src/ping_tool.zig')
| -rw-r--r-- | src/ping_tool.zig | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/ping_tool.zig b/src/ping_tool.zig new file mode 100644 index 0000000..eb212af --- /dev/null +++ b/src/ping_tool.zig @@ -0,0 +1,57 @@ +//! A trivial built-in "ping" tool used to exercise the tool-call loop +//! end-to-end against a real LLM. It accepts a `host` string and always +//! returns the literal string "PONG", regardless of what the host is. +//! +//! In phase 5 this kind of built-in will be replaced by a proper extension; +//! for now it lives in the CLI so we can verify the libpanto tool plumbing +//! without writing the Lua bridge first. + +const std = @import("std"); +const panto = @import("panto"); + +const NAME = "ping"; +const DESCRIPTION = + \\Test whether a server is reachable by hostname. Always responds with + \\"PONG" when the server is up. Use this when the user asks you to check + \\if a host is online or reachable. +; +const SCHEMA_JSON = + \\{ + \\ "type": "object", + \\ "properties": { + \\ "host": { + \\ "type": "string", + \\ "description": "The hostname or address to ping." + \\ } + \\ }, + \\ "required": ["host"] + \\} +; + +/// Returns a `Tool` value ready to register with `Agent.registerTool`. The +/// tool holds no per-instance state: name, description, and schema are +/// `comptime` string literals, and the vtable's deinit is a no-op. We pass +/// a sentinel pointer as ctx since the contract requires *anyopaque but +/// nothing dereferences it. +pub fn tool() panto.Tool { + return .{ + .name = NAME, + .description = DESCRIPTION, + .schema_json = SCHEMA_JSON, + .ctx = &ctx_sentinel, + .vtable = &vtable, + }; +} + +var ctx_sentinel: u8 = 0; + +const vtable: panto.Tool.VTable = .{ + .invoke = invoke, + .deinit = deinitNoop, +}; + +fn invoke(_: *anyopaque, _: []const u8, allocator: std.mem.Allocator) anyerror![]u8 { + return try allocator.dupe(u8, "PONG"); +} + +fn deinitNoop(_: *anyopaque, _: std.mem.Allocator) void {} |
