summaryrefslogtreecommitdiff
path: root/src/ping_tool.zig
blob: eb212af0bbd01ea93db3c4512c5fb500f5554815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 {}