xonecas.io
7814
Ta

tiny-c-agent / files

tiny-c-agent / src / tool.h

2.0 KB
1// tiny tools: the capabilities the model may call.
2//
3// Three plain functions: `read` returns a file's text (or an image), `edit`
4// replaces text in a file, and `bash` runs a shell command. Each result carries
5// text, an error flag, optional images, and display-only file diffs.
6
7#ifndef TINY_TOOL_H
8#define TINY_TOOL_H
9
10#include <stdbool.h>
11#include <stddef.h>
12
13#include "provider.h"
14
15// One image a tool attached to its result.
16typedef struct {
17    char *media_type;  // e.g. "image/png"
18    char *data;        // base64 payload
19} tiny_image;
20
21// One changed file under the working directory, display-only: it never reaches
22// the model. `patch` is a unified diff; it is NULL when the content cannot be
23// tracked, in which case `note` explains why.
24typedef struct {
25    char *path;   // relative to the working directory
26    char *patch;  // unified diff body, or NULL
27    char *note;   // reason when no patch exists, or NULL
28} tiny_file_diff;
29
30typedef struct {
31    char *text;          // the tool result text; always set
32    bool is_error;
33    tiny_image *images;  // owned by the caller
34    size_t images_len;
35    tiny_file_diff *diffs;  // owned by the caller; display-only
36    size_t diffs_len;
37} tiny_tool_result;
38
39// A tool's streamed output (bash's stdout/stderr), forwarded to the projection.
40typedef void (*tiny_tool_output_fn)(const char *chunk, void *user);
41
42// The tools the model may call. `*len` receives the count. `supports_images`
43// gates whether read's description mentions image input. The array is static
44// and must not be freed.
45const tiny_tool *tiny_tools(bool supports_images, size_t *len);
46
47// Executes `name` with `args`, a JSON object string. An unknown tool name yields
48// an error result. `out` forwards streamed output and may be NULL. `cancel` is
49// polled by bash and may be NULL.
50tiny_tool_result tiny_tool_run(const char *name, const char *args, bool supports_images,
51                               tiny_tool_output_fn out, void *user, const volatile bool *cancel);
52
53#endif