{
  "version": 1,
  "language": "en",
  "title": "From a tool call to a tool result",
  "description": "Two author-created traces inspect the hypothetical locale cache. A complete tool call executes. A cut-off tool call returns a failure result without executing. Select either trace in this full page.",
  "caption": "Original teaching trace. Playback timing is illustrative, not measured. This model does not specify every product's stop or retry policy.",
  "alt": "Flow diagram of the agent loop: the harness runs accepted tool calls, rejects cut-off ones, and returns both results to the next model call",
  "stateLabels": {
    "proposal": "Tool call",
    "executions": "Completed tool executions",
    "observations": "Recorded tool results",
    "latest": "Latest tool result",
    "next": "Next decision"
  },
  "targets": {
    "infer": {
      "id": "runtime-infer",
      "kind": "node",
      "label": "Call model"
    },
    "check": {
      "id": "runtime-check",
      "kind": "node",
      "label": "Check"
    },
    "execute": {
      "id": "runtime-execute",
      "kind": "node",
      "label": "Execute"
    },
    "observe": {
      "id": "runtime-observe",
      "kind": "node",
      "label": "Record result"
    },
    "reject": {
      "id": "runtime-reject",
      "kind": "node",
      "label": "Reject"
    },
    "proposal": {
      "id": "runtime-proposal",
      "kind": "edge",
      "label": "Submit tool call"
    },
    "accepted": {
      "id": "runtime-accepted",
      "kind": "edge",
      "label": "Accepted tool call"
    },
    "result": {
      "id": "runtime-result",
      "kind": "edge",
      "label": "Completed tool result"
    },
    "rejected": {
      "id": "runtime-rejected",
      "kind": "edge",
      "label": "Reject cut-off tool call"
    },
    "error": {
      "id": "runtime-error",
      "kind": "edge",
      "label": "Return failure result"
    },
    "feedback": {
      "id": "runtime-feedback",
      "kind": "edge",
      "label": "Use the tool result in the next model call"
    }
  },
  "sources": [
    {
      "title": "Original author teaching trace",
      "file": "diagram.svg",
      "sha256": "1e1311facc666bc13e9b7be86451858bbcbfb9fa8a3a03ef938212c84c71fbd8"
    },
    {
      "title": "Pi v0.80.6 execution loop",
      "url": "https://github.com/earendil-works/pi/blob/v0.80.6/packages/agent/src/agent-loop.ts"
    },
    {
      "title": "Article evidence and version ledger",
      "file": "SOURCE.md"
    }
  ],
  "limitations": [
    "The preview-cache task, tool-call outcomes, and tool-result counts are constructed teaching examples.",
    "Playback duration is illustrative and does not measure model or tool latency.",
    "The rejected branch models a cut-off tool call and makes no claim that every error in every tool is free of side effects."
  ],
  "scenarios": [
    {
      "id": "accepted-read",
      "title": "Accepted tool call: inspect the cache",
      "description": "A complete read tool call executes once. Its tool result shows that the current preview lookup uses only document ID.",
      "initial": {
        "proposal": "none",
        "executions": "0",
        "observations": "0",
        "latest": "none",
        "next": "begin inspection"
      },
      "unselected": [
        "reject",
        "rejected",
        "error"
      ],
      "steps": [
        {
          "title": "Produce a read tool call",
          "description": "The model completes one read tool call. No operation has executed yet.",
          "duration": 3000,
          "active": [
            "infer"
          ],
          "paths": [],
          "state": {
            "proposal": "complete read tool call",
            "executions": "0",
            "observations": "0",
            "latest": "none",
            "next": "check the tool call"
          }
        },
        {
          "title": "Accept the complete tool call",
          "description": "After the tool call reaches the check, the harness accepts its completion status and arguments.",
          "duration": 3000,
          "active": [
            "check"
          ],
          "paths": [
            "proposal"
          ],
          "state": {
            "proposal": "accepted read tool call",
            "executions": "0",
            "observations": "0",
            "latest": "none",
            "next": "execute the accepted read"
          }
        },
        {
          "title": "Finish the read operation",
          "description": "The completed execution count changes after the tool call arrives and this illustrative read finishes. A read leaves the file unchanged.",
          "duration": 3000,
          "active": [
            "execute"
          ],
          "paths": [
            "accepted"
          ],
          "state": {
            "proposal": "accepted read tool call",
            "executions": "1",
            "observations": "0",
            "latest": "none",
            "next": "record the tool result"
          }
        },
        {
          "title": "Record the result by tool-call ID",
          "description": "The tool-result count changes when the result reaches the record stage, not while it is in transit.",
          "duration": 3000,
          "active": [
            "observe"
          ],
          "paths": [
            "result"
          ],
          "state": {
            "proposal": "accepted read tool call",
            "executions": "1",
            "observations": "1",
            "latest": "preview lookup uses document.id",
            "next": "interpret the source"
          }
        },
        {
          "title": "Continue with the tool result",
          "description": "The tool result enters the next model call. The task is not yet repaired or tested.",
          "duration": 3000,
          "active": [
            "infer"
          ],
          "paths": [
            "feedback"
          ],
          "state": {
            "proposal": "accepted read tool call",
            "executions": "1",
            "observations": "1",
            "latest": "preview lookup uses document.id",
            "next": "inspect locale input and regression tests"
          }
        }
      ]
    },
    {
      "id": "incomplete-rejected",
      "title": "Cut-off tool call: return an error without execution",
      "description": "The tool call is cut off. This illustrative harness rejects it and records an error. Execution remains zero throughout.",
      "initial": {
        "proposal": "none",
        "executions": "0",
        "observations": "0",
        "latest": "none",
        "next": "begin inspection"
      },
      "unselected": [
        "execute",
        "accepted",
        "result"
      ],
      "steps": [
        {
          "title": "Produce a cut-off tool call",
          "description": "The model response ends before the tool call is complete. Nothing has executed.",
          "duration": 3000,
          "active": [
            "infer"
          ],
          "paths": [],
          "state": {
            "proposal": "cut-off tool call",
            "executions": "0",
            "observations": "0",
            "latest": "none",
            "next": "check completion status"
          }
        },
        {
          "title": "Detect the incomplete response",
          "description": "The completion check chooses the rejected path, even if some recovered arguments could parse.",
          "duration": 3000,
          "active": [
            "check"
          ],
          "paths": [
            "proposal"
          ],
          "state": {
            "proposal": "rejected: incomplete response",
            "executions": "0",
            "observations": "0",
            "latest": "none",
            "next": "skip execution"
          }
        },
        {
          "title": "Skip the operation",
          "description": "No tool is dispatched. The execution count remains zero.",
          "duration": 3000,
          "active": [
            "reject"
          ],
          "paths": [
            "rejected"
          ],
          "state": {
            "proposal": "rejected: incomplete response",
            "executions": "0",
            "observations": "0",
            "latest": "none",
            "next": "return the rejection reason"
          }
        },
        {
          "title": "Record the failure result",
          "description": "An error result arrives without any source read. It says what did not execute.",
          "duration": 3000,
          "active": [
            "observe"
          ],
          "paths": [
            "error"
          ],
          "state": {
            "proposal": "rejected: incomplete response",
            "executions": "0",
            "observations": "1",
            "latest": "cut-off tool call; no tool ran",
            "next": "repair the tool call"
          }
        },
        {
          "title": "Regenerate a complete tool call",
          "description": "The failure reason returns to the next model call. This trace ends before a new tool call or retry executes.",
          "duration": 3000,
          "active": [
            "infer"
          ],
          "paths": [
            "feedback"
          ],
          "state": {
            "proposal": "rejected: incomplete response",
            "executions": "0",
            "observations": "1",
            "latest": "cut-off tool call; no tool ran",
            "next": "generate a complete read tool call"
          }
        }
      ]
    }
  ]
}
