Skip to content

Generate Action Code

POST /ai/action/code refines the Tengo script on an existing action draft. The structure of the draft (name, description, trigger, input) stays unchanged; only the code and summary change.

Request

json
{
  "prompt": "Skip sending the email when the booking is shorter than 15 minutes.",
  "previous_summary": "Loads the booking, formats the start and end time, and emails the booker.",
  "previous_code": "/* the tengo code from the previous generation */",
  "trigger": "booking_created"
}

prompt, previous_summary, previous_code, and trigger are all required:

  • prompt describes what should change.
  • previous_summary and previous_code carry the latest summary and code from the draft. Pass them straight from the last response.
  • trigger is the event the script must run on. The generator uses it to scope the available context variables.

input is optional. Pass it to lock the input schema for the regenerated script.

Response

json
{
  "data": {
    "request_id": "f5b6d3a2-58a3-4f5e-9b48-3da1a8de0fa2",
    "code": {
      "code": "/* revised tengo */",
      "summary": "Adds a guard that returns early when the booking duration is below 15 minutes, then emails the booker."
    }
  },
  "request_id": "21a7c44a-39ad-4f6b-b07f-9e58b87a4ee9",
  "count": 1
}

Use the new code and summary as the next previous_code and previous_summary if you need another refinement pass.

Updating the Action

The endpoint returns code only. To persist the change, send the updated code and summary through PUT /action/{action_id}. The other fields on the action row are not modified.

Following Progress

Refinement runs inline like generation. Stream GET /ai/request/{id} or GET /ai/request/{id}/response with Accept: text/event-stream to follow status while a run is in flight.