aiml
SearchMy learning
Menu

Lesson 24 of 36Module 9

Bound scripted retrieval runs

Admit tool actions before spending source-read allowance

Bound a scripted retrieval run with action and source-byte admission checks, retain denied and failed attempts, and separate limits from task completion.

Prerequisites

Python dictionaries and JSON; versioned passages, lexical retrieval and source identity.

By the end, you can

  • Reserve action counts and UTF-8 source-text bytes before tool invocation.
  • Keep denied calls separate from admitted attempts that fail.
  • Explain what action limits leave outside their scope.
Runtime
Python 3.11+; SQLite with FTS5
Dependencies
Standard library only; no provider SDK or model download

Lab code, tests and fixtures (ZIP, 1.8 MB)Quiz check your understanding

Progress is saved in this browser.

Put an admission gate around the local retrieval loop. Before each requested tool operation, the gate checks whether it fits the configured action counts and source-text allowance. A valid action can still be denied, and an admitted action can still fail.

When you need this. Use admission checks when a policy can request another search or read and the caller must bound those operations before they happen.

The controller here is the declared offline question-rule policy. No model agent ran. Its source-byte allowance counts requested read-text UTF-8 bytes; it is neither a model-token budget nor a measurement of inference spend.

Requested tool actionWithinbudgets?Invoke admitted toolCounters + tool traceLimited terminal stateRefused action not calledactionadmitresult or errorsuccess: nextdenyTool failureNo next actionerrordata flowreturnfailure
The local runner checks counters and planned excerpt bytes before invoking each requested tool action. Successful calls can continue after updating the trace; tool failure stops the run. Exhausted limits terminate without the refused call.

Check the next action before calling the tool

Limits holds allowances for all admitted steps, searches, reads and source bytes. Its explicit constructor checks reject invalid types and values. A type annotation alone would not validate a supplied number.

The runner first validates an action’s tool name and argument shape. Search costs no source-body bytes under this contract. For a read, preflight checks its issued handle and obtains the expected byte count from metadata. It does not invoke the read to learn its cost.

The runner compares the proposed counters with every allowance. If a limit would be exceeded, the result is limited and the trace records a denied action with invoked: false. This ordering is the mechanism: reading first and counting afterwards cannot prevent that read.

Count admitted attempts even when they fail

An admitted operation reserves its step, tool-type count and planned source bytes before invocation. A tool error does not reset those counters. Otherwise a faulty tool could fail repeatedly while appearing never to consume its allowance.

Returned read text is validated against the authoritative handle-bound payload. Validated delivered bytes are recorded separately from reserved bytes. A changed payload fails validation and cannot be used as retrieved source text. Repeating the exact same action is also refused, while a new query remains a distinct action subject to the remaining budgets.

Invalid limits. Booleans, negative values and values outside the supported caps are rejected during configuration. Denied call. A valid next action that would cross a configured allowance is recorded without invoking that tool. Tool failure. The controlled fault happens after an actual local search and remains an admitted failed attempt.

Inspect each terminal state and its counters

The normal local fixture, each restricted allowance and the deliberate tool fault use the same pinned corpus and question. Controller status describes execution: completed means the policy returned no further action, limited means admission refused an action, and failed means validation, policy or tool execution failed. Inspect the policy’s own stop reason separately; no terminal state grades an answer.

Configured caseController statusReasonAdmitted stepsReserved source bytesValidated delivered bytes
within_limitscompletedpolicy_complete4378378
step_limitlimitedmax_steps2154154
search_limitlimitedmax_searches2154154
read_limitlimitedmax_reads3154154
source_byte_limitlimitedmax_source_bytes3154154

The fault’s actual reason is RuntimeError: controlled_after_search_fault. Its raw trace retains the attempted operation. A deliberately injected error illustrates this accounting rule; it is not an observed service failure rate.

Execute the bounded local runner

Download the retrieval-limits lab. The package includes the runner, scripted policy, exact search/read implementation, fixed corpus and independently executable failure tests.

limits.pySource · pythonDownload
"""Admission limits for an offline scripted tool controller, not a model agent."""
import copy
from dataclasses import asdict,dataclass
import json
import re


@dataclass(frozen=True)
class Limits:
    max_steps:int=6
    max_searches:int=2
    max_reads:int=2
    max_source_bytes:int=4096

    def __post_init__(self):
        for key,value in asdict(self).items():
            maximum=16_777_216 if key=='max_source_bytes' else 100
            if type(value) is not int or not 0<=value<=maximum:raise ValueError('invalid_'+key)


def action_cost(tools,action):
    if not isinstance(action,dict) or set(action)!={'tool','arguments'}:raise ValueError('invalid_action_schema')
    tool=action['tool'];arguments=action['arguments']
    if not isinstance(tool,str) or tool not in ('search','read'):raise ValueError('unknown_tool')
    if not isinstance(arguments,dict):raise ValueError('invalid_arguments')
    if tool=='search':
        if not {'query','version'}<=set(arguments) or set(arguments)-{'query','version','k'}:raise ValueError('invalid_search_arguments')
        if not isinstance(arguments['query'],str) or re.fullmatch(r'[A-Za-z0-9]{1,64}',arguments['query']) is None:raise ValueError('invalid_search_query')
        if not isinstance(arguments['version'],str) or re.fullmatch(r'[0-9]+\.[0-9]+',arguments['version']) is None:raise ValueError('invalid_search_version')
        if type(arguments.get('k',2)) is not int or not 1<=arguments.get('k',2)<=10:raise ValueError('invalid_search_k')
        return 0
    if set(arguments)!={'handle'} or not isinstance(arguments['handle'],dict):raise ValueError('invalid_read_arguments')
    cost=tools.read_cost(arguments['handle'])
    if type(cost) is not int or cost<0:raise ValueError('invalid_read_cost')
    return cost


def run_limited(tools,policy,limits=Limits()):
    """Validate, reserve, then invoke. Corpus setup is outside these counters."""
    if not isinstance(limits,Limits):raise ValueError('invalid_limits')
    usage={'steps':0,'searches':0,'reads':0,'reserved_source_bytes':0,'delivered_source_bytes':0}
    observations=[];trace=[];seen=set()
    status='completed';reason='policy_complete'
    while True:
        try:
            action=policy(copy.deepcopy(observations))
            if action is None:break
            cost=action_cost(tools,action)
            canonical=copy.deepcopy(action)
            if action['tool']=='search':canonical['arguments']={'query':action['arguments']['query'].lower(),'version':action['arguments']['version'],'k':action['arguments'].get('k',2)}
            fingerprint=json.dumps(canonical,sort_keys=True,separators=(',',':'),allow_nan=False)
            if fingerprint in seen:raise ValueError('repeated_action')
        except Exception as error:
            status='failed';reason=type(error).__name__+': '+str(error)
            trace.append({'decision':'refused','reason':reason,'invoked':False});break
        tool=action['tool']
        checks=[('max_steps',usage['steps']+1,limits.max_steps),('max_searches',usage['searches']+(tool=='search'),limits.max_searches),('max_reads',usage['reads']+(tool=='read'),limits.max_reads),('max_source_bytes',usage['reserved_source_bytes']+cost,limits.max_source_bytes)]
        denied=next((name for name,requested,maximum in checks if requested>maximum),None)
        if denied:
            status='limited';reason=denied
            trace.append({'action':copy.deepcopy(action),'decision':'denied','reason':denied,'invoked':False,'preflight_source_bytes':cost});break
        seen.add(fingerprint)
        usage['steps']+=1;usage['searches']+=int(tool=='search');usage['reads']+=int(tool=='read');usage['reserved_source_bytes']+=cost
        event={'action':copy.deepcopy(action),'decision':'executed','invoked':True,'reserved_source_bytes':cost}
        try:
            result=tools.search(**action['arguments']) if tool=='search' else tools.read(action['arguments']['handle'])
            if tool=='read':
                result=tools.validate_read(result,action['arguments']['handle'])
                if not isinstance(result,dict) or not isinstance(result.get('text'),str):raise ValueError('invalid_read_result')
                received=len(result['text'].encode('utf-8'));usage['delivered_source_bytes']+=received
                if received!=cost:raise ValueError('read_size_contract_changed')
            event['status']='succeeded';event['result']=copy.deepcopy(result)
            observations.append({'tool':tool,'arguments':copy.deepcopy(action['arguments']),'result':copy.deepcopy(result)})
        except Exception as error:
            status='failed';reason=type(error).__name__+': '+str(error)
            event['status']='failed';event['reason']=reason
        event['usage_after']=dict(usage);trace.append(event)
        if status=='failed':break
    return {'controller_status':status,'terminal_reason':reason,'limits':asdict(limits),'usage':usage,'trace':trace,'observations':observations,'scope':'Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens.'}
Run the admission checksTerminal · bash
python run.py --output scratch-result.json
python -m unittest discover -v
Saved CLI outputRecorded output · jsonDownload
{
  "cases": {
    "read_limit": "limited",
    "search_limit": "limited",
    "source_byte_limit": "limited",
    "step_limit": "limited",
    "within_limits": "completed"
  },
  "execution_mode": "offline-scripted-controller-limits",
  "model_called": false
}

This program is a local CLI with in-memory counters. Corpus loading and index construction occur before the action loop. Policy-callback computation, process memory, disk I/O, model tokens and wall-clock execution are outside these limits. A blocked callback needs an execution timeout or process boundary; a step counter cannot interrupt it. No HTTP deployment, concurrency admission or cancellation integration was measured.

View the complete local execution JSON
Actual offline execution recordRecorded output · jsonDownload
{
  "execution_mode": "offline-scripted-controller-limits",
  "model_called": false,
  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
  "question": "Will write_text replace the contents of an existing file?",
  "version": "3.12",
  "cases": [
    {
      "case_id": "within_limits",
      "policy_terminal_status": "completed",
      "policy_reason": "configured_context_marker_found",
      "result": {
        "controller_status": "completed",
        "terminal_reason": "policy_complete",
        "limits": {
          "max_steps": 6,
          "max_searches": 2,
          "max_reads": 2,
          "max_source_bytes": 4096
        },
        "usage": {
          "steps": 4,
          "searches": 2,
          "reads": 2,
          "reserved_source_bytes": 378,
          "delivered_source_bytes": 378
        },
        "trace": [
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "text",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            },
            "usage_after": {
              "steps": 1,
              "searches": 1,
              "reads": 0,
              "reserved_source_bytes": 0,
              "delivered_source_bytes": 0
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 154,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            },
            "usage_after": {
              "steps": 2,
              "searches": 1,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "overwritten",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            },
            "usage_after": {
              "steps": 3,
              "searches": 2,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 224,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
              "source_id": "path-write",
              "version": "3.12",
              "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
              "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
              "byte_count": 224,
              "native_score": -0.7992166451067193,
              "rank": 1,
              "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75",
              "text": "Path.write_text(data, encoding=None, errors=None, newline=None) writes text to a file and closes it. Set encoding=\"utf-8\" to select UTF-8. An existing file is overwritten. The method returns the number of characters written.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.write_text",
              "read_request_id": "a9ec642e4ed3206ac85e5dd03d4de9ff57de3167e134079eafe4a31de23cec67",
              "result_sha256": "662c96d3b972224ac1549f9a6c3ad495b3ed885b6db477d52aeb7527ec1dbbb7"
            },
            "usage_after": {
              "steps": 4,
              "searches": 2,
              "reads": 2,
              "reserved_source_bytes": 378,
              "delivered_source_bytes": 378
            }
          }
        ],
        "observations": [
          {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                "source_id": "path-read",
                "version": "3.12",
                "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "byte_count": 154,
                "native_score": -1.4220532319391636e-06,
                "rank": 1,
                "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            }
          },
          {
            "tool": "search",
            "arguments": {
              "query": "overwritten",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                "source_id": "path-write",
                "version": "3.12",
                "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                "byte_count": 224,
                "native_score": -0.7992166451067193,
                "rank": 1,
                "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
              "source_id": "path-write",
              "version": "3.12",
              "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
              "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
              "byte_count": 224,
              "native_score": -0.7992166451067193,
              "rank": 1,
              "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75",
              "text": "Path.write_text(data, encoding=None, errors=None, newline=None) writes text to a file and closes it. Set encoding=\"utf-8\" to select UTF-8. An existing file is overwritten. The method returns the number of characters written.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.write_text",
              "read_request_id": "a9ec642e4ed3206ac85e5dd03d4de9ff57de3167e134079eafe4a31de23cec67",
              "result_sha256": "662c96d3b972224ac1549f9a6c3ad495b3ed885b6db477d52aeb7527ec1dbbb7"
            }
          }
        ],
        "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
      }
    },
    {
      "case_id": "step_limit",
      "policy_terminal_status": null,
      "policy_reason": null,
      "result": {
        "controller_status": "limited",
        "terminal_reason": "max_steps",
        "limits": {
          "max_steps": 2,
          "max_searches": 2,
          "max_reads": 2,
          "max_source_bytes": 4096
        },
        "usage": {
          "steps": 2,
          "searches": 1,
          "reads": 1,
          "reserved_source_bytes": 154,
          "delivered_source_bytes": 154
        },
        "trace": [
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "text",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            },
            "usage_after": {
              "steps": 1,
              "searches": 1,
              "reads": 0,
              "reserved_source_bytes": 0,
              "delivered_source_bytes": 0
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 154,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            },
            "usage_after": {
              "steps": 2,
              "searches": 1,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "overwritten",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "denied",
            "reason": "max_steps",
            "invoked": false,
            "preflight_source_bytes": 0
          }
        ],
        "observations": [
          {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                "source_id": "path-read",
                "version": "3.12",
                "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "byte_count": 154,
                "native_score": -1.4220532319391636e-06,
                "rank": 1,
                "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            }
          }
        ],
        "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
      }
    },
    {
      "case_id": "search_limit",
      "policy_terminal_status": null,
      "policy_reason": null,
      "result": {
        "controller_status": "limited",
        "terminal_reason": "max_searches",
        "limits": {
          "max_steps": 6,
          "max_searches": 1,
          "max_reads": 2,
          "max_source_bytes": 4096
        },
        "usage": {
          "steps": 2,
          "searches": 1,
          "reads": 1,
          "reserved_source_bytes": 154,
          "delivered_source_bytes": 154
        },
        "trace": [
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "text",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            },
            "usage_after": {
              "steps": 1,
              "searches": 1,
              "reads": 0,
              "reserved_source_bytes": 0,
              "delivered_source_bytes": 0
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 154,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            },
            "usage_after": {
              "steps": 2,
              "searches": 1,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "overwritten",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "denied",
            "reason": "max_searches",
            "invoked": false,
            "preflight_source_bytes": 0
          }
        ],
        "observations": [
          {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                "source_id": "path-read",
                "version": "3.12",
                "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "byte_count": 154,
                "native_score": -1.4220532319391636e-06,
                "rank": 1,
                "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            }
          }
        ],
        "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
      }
    },
    {
      "case_id": "read_limit",
      "policy_terminal_status": null,
      "policy_reason": null,
      "result": {
        "controller_status": "limited",
        "terminal_reason": "max_reads",
        "limits": {
          "max_steps": 6,
          "max_searches": 2,
          "max_reads": 1,
          "max_source_bytes": 4096
        },
        "usage": {
          "steps": 3,
          "searches": 2,
          "reads": 1,
          "reserved_source_bytes": 154,
          "delivered_source_bytes": 154
        },
        "trace": [
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "text",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            },
            "usage_after": {
              "steps": 1,
              "searches": 1,
              "reads": 0,
              "reserved_source_bytes": 0,
              "delivered_source_bytes": 0
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 154,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            },
            "usage_after": {
              "steps": 2,
              "searches": 1,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "overwritten",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            },
            "usage_after": {
              "steps": 3,
              "searches": 2,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              }
            },
            "decision": "denied",
            "reason": "max_reads",
            "invoked": false,
            "preflight_source_bytes": 224
          }
        ],
        "observations": [
          {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                "source_id": "path-read",
                "version": "3.12",
                "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "byte_count": 154,
                "native_score": -1.4220532319391636e-06,
                "rank": 1,
                "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            }
          },
          {
            "tool": "search",
            "arguments": {
              "query": "overwritten",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            }
          }
        ],
        "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
      }
    },
    {
      "case_id": "source_byte_limit",
      "policy_terminal_status": null,
      "policy_reason": null,
      "result": {
        "controller_status": "limited",
        "terminal_reason": "max_source_bytes",
        "limits": {
          "max_steps": 6,
          "max_searches": 2,
          "max_reads": 2,
          "max_source_bytes": 200
        },
        "usage": {
          "steps": 3,
          "searches": 2,
          "reads": 1,
          "reserved_source_bytes": 154,
          "delivered_source_bytes": 154
        },
        "trace": [
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "text",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            },
            "usage_after": {
              "steps": 1,
              "searches": 1,
              "reads": 0,
              "reserved_source_bytes": 0,
              "delivered_source_bytes": 0
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                }
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 154,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            },
            "usage_after": {
              "steps": 2,
              "searches": 1,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "search",
              "arguments": {
                "query": "overwritten",
                "version": "3.12",
                "k": 2
              }
            },
            "decision": "executed",
            "invoked": true,
            "reserved_source_bytes": 0,
            "status": "succeeded",
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            },
            "usage_after": {
              "steps": 3,
              "searches": 2,
              "reads": 1,
              "reserved_source_bytes": 154,
              "delivered_source_bytes": 154
            }
          },
          {
            "action": {
              "tool": "read",
              "arguments": {
                "handle": {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              }
            },
            "decision": "denied",
            "reason": "max_source_bytes",
            "invoked": false,
            "preflight_source_bytes": 224
          }
        ],
        "observations": [
          {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "query": "text",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                  "source_id": "path-read",
                  "version": "3.12",
                  "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                  "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                  "byte_count": 154,
                  "native_score": -1.4220532319391636e-06,
                  "rank": 1,
                  "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
                },
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -1.320388349514563e-06,
                  "rank": 2,
                  "read_token": "397d6f236743e576b50940b06d3df84a0712dc67157f5efdeb544448555729f1"
                }
              ]
            }
          },
          {
            "tool": "read",
            "arguments": {
              "handle": {
                "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
                "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
                "source_id": "path-read",
                "version": "3.12",
                "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
                "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "start_line": 1,
                "end_line": 1,
                "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
                "byte_count": 154,
                "native_score": -1.4220532319391636e-06,
                "rank": 1,
                "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124"
              }
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "3f33383e706e36449e22c380704d880d5e2b8a4b1f6b779b8aa54206e072ad5f",
              "passage_id": "c737db948e8111ae00e3442d8a22c80c876e43446dc1ee176ffe8ce142a41900",
              "source_id": "path-read",
              "version": "3.12",
              "document_revision": "b58385b9bf597a951c16c035653d639929924e53eae3e5ada255afd6ee1592f2",
              "source_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "start_line": 1,
              "end_line": 1,
              "text_sha256": "dc097ca63486ace45279f412ea266bf754fcd2f0b1153f5d763ce905dafbc2c0",
              "byte_count": 154,
              "native_score": -1.4220532319391636e-06,
              "rank": 1,
              "read_token": "72abbf5e0022ef780447ed8c2322b711cac8b4971d817a440bc02dfa28b07124",
              "text": "Path.read_text(encoding=None, errors=None) opens a file, returns its text as a string and closes the file. Set encoding=\"utf-8\" when reading a UTF-8 file.",
              "url": "https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.read_text",
              "read_request_id": "b2ce4d1e809a197df6c864261264b583737b1f41c59f8a4b6e353911b84c5bfe",
              "result_sha256": "2d855cfa0b4f7e90c3711783b7779709f3b964760fd789d0d65b11f9b3604ac5"
            }
          },
          {
            "tool": "search",
            "arguments": {
              "query": "overwritten",
              "version": "3.12",
              "k": 2
            },
            "result": {
              "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
              "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
              "query": "overwritten",
              "version": "3.12",
              "k": 2,
              "results": [
                {
                  "corpus_id": "0615d22a3315e97c0a88c6c566c546877304f5a28a97e83f68dd36881d4bbd0e",
                  "search_request_id": "aeffc68efdee46b8d23c597f651143424c575c0c1a4699ab08a48734d011f127",
                  "passage_id": "c66643a4609c6ee157458bf4353f7446b9c6a200a3ef453846d6a18d5b5069a7",
                  "source_id": "path-write",
                  "version": "3.12",
                  "document_revision": "28c6349eaf80b629322edb310bb871dc45a04af9fad3b752bc75d12f0d7314e7",
                  "source_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "start_line": 1,
                  "end_line": 1,
                  "text_sha256": "a48b4b9f763cd6309ebe32af19c5a814adcf810c2259683da9f328ccee46948e",
                  "byte_count": 224,
                  "native_score": -0.7992166451067193,
                  "rank": 1,
                  "read_token": "08b866d8cf00533f3484aac4d78ac512bd4df8767c9ea11fbd2e817eeeb1dd75"
                }
              ]
            }
          }
        ],
        "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
      }
    }
  ],
  "controlled_tool_failure": {
    "scope": "deliberate fault after actual local search; not a reliability measurement",
    "result": {
      "controller_status": "failed",
      "terminal_reason": "RuntimeError: controlled_after_search_fault",
      "limits": {
        "max_steps": 6,
        "max_searches": 2,
        "max_reads": 2,
        "max_source_bytes": 4096
      },
      "usage": {
        "steps": 1,
        "searches": 1,
        "reads": 0,
        "reserved_source_bytes": 0,
        "delivered_source_bytes": 0
      },
      "trace": [
        {
          "action": {
            "tool": "search",
            "arguments": {
              "query": "text",
              "version": "3.12",
              "k": 2
            }
          },
          "decision": "executed",
          "invoked": true,
          "reserved_source_bytes": 0,
          "status": "failed",
          "reason": "RuntimeError: controlled_after_search_fault",
          "usage_after": {
            "steps": 1,
            "searches": 1,
            "reads": 0,
            "reserved_source_bytes": 0,
            "delivered_source_bytes": 0
          }
        }
      ],
      "observations": [],
      "scope": "Offline scripted tool policy. Corpus initialization is outside action counters. Source bytes are reserved read-text UTF-8 bytes, not disk I/O or model tokens."
    }
  },
  "limit": "Counts cover admitted tool attempts and validated read-text bytes. Corpus initialization, policy callback computation, wall time, model tokens and inference costs are outside this contract. No model agent or generated answer."
}

The CLI summary distinguishes the completed normal run from four limited runs. The full JSON also retains the controlled tool failure and its admitted-attempt counters.

Verify that a denied action never ran

Compare the step-limited trace with the normal trace. Locate the last admitted operation and the next denied action. Confirm that the denied action has no successful observation and did not increment the admitted counters. Then inspect the controlled tool failure and explain why its admitted search still consumes a step.

The next valid read would exceed the remaining source-byte allowance. What should this runner do?

Choose one answer, then check your reasoning.

Read the explanation

The budget covers admitted tool actions and reserved read-text bytes, not process memory or wall-clock execution.

What’s next

Continue with Compare Agents and Pipelines.

References

Python dataclasses, checked on 23 October 2026, describes generated methods and the limits of annotation and frozen-instance behavior. The explicit validation and admission rules are implemented in this lab. Python unittest documents the assertion mechanisms used to check refused configurations and tool failures; passing those checks does not measure service reliability.

Written by Arjun Prabhulal.

Module 9

Bounded retrieval policies