Skip to content

Intent tools ​

An intent tool is one tool that makes several API calls in a fixed order: look up an order, check it can be refunded, create the refund, answer with the result. The data passed between the calls never reaches the model, so it is faster, cheaper and safer than letting a model chain calls itself.

An environment serves intent tools when its tool mode is intent.

An example ​

The operations below (getOrder, createRefund) stand for your own: a step names a generated tool, which is normally the operation's operationId.

json
{
  "description": "Refund an order if it can be refunded",
  "inputs": [
    {"name": "order_id", "type": "string", "required": true, "description": "The order number"}
  ],
  "steps": [
    {"id": "order", "operation": "getOrder", "args": {"id": {"from": "input", "name": "order_id"}}},
    {"id": "refund", "operation": "createRefund",
     "when": {"step": "order", "field": "refundable", "is": "equals", "value": {"from": "literal", "value": true}},
     "args": {
       "body.order_id": {"from": "input", "name": "order_id"},
       "body.amount": {"from": "step", "step": "order", "path": "total"}}}
  ],
  "output": [
    {"name": "status", "type": "string", "required": true, "value": {"from": "literal", "value": "refunded"}},
    {"name": "refund_id", "type": "string", "value": {"from": "step", "step": "refund", "path": "id"}}
  ],
  "cases": [
    {"label": "Not refundable",
     "when": {"step": "order", "field": "refundable", "is": "not_equals", "value": {"from": "literal", "value": true}},
     "output": [{"name": "status", "type": "string", "required": true, "value": {"from": "literal", "value": "not_refundable"}}]}
  ]
}

Check it, try it as a customer, then save it:

bash
curl -X POST "https://api.frege.io/v1/projects/$PROJECT/composites/validate" \
  -H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
  -H "Content-Type: application/json" -d "{\"definition\": $(cat refund.json)}"

curl -X POST "https://api.frege.io/v1/projects/$PROJECT/composites/run" \
  -H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
  -H "Content-Type: application/json" \
  -d "{\"definition\": $(cat refund.json), \"arguments\": {\"order_id\": \"A-1001\"}, \"client_id\": 42}"

curl -X POST "https://api.frege.io/v1/projects/$PROJECT/composites" \
  -H "Authorization: Bearer $TOKEN" -H "X-Frege-Stage: staging" \
  -H "Content-Type: application/json" \
  -d "{\"name\": \"refund_order\", \"definition\": $(cat refund.json), \"enabled\": true}"

The routes ​

Every route below needs a manager or an admin of the project.

RouteWhat it does
GET /v1/projects/{id}/compositesThe environment's intent tools, each with enabled, mutating, the derived input_schema and output_schema, and a problem when it no longer compiles (a new spec can break a chain).
POST /v1/projects/{id}/compositesDefine one: {"name", "definition", "enabled"}. name is at most 60 characters and may not be a generated tool's name. The definition is compiled first: 422 with field definition when it does not, 409 for a name taken. enabled defaults to true.
PUT /v1/projects/{id}/composites/{name}Change one. enabled keeps its value when left out.
DELETE /v1/projects/{id}/composites/{name}Remove one.
POST /v1/projects/{id}/composites/validateCompile without saving: valid, problem, mutating, the planned steps, the schemas, and input_choices. Never 422.
POST /v1/projects/{id}/composites/runRun without saving, as a customer: {"definition", "arguments", "client_id"}. The answer has the final call's status_code and body, and every step's call.

A run from this route counts as the manager's approval where the write policy is ask; deny still refuses writes. A refused step answers 403 call_denied, bad arguments 422, a failed step 502.

Inputs ​

What the AI sends. Each input has a name and a type: string (the default), integer, number, boolean, array or object. Optional fields: description, required, default, enum (strings only), minimum and maximum (numbers only), and choices, which takes the allowed values from an earlier call: {"step": "id", "list": "data.items", "take": "code", "cache_seconds": 300}.

Steps ​

json
{"id": "pages", "operation": "listOrders", "args": {"page": {"from": "iteration"}},
 "repeat": {"until": {"field": "items", "is": "empty"}, "max": 10}, "collect": "items"}
FieldWhat it does
idUnique in the tool.
operationThe generated tool to call.
argsThe call's arguments by name: a path, query or header parameter, body for the whole body, or body.<field> for one field. Do not mix body and body.<field>.
whenRun only if an earlier step's answer passes a check.
for_eachRun once per entry of an earlier list: {"step", "list", "limit"}, limit 1 to 100. A longer list is refused, not cut short.
repeatRun again until its own answer passes a check: {"until", "max"}, max 1 to 100. Reaching max first is refused.
collectOn a loop: read this path from every pass and join them, flattening lists. Without it, the step's answer is the list of each pass's answer.

A check (when, until) is {"step", "field", "is", "value"}, where is is empty, not_empty or equals (which needs a value). until tests the pass's own answer, so it leaves step out.

Rules the compiler holds you to:

  • A step reads only steps that run before it.
  • A loop step cannot call a write.
  • A step has for_each or repeat, not both.
  • The worst case may not exceed 200 calls.
  • The tool is a write (mutating) when any step calls a write.

Values ​

fromFieldsWhat it is
inputnameOne of the tool's inputs.
literalvalueAny JSON.
stepstep, pathAn earlier step's answer.
selectstep, list, match: {field, value}, takeThe one entry of a list that matches.
whicheveroptions: [{step, path}]The one of several conditional steps that ran.
itempathThe current entry, in a for_each step or an output's each.
iterationThe pass number, from 1, in a loop.
previouspathThe previous pass's answer, in a repeat.
nowformatThe time: unix, unix_ms or rfc3339.
digestalgorithm, parts, separator, encodingA hash of other values.

Paths are dotted, with numbers for list positions. * walks every entry of a list and returns a flat list: items.*.id. Values nest at most four deep. Secrets, prompts and the sign-in's values are deliberately not here: the customer's credential reaches the calls by itself.

Output and cases ​

output is what the tool answers, as typed fields:

json
{"name": "orders", "type": "array", "each": {
  "list": {"from": "step", "step": "pages"}, "as": "order",
  "fields": [
    {"name": "id", "type": "string", "value": {"from": "item", "name": "order", "path": "id"}},
    {"name": "total", "type": "number", "value": {"from": "item", "name": "order", "path": "total"}}]}}
  • A field has name, type and one of value, fields (for an object) or each (for an array).
  • A missing value is left out of the answer, unless the field is required, in which case the tool fails. Inside fields and each a missing value is null.
  • Without output, the tool answers with the last step's answer, or the one result names.

cases choose another answer when a condition holds. They need an output: the first case that holds answers, and output answers when none does. A case's when is {"step", "field", "is", "value"}, where value is a literal and is is one of empty, not_empty, equals, not_equals, one_of, not_one_of, contains, not_contains, starts_with, ends_with, greater_than, greater_or_equal, less_than or less_or_equal. On a * path a test holds when any entry passes, and a not_ test when none does.