Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-openai-request-2Built by davevia claude-codeRuns on Liberasnew version of agent-openai-request

OpenAI chat completions: request body, with provider turns

A new version of agent-openai-request (it supersedes it): exactly its rules, except that an assistant message with extra becomes extra parsed as JSON, as the whole message object, whatever its content and tool calls (ADR 0064). extra that is not JSON is the error "message {i}: extra is not JSON", checked where that message's other errors would be.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init agent-openai-request-2 --lang rust
cd agent-openai-request-2 && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)50 lines›
agent-openai-request-2.wit
package root:component;

world root {
  import liberas:agent/types@0.1.0;

  export liberas:agent/wire-request-body@0.1.0;
}
package liberas:agent@0.1.0 {
  interface types {
    enum role {
      system,
      user,
      assistant,
      tool,
    }

    record tool-call {
      id: string,
      name: string,
      arguments: string,
    }

    record message {
      role: role,
      content: string,
      tool-call-id: option<string>,
      tool-calls: option<list<tool-call>>,
      extra: option<string>,
    }

    record tool-def {
      name: string,
      description: string,
      input-schema: string,
    }

    record wire-request {
      model: string,
      max-tokens: u32,
      messages: list<message>,
      tools: list<tool-def>,
    }
  }
  interface wire-request-body {
    use types.{wire-request};

    body: func(request: wire-request) -> result<string, string>;
  }
}
Test vectors12›
agent-openai-request-2.cases.json
[
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [
          {
            "name": "read-file",
            "description": "Reads a file.",
            "input-schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
          }
        ],
        "messages": [
          {
            "role": "system",
            "content": "Be brief.",
            "tool-call-id": null
          },
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [
          {
            "name": "read-file",
            "description": "Reads a file.",
            "input-schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"}},\"required\":[\"path\"],\"additionalProperties\":false}"
          },
          {
            "name": "write-file",
            "description": "Writes a file.",
            "input-schema": "{\"type\":\"object\",\"properties\":{\"path\":{\"type\":\"string\"},\"text\":{\"type\":\"string\"}},\"required\":[\"path\",\"text\"],\"additionalProperties\":false}"
          }
        ],
        "messages": [
          {
            "role": "system",
            "content": "You are a careful assistant.",
            "tool-call-id": null
          },
          {
            "role": "user",
            "content": "read a and tell me",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": null,
            "content": "Reading.",
            "tool-calls": [
              {
                "id": "c1",
                "name": "read-file",
                "arguments": "{\"path\":\"a\"}"
              },
              {
                "id": "c2",
                "name": "read-file",
                "arguments": "{\"path\":\"b\"}"
              }
            ],
            "tool-call-id": null
          },
          {
            "role": "tool",
            "content": "alpha",
            "tool-call-id": "c1"
          },
          {
            "role": "tool",
            "content": "error: no such file",
            "tool-call-id": "c2"
          },
          {
            "role": "assistant",
            "extra": null,
            "content": "a says alpha; b is missing.",
            "tool-calls": [],
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": null,
            "content": "",
            "tool-calls": [
              {
                "id": "c1",
                "name": "read-file",
                "arguments": "{not json"
              }
            ],
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": null,
            "content": "",
            "tool-calls": [],
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": null,
            "content": "ok",
            "tool-calls": null,
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "tool",
            "content": "x",
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [
          {
            "name": "t",
            "description": "d",
            "input-schema": "{oops"
          }
        ],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "system",
            "content": "one",
            "tool-call-id": null
          },
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "system",
            "content": "two",
            "tool-call-id": null
          }
        ],
        "max-tokens": 1
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": "{\"role\":\"assistant\",\"content\":null,\"reasoning_content\":\"…\",\"tool_calls\":[{\"id\":\"c1\",\"type\":\"function\",\"function\":{\"name\":\"f\",\"arguments\":\"{}\"}}]}",
            "content": "ignored",
            "tool-calls": [],
            "tool-call-id": null
          },
          {
            "role": "tool",
            "content": "r",
            "tool-call-id": "c1"
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": "nope",
            "content": "",
            "tool-calls": [],
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  },
  {
    "args": {
      "request": {
        "model": "gpt-5",
        "tools": [],
        "messages": [
          {
            "role": "user",
            "content": "hi",
            "tool-call-id": null
          },
          {
            "role": "tool",
            "content": "x",
            "tool-call-id": null
          },
          {
            "role": "assistant",
            "extra": "nope",
            "content": "",
            "tool-calls": [],
            "tool-call-id": null
          }
        ],
        "max-tokens": 16000
      }
    }
  }
]
Versions (units)1›
  1. v1by dave3f2c93af25stable 5.1.0latestconfirmed10/23/2026
Verification9›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 12 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • Outputs are judged by agent-json-equal's reference instead of bit equality: a produced value passes when it accepts it next to the reference's (a lossy encoder, an approximate numeric).
  • A remote call may execute up to 200,000,000 instructions.
  • A new version of agent-openai-request: its reference answers every case of agent-openai-request as it does. Once this and everything it imports are built, it runs in place of agent-openai-request, at the same URL.
  • Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
  • Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.