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

Context window, with provider turns

A new version of agent-context-2 (it supersedes it): the same rules over messages that may carry extra (ADR 0064). A message costs ceil(UTF-8 bytes of its content / 4) + 4 tokens whatever its tool calls or extra; fit keeps every system message, then the newest of the rest that fit, in their original order, each message exactly as given.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init agent-context-3 --lang rust
cd agent-context-3 && 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)39 lines›
agent-context-3.wit
package root:component;

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

  export liberas:agent/context3@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>,
    }
  }
  interface context3 {
    use types.{message};

    fit: func(messages: list<message>, limit: u32) -> list<message>;

    estimate: func(messages: list<message>) -> u32;
  }
}
Test vectors9›
agent-context-3.cases.json
[
  {
    "fn": "estimate",
    "args": {
      "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
        }
      ]
    }
  },
  {
    "fn": "estimate",
    "args": {
      "messages": [
        {
          "role": "assistant",
          "extra": null,
          "content": "",
          "tool-calls": [
            {
              "id": "1",
              "name": "x",
              "arguments": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
            }
          ],
          "tool-call-id": null
        }
      ]
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 30,
      "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
        }
      ]
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 1000,
      "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
        }
      ]
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 20,
      "messages": [
        {
          "role": "system",
          "content": "sys",
          "tool-call-id": null
        },
        {
          "role": "user",
          "content": "hi",
          "tool-call-id": null
        },
        {
          "role": "user",
          "content": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "tool-call-id": null
        },
        {
          "role": "assistant",
          "content": "a",
          "tool-call-id": null
        },
        {
          "role": "user",
          "content": "b",
          "tool-call-id": null
        }
      ]
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 10,
      "messages": [
        {
          "role": "user",
          "content": "hi",
          "tool-call-id": null
        },
        {
          "role": "system",
          "content": "late system",
          "tool-call-id": null
        },
        {
          "role": "user",
          "content": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          "tool-call-id": null
        }
      ]
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 3,
      "messages": []
    }
  },
  {
    "fn": "fit",
    "args": {
      "limit": 100,
      "messages": [
        {
          "role": "system",
          "content": "s",
          "tool-call-id": null
        },
        {
          "role": "assistant",
          "extra": "[{\"type\":\"thinking\",\"thinking\":\"The file first.\",\"signature\":\"sig-1\"},{\"type\":\"text\",\"text\":\"Reading.\"},{\"type\":\"tool_use\",\"id\":\"c1\",\"name\":\"read-file\",\"input\":{\"path\":\"a\"}}]",
          "content": "Reading.",
          "tool-calls": [
            {
              "id": "c1",
              "name": "read-file",
              "arguments": "{\"path\":\"a\"}"
            }
          ],
          "tool-call-id": null
        },
        {
          "role": "tool",
          "content": "alpha",
          "tool-call-id": "c1"
        }
      ]
    }
  },
  {
    "fn": "estimate",
    "args": {
      "messages": [
        {
          "role": "assistant",
          "extra": "[{\"type\":\"thinking\",\"thinking\":\"The file first.\",\"signature\":\"sig-1\"},{\"type\":\"text\",\"text\":\"Reading.\"},{\"type\":\"tool_use\",\"id\":\"c1\",\"name\":\"read-file\",\"input\":{\"path\":\"a\"}}]",
          "content": "",
          "tool-calls": [],
          "tool-call-id": null
        }
      ]
    }
  }
]
Versions (units)1›
  1. v1by davefe281e0216stable 5.1.0latestconfirmed10/23/2026
Verification8›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 9 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.
  • A new version of agent-context-2: its reference answers every case of agent-context-2 as it does. Once this and everything it imports are built, it runs in place of agent-context-2, 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%.