A-Graph by Agens Research Labs

Utilities

A utility is a program or a service of yours that the program calls on the data of a node, before or after the model: to convert a PDF into Markdown, to hide personal data, to add a mark.

A utility is a program or a service of yours that the program calls on the data of a node, before or after the model: to convert a PDF into Markdown, to hide personal data, to add a mark. Unlike a tool, the model does not know that utilities exist. They can be written in any language. Utilities are declared in utilities, each with an id; a node names them where it wants its data changed. Every key is described in the reference.

utilities:
  - id: pdf_to_md
    transport: stdio
    command: python3
    args: [utilities/pdf_to_md.py]
    timeout: 60
  - id: redact
    transport: http
    url: http://localhost:9000/redact
    headers: { Authorization: { env: REDACT_TOKEN } }
    timeout: 60
  • transport: stdio: the program is started for each call. A container that runs once is a program too: command: docker with args: [run, --rm, -i, <image>].
  • transport: http: a service already running, which a-graph does not start or stop. Its host must be in the allowed hosts.
  • timeout (mandatory, at least 1): the seconds a call may take; after that the program is stopped or the request is abandoned.

The contract

A utility receives one JSON object and answers one, on its standard input and output (stdio) or as the body of a POST and of its answer (http).

It receives a text, or a file: by its path, or by its bytes in base64.

{ "text": "..." }
{ "path": "docs/a.pdf", "mime_type": "application/pdf" }
{ "data": "<base64>", "mime_type": "application/pdf" }

A program (stdio) gets the path of a file on disk: a media from the resources with a source: { path }. Every other file comes as its bytes: a file for a service (http), which may not see the disk of a-graph, and a file in memory, a media in base64, a media from a url or a file made by a model, by a node or by the utility before. a-graph writes no file of its own for a utility.

mime_type is the type of the file. For a file on disk it comes from the extension (pdf, docx, xlsx, pptx, html, md, txt, csv, json, png, jpg, webp, gif, mp3, wav, mp4), and is left out when the extension does not say it; for a media in base64 it is the mime_type the graph gives, and is left out when the graph gives none; for a media from a url it is the mime_type the graph gives, or else the one of the extension of the path of the url; for a file made by a model, by a node or by a utility it is the type given by what made it.

It answers a text, or a file in base64 with its type:

{ "text": "..." }
{ "mime_type": "application/pdf", "data": "<base64>" }

When a utility fails

A utility that fails stops the run, with its exit status or the status of its answer. What it wrote, on its standard error or in the body of its answer, is the detail of the error: a content, written only as the passport allows (see observability). No model is involved to read the reason. A utility that answers neither text nor mime_type with data, or that does not answer within timeout, fails too (utility_failed). A file in memory that is not valid base64 is not sent: the utility that would get it fails (utility_failed), and why the base64 is not valid is the detail.

Where a node uses them

The key utility names one or more utilities, by id, in the order they run: each gets what the one before answered. One id alone is a list of one.

PlaceWhat goes throughWhat they must give back
message.input.utilitythe messages the node takes, from the user and from the node beforea text
message.output.utilitythe text the node produces, once, before every destinationa text
media.input[].utilitya media the node reads, by its path or its bytes (see the contract)a text or an image
media.output[].utilitywith from: model, the file the model made; with from: message, the text of the nodea file
external.vectordb[].utility.querythe query, before it is turned into a vector and searcheda text
external.vectordb[].utility.chunkseach chunk found, before the prompta text
external.memory[].read.utilityeach message read back, and the summarya text
external.memory[].write.utilitywhat is saved, after the utilities of message.outputa text
blackboard.write.utilitythe text written, after the utilities of message.outputa text

A utility that gives back a file where a text is needed fails the run.

On this page