Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-anthropic-responseBuilt by davevia claude-codeRuns on Liberasruns as agent-anthropic-response-2

Anthropic Messages API: response

parse(body): what the model produced, from a Messages API response. The body must be JSON (else "not JSON"); a body whose type is "error" is the error error.message (or "error" when that is not a string); otherwise content must be an array (else "no content"). Walking content in order: a text block appends its text ("a text block without text" when text is not a string); a tool_use block appends a tool call {id, name, arguments: its input as compact JSON with object keys in ascending byte order of their UTF-8 at every level} ("a tool_use block without id" / "… without name" / "… without input" when missing or not a string); any other block (thinking, server tool results, …) is skipped. The result is {text: the texts concatenated, tool-calls}.

Interface (WIT)27 lines›
agent-anthropic-response.wit
package root:component;

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

  export liberas:agent/wire-response@0.1.0;
}
package liberas:agent@0.1.0 {
  interface types {
    record tool-call {
      id: string,
      name: string,
      arguments: string,
    }

    record model-output {
      text: string,
      tool-calls: list<tool-call>,
    }
  }
  interface wire-response {
    use types.{model-output};

    parse: func(body: string) -> result<model-output, string>;
  }
}
Test vectors17›
agent-anthropic-response.cases.json
[
  {
    "args": {
      "body": "{\"id\":\"msg_1\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"text\",\"text\":\"Hello.\"}],\"stop_reason\":\"end_turn\"}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"text\",\"text\":\"Reading \"},{\"type\":\"tool_use\",\"id\":\"toolu_1\",\"name\":\"read-file\",\"input\":{\"path\":\"a\",\"opts\":{\"b\":[1,{\"z\":1,\"a\":2}]}}},{\"type\":\"text\",\"text\":\"now\"}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"thinking\",\"thinking\":\"…\"},{\"type\":\"tool_use\",\"id\":\"toolu_1\",\"name\":\"f\",\"input\":{}}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"error\",\"error\":{\"type\":\"overloaded_error\",\"message\":\"Overloaded\"}}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"error\",\"error\":{\"type\":\"x\"}}"
    }
  },
  {
    "args": {
      "body": "not json at all"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\"}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"tool_use\",\"name\":\"f\",\"input\":{}}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"text\",\"text\":5}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"tool_use\",\"id\":\"t\",\"name\":\"f\",\"input\":\"a string input\"}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"text\",\"text\":\"é\\u0000\"}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"tool_use\",\"id\":\"a\",\"name\":\"f\",\"input\":{\"z\":1,\"a\":[1,2,{\"y\":null,\"b\":\"x\"}]}},{\"type\":\"tool_use\",\"id\":\"b\",\"name\":\"g\",\"input\":{}}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"text\",\"text\":\"one \"},{\"type\":\"text\",\"text\":\"two\"}],\"stop_reason\":\"max_tokens\",\"usage\":{\"input_tokens\":1}}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"tool_use\",\"id\":\"n\",\"name\":\"num\",\"input\":{\"f\":1.5,\"i\":2,\"big\":12345678901234,\"neg\":-0.25,\"e\":1e+21}}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"server_tool_use\",\"id\":\"s\",\"name\":\"web_search\",\"input\":{}},{\"type\":\"web_search_tool_result\",\"tool_use_id\":\"s\",\"content\":[]},{\"type\":\"text\",\"text\":\"found\"}]}"
    }
  },
  {
    "args": {
      "body": "{\"type\":\"message\",\"content\":[{\"type\":\"tool_use\",\"id\":\"u\",\"name\":\"f\",\"input\":{\"키\":\"값\",\"\\\"q\\\"\":\"\\\\\"}}]}"
    }
  }
]
Versions (units)1›
  1. v1by daveac7a8dad35latestconfirmed10/23/2026
Verification7›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 17 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.
  • A remote call may execute up to 200,000,000 instructions.
  • 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%.