<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc [
  <!ENTITY nbsp "&#160;">
  <!ENTITY zwsp "&#8203;">
  <!ENTITY nbhy "&#8209;">
  <!ENTITY wj   "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     docName="draft-song-anp-aitp-00"
     category="exp"
     ipr="trust200902"
     submissionType="independent"
     xml:lang="en"
     version="3">

  <front>
    <title abbrev="AITP">Agent Invocation Transport Protocol (AITP)</title>

    <seriesInfo name="Internet-Draft" value="draft-song-anp-aitp-00"/>

    <author fullname="Jinke Song" initials="J." surname="Song">
      <organization abbrev="HKUST">Dept. of CSE, Hong Kong University of Science and Technology</organization>
      <address>
        <email>ink@chatchat.space</email>
      </address>
    </author>

    <author fullname="Mu Yuan" initials="M." surname="Yuan">
      <organization abbrev="CUHK">Dept. of IE, The Chinese University of Hong Kong</organization>
      <address>
        <email>muyuan@cuhk.edu.hk</email>
      </address>
    </author>

    <date year="2026" month="March" day="25"/>

    <area>art</area>
    <workgroup>Independent Submission</workgroup>

    <keyword>agent</keyword>
    <keyword>invocation</keyword>
    <keyword>transport</keyword>
    <keyword>streaming</keyword>

    <abstract>
      <t>
        The Agent Internet Protocol (AIP) provides best-effort,
        name-based datagram delivery between autonomous AI agents
        identified by agent:// URIs.  The Agent Invocation Transport
        Protocol (AITP) is a message-framed invocation and streaming
        transport above AIP.
      </t>
      <t>
        Unlike traditional host-to-host transports (TCP, QUIC) that
        operate on socket endpoints and byte streams, AITP is natively
        message-framed, method-aware, and association-aware: its
        header carries a method name as a first-class field, and its
        protocol data units are discrete requests, responses, stream
        chunks, and control segments exchanged between named agents.
        AITP is not a byte-stream transport; it is an agent-native
        invocation and streaming transport that carries method names,
        request/response correlation, flow control, and session
        semantics natively in its header — so that upper-layer agent
        protocols need not reinvent them.  AITP intentionally includes
        a minimal generic invocation outcome space (four dispatch-
        level status codes); richer application semantics belong in
        the response body or upper-layer protocols.
      </t>
      <t>
        Unlike transport bindings that adapt existing agent protocols
        to HTTP, gRPC, or MOQT, AITP defines a common invocation
        substrate directly above AIP, with association state,
        request-concurrency flow control, and method-aware framing
        as first-class transport concerns.
      </t>
      <t>
        AITP is best understood as a common invocation substrate
        above AIP, not as a byte-stream transport analogue.
      </t>
      <t>
        This document specifies the AITP segment format, segment types,
        status codes, flag bits, TLV options, association state machine,
        reliability engine, flow control, circuit-breaker mechanism,
        streaming, orderly close and abort, and interfaces to AIP below
        and application protocols above.
      </t>
    </abstract>
  </front>

  <middle>

    <!-- ============================================================ -->
    <!--  SECTION 1 — INTRODUCTION                                     -->
    <!-- ============================================================ -->

    <section anchor="introduction">
      <name>Introduction</name>

      <section anchor="problem-statement">
        <name>Problem Statement</name>
        <t>
          AIP <xref target="I-D.song-anp-aip"/> provides a best-effort
          datagram service between agents identified by agent:// URIs:
          messages may be lost, duplicated, or reordered.  Agent
          applications -- remote procedure calls, streaming inference,
          multi-turn conversations -- require reliable delivery with
          request-response correlation.
        </t>
        <t>
          Existing host-to-host transports (TCP, QUIC) solve this
          problem for processes bound to IP addresses and ports.  They
          provide reliable byte streams or datagrams between network
          endpoints, but they have no notion of agent:// addressing,
          association semantics between named agents, or message-level
          request/response framing.  Using such transports directly
          forces every upper-layer agent protocol (task orchestration,
          knowledge replication, capability advertisement) to
          independently reinvent request IDs, timeouts, retransmission,
          flow control, and orderly close.
        </t>
        <t>
          AITP bridges this gap.  It is an agent-to-agent transport, not
          a host-to-host transport: its endpoints are agent:// URIs,
          its protocol data unit is a self-framed message (not a byte
          stream), and its association state tracks agent conversations
          rather than network connections.  AITP accepts AIP datagrams
          carrying Protocol = 1 and provides upper-layer protocols with
          synchronous invocation, fire-and-forget messaging, and bidirectional
          streaming, all mediated through per-agent association state
          with request-concurrency flow control (counted in outstanding
          requests, not bytes) and circuit-breaker fault isolation.
        </t>
      </section>

      <section anchor="scope">
        <name>Scope</name>
        <t>
          This document is one of four core Internet-Drafts in
          the Agent Network Protocol (ANP) suite: AIP
          <xref target="I-D.song-anp-aip"/> (datagram
          delivery), AITP (this document, invocation transport),
          ANS <xref target="I-D.song-anp-ans"/> (name system),
          and ADP <xref target="I-D.song-anp-adp"/> (description
          and discovery).  The four drafts are designed to
          co-evolve as a self-contained protocol suite; no
          additional specification is required for baseline
          interoperability.  AIP's local-resolver semantic
          extension <bcp14>MAY</bcp14> be backed by an
          implementation that consults ADP discovery services
          for ranked capability matching; ANS core provides
          name-to-peer binding but does not itself perform
          ranked semantic discovery.
        </t>
        <t>
          AITP defines an experimental, lightweight invocation
          and streaming transport above AIP
          <xref target="I-D.song-anp-aip"/>, intended for
          implementation and operational experimentation.
        </t>
        <t>
          In one sentence: AIP delivers datagrams to agents; AITP
          provides a common invocation and streaming substrate on
          which those agents converse.
        </t>
        <t>AITP is responsible for:</t>
        <ol>
          <li>Association lifecycle -- establish, maintain, orderly
              close, and abort.</li>
          <li>Request/response exchange with correlation by
              Request ID.</li>
          <li>Fire-and-forget one-way messaging (NOACK flag).</li>
          <li>Bidirectional streaming with FIN-based termination.</li>
          <li>Status codes for transport-level outcomes and
              minimal handler-dispatch outcomes needed for generic
              interoperability.</li>
          <li>Retransmission with exponential-backoff timeout and
              deduplication of retransmitted requests.</li>
          <li>Receiver-advertised flow control via the Window
              field.</li>
          <li>Per-association circuit breaker for fault
              isolation.</li>
          <li>Extensible TLV options for timeout, sequencing,
              timestamps, signatures, and metadata.</li>
        </ol>
        <t>AITP is NOT responsible for:</t>
        <ol>
          <li>Naming, resolution, or agent discovery -- these belong
              to AIP and the Agent Name System (ANS).</li>
          <li>Addressing and forwarding -- these belong to AIP.</li>
          <li>End-to-end business semantics, task orchestration, or
              agent workflow -- these belong to upper-layer application
              protocols.</li>
          <li>Economic settlement or credit systems.</li>
          <li>Knowledge synchronisation or replication.</li>
          <li>A general identity or authentication framework -- AITP
              provides optional segment-level signatures (SIGNED flag)
              and defers to AIP and deployment-context mechanisms for
              identity binding.</li>
          <li>Payload confidentiality or end-to-end encryption --
              these are application-layer responsibilities.</li>
          <li>Message fragmentation -- AITP relies on AIP's maximum
              message size (65535 octets).</li>
        </ol>
        <t>
          Accordingly, this document does not specify a complete agent
          runtime, workflow engine, business protocol family, or
          deployment profile; it defines only the common invocation
          and streaming substrate shared by such systems.
        </t>
        <t>
          Because AITP carries a Method name as a first-class header
          field and defines minimal handler-dispatch status codes,
          it is not a pure transport in the TCP/QUIC sense.  It is
          an agent-native invocation transport that unifies method
          dispatch, request/response correlation, retry, flow
          control, and session management into a shared substrate
          so that multiple upper-layer agent protocols (ADP, task
          orchestration, capability advertisement, knowledge sync,
          and future agent message families) need not independently
          reinvent these mechanics.  AITP is best understood as a
          common invocation substrate above AIP, rather than as a
          byte-stream transport analogue.
        </t>
      </section>

      <section anchor="relation-existing">
        <name>Relationship to Existing Transport Protocols</name>
        <t>
          A natural question is: "Why not use QUIC streams with gRPC,
          or libp2p streams with a custom RPC layer?"  This section
          explains why AITP occupies a distinct position in the
          protocol stack.
        </t>

        <section anchor="rel-abstraction">
          <name>Different Abstraction Objects</name>
          <t>
            TCP and QUIC are host-to-host (or process-to-process)
            transports.  Their endpoints are IP addresses and ports;
            their primary abstraction is the connection or stream
            between network endpoints.  They do not understand
            agent:// URIs, resolver-assisted delivery, or agent
            association semantics.
          </t>
          <t>
            AITP is an agent-to-agent transport.  Its endpoints are
            agent:// URIs; its primary abstraction is the association
            between named agents.  An association carries not just
            connectivity state, but also request correlation, flow
            control windows counted in outstanding requests (not
            bytes), and a circuit breaker reflecting the remote
            agent's operational health -- concepts that have no
            direct counterpart in traditional transport protocols.
          </t>
        </section>

        <section anchor="rel-framing">
          <name>Message-Framed, Not Byte-Stream</name>
          <t>
            TCP provides an unstructured byte stream; applications
            must impose their own framing.  QUIC improves on this
            with multiple streams but remains byte-oriented within
            each stream.
          </t>
          <t>
            AITP is natively message-framed.  Every segment is a
            self-contained protocol data unit with a typed header,
            request ID, method name, status code, and body.  The
            transport itself understands "this is a request", "this
            is a response", "this is a stream chunk", and "this is
            a control message" -- eliminating the need for upper-layer
            protocols to define their own framing and multiplexing.
          </t>
        </section>

        <section anchor="rel-complementary">
          <name>Complementary Layering</name>
          <t>
            AITP does not compete with TCP or QUIC for the same layer.
            The correct relationship is:
          </t>
          <artwork type="ascii-art"><![CDATA[
  Upper-layer protocols   ADP, task, knowledge, capability, ...
  ─────────────────────────────────────────────────────────────
  AITP                     agent-to-agent invocation & streaming
  ─────────────────────────────────────────────────────────────
  AIP                     agent:// datagram substrate
  ─────────────────────────────────────────────────────────────
  Link / Network          libp2p over TCP, QUIC, WebSocket, ...
]]></artwork>
          <t>
            Traditional transports provide network reachability and
            basic reliable delivery at the link/network layer.  AIP
            provides agent-oriented, name-based datagram delivery
            above that.  AITP provides reliable invocation and
            streaming semantics above AIP.  Each layer has a distinct
            job; removing any one forces its responsibilities onto an
            adjacent layer.
          </t>
          <t>
            AITP does not replace lower-layer transports such as TCP
            or QUIC; it defines a reusable invocation substrate for
            agent://-addressed communication above AIP.
          </t>
        </section>
      </section>

      <section anchor="positioning-agent-approaches">
        <name>Positioning Among Agent Communication Approaches</name>

        <t>
          The preceding section distinguishes AITP from host-to-host
          transports.  This section clarifies its relationship to
          agent-oriented communication approaches that operate at
          different layers of the stack.
        </t>

        <t>
          Several agent protocol families (e.g., A2A) define
          application-level messaging semantics — task lifecycle,
          capability exchange, content negotiation — and then bind
          those semantics onto existing transports such as HTTP or
          gRPC.  AITP does not define application semantics.  It
          occupies a lower position: a reusable invocation and
          streaming substrate above AIP, designed to be shared by
          multiple upper-layer agent protocols rather than serving
          one particular protocol family.
        </t>

        <t>
          Client-server agent transports such as MCP's stdio and
          Streamable HTTP provide carriage for JSON-RPC exchanges
          between a client and a server, inheriting session and
          flow-control semantics from the underlying transport or
          runtime environment.  AITP targets symmetric agent-to-agent
          exchanges between agent://-identified endpoints; association
          state and request-concurrency control are defined within
          the protocol itself rather than inherited from an underlying
          HTTP or process-level session.
        </t>

        <t>
          Deployment platforms and runtime messaging fabrics may
          provide routing, streaming, or orchestration facilities
          for agents.  AITP does not attempt to standardize such
          systems.  It specifies a protocol-layer invocation substrate
          that can be implemented independently of any particular
          runtime while remaining reusable across agent-oriented
          application protocols built above AIP.
        </t>
      </section>

      <section anchor="interop-model">
        <name>Interoperability Model</name>
        <t>
          This section summarizes the minimum requirements for
          implementing an AITP endpoint, achieving two-party
          interoperability, and distinguishing core protocol
          behaviour from optimization profiles.
        </t>

        <section anchor="interop-minimum">
          <name>Minimum Endpoint Requirements</name>
          <t>A conforming AITP endpoint requires:</t>
          <ol>
            <li>An AIP module providing SEND and RECEIVE primitives
                with Protocol = 1.</li>
            <li>An association table keyed by (localURI, remoteURI)
                that tracks lifecycle state, flow control window, and
                circuit-breaker state.</li>
            <li>Request ID tracking for correlation and
                deduplication.</li>
            <li>A method-dispatch surface capable of mapping Method
                values to local handlers.</li>
          </ol>
        </section>

        <section anchor="interop-conditions">
          <name>Two-Party Interoperability Conditions</name>
          <t>Two implementations interoperate when they share:</t>
          <ol>
            <li>The same AITP version (currently 1).</li>
            <li>Agreed semantics for the flags, status codes, and
                option types they exchange.</li>
            <li>Compatible compression and signature expectations, if
                the COMPR or SIGNED flags are used.</li>
          </ol>
        </section>

        <section anchor="interop-profiles">
          <name>Core versus Profile</name>
          <t>
            The following are optimization profiles or implementation
            choices, not core protocol requirements:
          </t>
          <ul>
            <li>Lazy association establishment (core baseline is the
                explicit INIT handshake).</li>
            <li>Compression algorithm selection (COMPR flag).</li>
            <li>Operational telemetry and monitoring counters.</li>
            <li>Deployment-specific defaults for window size,
                retransmission parameters, and circuit-breaker
                thresholds.</li>
          </ul>
        </section>
      </section>

      <section anchor="design-rationale">
        <name>Design Rationale</name>
        <t>
          AITP is justified when the following conditions hold:
        </t>
        <ol>
          <li>
            <t><strong>Multiple upper-layer protocols share transport
            needs.</strong></t>
            <t>
              If ADP, task orchestration, knowledge sync, and
              capability advertisement each need method dispatch,
              request/response correlation, retransmission, timeout,
              request-concurrency flow control, and orderly close,
              factoring these into a shared invocation transport
              eliminates redundant specification and implementation.
            </t>
          </li>
          <li>
            <t><strong>AIP remains a narrow waist.</strong></t>
            <t>
              If reliable delivery, association state, and
              request/response semantics were pushed down into AIP,
              AIP would lose its simplicity as a best-effort datagram
              layer.  AITP exists precisely so that AIP can stay thin.
            </t>
          </li>
          <li>
            <t><strong>Agent-native addressing and conversation
            semantics are valued as an independent standard
            layer.</strong></t>
            <t>
              If a deployment is willing to fully delegate transport
              to an existing RPC framework (e.g., gRPC over QUIC),
              AITP is not required.  AITP is valuable when the community
              seeks a self-contained, agent-native invocation transport
              specification that does not depend on any specific
              lower-layer RPC stack.
            </t>
          </li>
        </ol>
        <t>
          A practical test: if removing AITP would cause every
          upper-layer agent protocol to independently redefine
          method dispatch, request IDs, retry policies, timeout
          handling, flow control, and session close/abort, then AITP
          earns its place in the architecture.
        </t>
        <t>
          Method is a first-class header field.  Upper-layer agent
          protocols rely on it for dispatch; AITP provides the
          invocation framing so that they do not each define their
          own.  This is what makes AITP an invocation substrate
          rather than a generic message bus, and is the primary
          reason its flow control counts outstanding requests rather
          than bytes.
        </t>
        <t>
          Because AITP is invocation-oriented rather than byte-stream-
          oriented, its flow control regulates concurrent outstanding
          requests admitted by the remote agent, not raw octet volume
          on the wire.
        </t>
      </section>

      <section anchor="assumptions">
        <name>Assumptions</name>
        <t>AITP assumes:</t>
        <ol>
          <li>An AIP module capable of sending and receiving datagrams
              with Protocol = 1.  AITP does not require any specific AIP
              implementation beyond the SEND/RECEIVE primitives defined
              in <xref target="I-D.song-anp-aip"/>.</li>
          <li>Agent:// URIs are stable identifiers for the duration of
              an association.  If an agent migrates, existing
              associations <bcp14>MAY</bcp14> be invalidated.</li>
          <li>AITP <bcp14>MAY</bcp14> be used by companion upper-layer
              protocols such as capability advertisement (ADP), task
              orchestration, or knowledge synchronisation, but does not
              depend on any specific upper-layer protocol for baseline
              operation.</li>
          <li>The receiving side exposes a method-dispatch surface
              capable of mapping Method values to local handlers.
              AITP does not prescribe how such handlers are
              represented internally.</li>
        </ol>
      </section>

      <section anchor="requirements-language">
        <name>Requirements Language</name>
        <t>
          The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
          "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>",
          "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>",
          "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>",
          "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and
          "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted
          as described in BCP&nbsp;14 <xref target="RFC2119"/>
          <xref target="RFC8174"/> when, and only when, they appear in all
          capitals, as shown here.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 2 — TERMINOLOGY                                      -->
    <!-- ============================================================ -->

    <section anchor="terminology">
      <name>Terminology</name>

      <dl>
        <dt>Segment</dt>
        <dd>
          The protocol data unit of AITP.  A self-contained unit carrying
          a fixed header, method name, TLV options, and body.  Segments
          are carried as AIP datagram payloads with Protocol = 1.
        </dd>

        <dt>Association</dt>
        <dd>
          A stateful transport-layer relationship between two agents
          identified by their agent:// URIs.  An association tracks
          lifecycle state, flow control windows, and circuit-breaker
          state.
        </dd>

        <dt>Request ID</dt>
        <dd>
          A 32-bit sender-assigned identifier used to correlate requests
          with responses and to detect duplicates.  Request IDs
          <bcp14>MUST</bcp14> be unique among outstanding requests
          within a single association.  A stream is a long-lived
          request context identified by its opening Request ID.
        </dd>

        <dt>Method</dt>
        <dd>
          A UTF-8 string (up to 255 octets) identifying the
          operation to be invoked on the remote agent.  Method is a
          first-class header field; upper-layer protocols rely on it
          for dispatch without defining their own invocation framing.
        </dd>

        <dt>Flow Control Window</dt>
        <dd>
          A 16-bit value advertised by the receiver indicating the
          maximum number of concurrent in-flight requests it is willing
          to accept from the sender.
        </dd>

        <dt>Circuit Breaker</dt>
        <dd>
          A per-association fault-isolation mechanism that prevents
          sending requests to a peer that is experiencing persistent
          failures.
        </dd>
      </dl>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 3 — SEGMENT FORMAT                                   -->
    <!-- ============================================================ -->

    <section anchor="segment-format">
      <name>AITP Segment Format</name>

      <t>
        AITP segments are carried as AIP datagram payloads with
        Protocol = 1.  A segment consists of a 16-octet fixed header,
        a variable-length method name (padded to a 4-octet boundary),
        a variable-length TLV options region (padded to a 4-octet
        boundary), and a variable-length body.
      </t>

      <section anchor="header-diagram">
        <name>Header Structure</name>
        <figure anchor="fig-header">
          <name>AITP Segment Header (16 octets fixed)</name>
          <artwork type="ascii-art"><![CDATA[
 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Version|  Type |    Status     |             Flags             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Request ID                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Body Length                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Method Len    |  Options Len  |            Window             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Method (UTF-8, padded to 4-octet boundary) ...        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Options (TLV, padded to 4-octet boundary) ...         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         Body (variable)       ...                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Note: one tick mark represents one bit position.
]]></artwork>
        </figure>
      </section>

      <section anchor="field-definitions">
        <name>Field Definitions</name>

        <dl>
          <dt>Version (4 bits)</dt>
          <dd>
            <t>
              Protocol version.  The current version is 1.
              Implementations <bcp14>MUST</bcp14> silently discard
              segments with an unrecognized version.
            </t>
          </dd>

          <dt>Type (4 bits)</dt>
          <dd>
            <t>The segment type:</t>
            <table anchor="tbl-types">
              <name>AITP Segment Types</name>
              <thead>
                <tr>
                  <th>Value</th>
                  <th>Name</th>
                  <th>Description</th>
                </tr>
              </thead>
              <tbody>
                <tr><td>0</td><td>REQUEST</td><td>Invocation request.  Carries a method name and request body.</td></tr>
                <tr><td>1</td><td>RESPONSE</td><td>Invocation response.  Carries a status code and response body.</td></tr>
                <tr><td>2</td><td>STREAM</td><td>Streaming data chunk.  Part of a bidirectional stream identified by Request ID.</td></tr>
                <tr><td>3</td><td>CONTROL</td><td>Association lifecycle control.  Exactly one of INIT, FIN, or RST <bcp14>MUST</bcp14> be set; invalid combinations <bcp14>MUST</bcp14> be rejected.</td></tr>
                <tr><td>4-15</td><td></td><td>Reserved for future use.</td></tr>
              </tbody>
            </table>
            <t>
              Implementations <bcp14>MUST</bcp14> silently discard
              segments with unrecognized Type values.
            </t>
          </dd>

          <dt>Status (8 bits)</dt>
          <dd>
            <t>
              Result status code.  Primarily meaningful in RESPONSE
              segments; in REQUEST and STREAM segments this field
              <bcp14>SHOULD</bcp14> be set to 0 (OK).
            </t>
            <t>
              AITP status codes span two tiers.  Transport-processing
              codes (0-1, 3-4, 6, 9) reflect outcomes that any
              message-framed transport must report.  Handler-dispatch
              codes (2, 5, 7-8) report minimal method-invocation
              outcomes needed for generic interoperability; they allow
              a sender to distinguish "method not found" from
              "transport error" without requiring application-layer
              parsing.  Dispatch-level status codes are intentionally
              minimal and exist only to support generic upper-layer
              interoperability; richer application semantics belong
              in the response body or upper-layer protocols, not in
              the Status field.
            </t>
            <table anchor="tbl-status">
              <name>AITP Status Codes</name>
              <thead>
                <tr>
                  <th>Value</th>
                  <th>Name</th>
                  <th>Tier</th>
                  <th>Description</th>
                </tr>
              </thead>
              <tbody>
                <tr><td>0</td><td>OK</td><td>Transport</td><td>Success.</td></tr>
                <tr><td>1</td><td>ERROR</td><td>Transport</td><td>Generic error.</td></tr>
                <tr><td>2</td><td>NOT_FOUND</td><td>Dispatch</td><td>Method not registered on the remote agent.</td></tr>
                <tr><td>3</td><td>TIMEOUT</td><td>Transport</td><td>Request timed out (generated locally by the reliability engine).</td></tr>
                <tr><td>4</td><td>BUSY</td><td>Transport</td><td>Remote agent is overloaded; retry later.</td></tr>
                <tr><td>5</td><td>UNAUTHORIZED</td><td>Dispatch</td><td>Caller lacks permission for the requested method.</td></tr>
                <tr><td>6</td><td>INVALID_REQUEST</td><td>Transport</td><td>Malformed request (bad parameters, missing method, etc.).</td></tr>
                <tr><td>7</td><td>INTERNAL_ERROR</td><td>Dispatch</td><td>Unspecified internal processing error on the remote agent.</td></tr>
                <tr><td>8</td><td>NOT_IMPLEMENTED</td><td>Dispatch</td><td>Method recognized but not yet implemented.</td></tr>
                <tr><td>9</td><td>SERVICE_SHUTDOWN</td><td>Transport</td><td>Remote agent is shutting down gracefully.</td></tr>
                <tr><td>10-255</td><td></td><td></td><td>Available for future assignment (IANA registry).</td></tr>
              </tbody>
            </table>
            <t>
              In summary, the four dispatch codes (NOT_FOUND,
              UNAUTHORIZED, INTERNAL_ERROR, NOT_IMPLEMENTED) form
              AITP's minimal generic invocation outcome space.
              They exist so that any upper-layer protocol can
              interpret a basic method-dispatch result without
              parsing the response body.  These four outcomes are
              sufficient to distinguish transport success from basic
              invocation failure classes without committing AITP to
              any application-specific error taxonomy; they support
              interoperable invocation behavior across heterogeneous
              upper-layer protocols without encoding business-level
              semantics.  Richer business
              semantics — task state, payment results, capability
              negotiation outcomes —
              <bcp14>MUST</bcp14> be carried in the response body
              or defined by upper-layer protocols, not encoded as
              AITP status codes.
            </t>
          </dd>

          <dt>Flags (16 bits)</dt>
          <dd>
            <t>A bitmask of control flags:</t>
            <table anchor="tbl-flags">
              <name>AITP Flag Bits</name>
              <thead>
                <tr>
                  <th>Bit</th>
                  <th>Value</th>
                  <th>Name</th>
                  <th>Description</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>0</td>
                  <td>0x0001</td>
                  <td>ACK</td>
                  <td>Acknowledgment.  Set in RESPONSE segments and CONTROL acknowledgments.</td>
                </tr>
                <tr>
                  <td>1</td>
                  <td>0x0002</td>
                  <td>FIN</td>
                  <td>End of stream or association close.  Signals graceful termination.</td>
                </tr>
                <tr>
                  <td>2</td>
                  <td>0x0004</td>
                  <td>INIT</td>
                  <td>Association initialization request.</td>
                </tr>
                <tr>
                  <td>3</td>
                  <td>0x0008</td>
                  <td>RST</td>
                  <td>Reset.  Immediately aborts the association.</td>
                </tr>
                <tr>
                  <td>4</td>
                  <td>0x0010</td>
                  <td>SEQ</td>
                  <td>Sequence number present in options (for ordered delivery within a stream).</td>
                </tr>
                <tr>
                  <td>5</td>
                  <td>0x0020</td>
                  <td>NOACK</td>
                  <td>No acknowledgment requested.  Used for fire-and-forget semantics.</td>
                </tr>
                <tr>
                  <td>6</td>
                  <td>0x0040</td>
                  <td>COMPR</td>
                  <td>Body is compressed.  Compression algorithm is deployment-specific.  Peers <bcp14>MUST</bcp14> either agree on the compression format out of band or reject compressed segments they cannot decode.</td>
                </tr>
                <tr>
                  <td>7</td>
                  <td>0x0080</td>
                  <td>SIGNED</td>
                  <td>Segment carries a cryptographic signature in options.</td>
                </tr>
                <tr>
                  <td>8-13</td>
                  <td></td>
                  <td></td>
                  <td>Reserved for future use.</td>
                </tr>
                <tr>
                  <td>14</td>
                  <td>0x4000</td>
                  <td>CBOPEN</td>
                  <td>Circuit breaker: half-open probe request.</td>
                </tr>
                <tr>
                  <td>15</td>
                  <td>0x8000</td>
                  <td>CBTRIP</td>
                  <td>Circuit breaker: tripped notification to peer.</td>
                </tr>
              </tbody>
            </table>
          </dd>

          <dt>Request ID (32 bits)</dt>
          <dd>
            <t>
              A sender-assigned identifier for request-response
              correlation and deduplication.  Each new request
              <bcp14>MUST</bcp14> use a unique Request ID among
              outstanding requests within the same association.
              RESPONSE segments <bcp14>MUST</bcp14> echo the
              Request ID of the corresponding REQUEST.
            </t>
            <t>
              A stream-opening STREAM segment consumes a Request ID
              for the lifetime of the stream.  The ID
              <bcp14>MUST NOT</bcp14> be reused for another request
              or stream within the same association until the stream
              has terminated (FIN exchanged or RST received).
            </t>
          </dd>

          <dt>Body Length (32 bits)</dt>
          <dd>
            <t>
              The length in octets of the body: the request body in
              REQUEST segments, or the response body in RESPONSE
              segments.  A Body Length of 0 is valid (e.g., for
              CONTROL segments or parameterless requests).
            </t>
          </dd>

          <dt>Method Len (8 bits)</dt>
          <dd>
            <t>
              The length in octets of the UTF-8 method name.  Maximum
              255.  A value of 0 is permitted for CONTROL segments that
              carry no method.  The method field is padded to a 4-octet
              boundary with zero-valued octets.
            </t>
          </dd>

          <dt>Options Len (8 bits)</dt>
          <dd>
            <t>
              The total length in octets of the TLV options region,
              including any padding.  Maximum 255.  The options region
              <bcp14>MUST</bcp14> be padded to a 4-octet boundary.
            </t>
          </dd>

          <dt>Window (16 bits)</dt>
          <dd>
            <t>
              The sender's advertised receive window: the number of
              concurrent in-flight requests the sender is willing to
              accept.  The receiver uses this value for flow control
              (see <xref target="flow-control"/>).  The initial value
              is deployment-specific; implementations
              <bcp14>MAY</bcp14> advertise any value from 1 to 65535.
            </t>
          </dd>
        </dl>
      </section>

      <section anchor="options">
        <name>TLV Options</name>
        <t>
          The options region carries zero or more Type-Length-Value (TLV)
          encoded options, following the same encoding as AIP options:
        </t>
        <artwork type="ascii-art"><![CDATA[
+--------+--------+----------------------------+
|  Type  | Length  |    Data (Length octets)     |
+--------+--------+----------------------------+
  1 byte   1 byte    variable
]]></artwork>

        <table anchor="tbl-options">
          <name>Standard AITP Options</name>
          <thead>
            <tr>
              <th>Type</th>
              <th>Name</th>
              <th>Length</th>
              <th>Description</th>
            </tr>
          </thead>
          <tbody>
            <tr><td>1</td><td>Timeout</td><td>4</td><td>Request timeout in milliseconds (uint32, big-endian).  Included in REQUEST segments to advise the receiver of the caller's deadline.</td></tr>
            <tr><td>2</td><td>SeqNum</td><td>4</td><td>Sequence number (uint32, big-endian).  Used with the SEQ flag for ordered delivery within a stream.</td></tr>
            <tr><td>3</td><td>AckNum</td><td>4</td><td>Acknowledgment number (uint32, big-endian).  Acknowledges receipt of a specific sequence number.</td></tr>
            <tr><td>4</td><td>Timestamp</td><td>8</td><td>UTC Unix timestamp in microseconds (uint64, big-endian).  Used for latency measurement.</td></tr>
            <tr><td>5</td><td>Signature</td><td>variable</td><td>Cryptographic signature over the segment.  Used with the SIGNED flag.</td></tr>
            <tr><td>6</td><td>Metadata</td><td>variable</td><td>Key-value metadata (encoding is application-defined).</td></tr>
            <tr><td>7-127</td><td></td><td></td><td>Available for future assignment (IANA).</td></tr>
            <tr><td>128-254</td><td></td><td></td><td>Available for experimental / private use.</td></tr>
            <tr><td>255</td><td></td><td></td><td>Reserved.</td></tr>
          </tbody>
        </table>

        <t>
          The entire options region <bcp14>MUST</bcp14> be padded to a
          4-octet boundary.  Implementations <bcp14>MUST</bcp14> ignore
          unrecognized option types (skip by reading Type and Length,
          then advancing Length octets).
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 4 — ASSOCIATION STATE MACHINE                        -->
    <!-- ============================================================ -->

    <section anchor="association">
      <name>Association State Machine</name>

      <t>
        An association is a stateful transport-layer relationship between
        two agents, identified by the (localURI, remoteURI) pair.  Each
        association tracks lifecycle state, flow control parameters, and
        circuit-breaker state.
      </t>

      <section anchor="assoc-states">
        <name>Association States</name>

        <table anchor="tbl-states">
          <name>AITP Association States</name>
          <thead>
            <tr>
              <th>Value</th>
              <th>Name</th>
              <th>Description</th>
            </tr>
          </thead>
          <tbody>
            <tr><td>0</td><td>CLOSED</td><td>No association exists.  Initial and terminal state.</td></tr>
            <tr><td>1</td><td>LISTEN</td><td>Waiting for an incoming INIT from a remote peer.</td></tr>
            <tr><td>2</td><td>INIT_SENT</td><td>INIT sent; awaiting INIT+ACK from the remote peer.</td></tr>
            <tr><td>3</td><td>INIT_RECV</td><td>INIT received; INIT+ACK sent; awaiting first data exchange.</td></tr>
            <tr><td>4</td><td>OPEN</td><td>Association fully established.  Data exchange is permitted.</td></tr>
            <tr><td>5</td><td>HALF_CLOSED</td><td>Local side has sent or received FIN; no new requests accepted, but in-flight responses may still arrive.</td></tr>
            <tr><td>6</td><td>DRAINING</td><td>Both sides have exchanged FIN; draining in-flight segments before transitioning to CLOSED.</td></tr>
          </tbody>
        </table>
      </section>

      <section anchor="assoc-transitions">
        <name>State Transitions</name>
        <t>
          The following transitions are valid.  Any other transition
          <bcp14>MUST</bcp14> be rejected as a protocol error.
        </t>

        <artwork type="ascii-art"><![CDATA[
                   +--------+
                   | CLOSED |<-----------------------+
                   +--------+                        |
                    /      \                         |
            passive/        \active                  |
                  v          v                       |
           +--------+   +-----------+               |
           | LISTEN |   | INIT_SENT |               |
           +--------+   +-----------+               |
                  \          /                       |
          INIT    \        / INIT+ACK                |
          recv     v      v                          |
              +-----------+                          |
              | INIT_RECV |                          |
              +-----------+                          |
                    |                                |
                    v                                |
               +--------+                           |
               |  OPEN  |-----------+               |
               +--------+           |               |
                /      \            |               |
           FIN /        \ FIN      RST              |
              v          v          |               |
       +-------------+ +----------+|               |
       | HALF_CLOSED | | DRAINING |+               |
       +-------------+ +----------+                |
              \            /                        |
               \          /  all drained            |
                v        v                          |
                   +--------+                       |
                   | CLOSED |                       |
                   +--------+-----------------------+
]]></artwork>

        <t>Valid transitions from each state:</t>
        <dl>
          <dt>CLOSED</dt>
          <dd>LISTEN (passive open) or INIT_SENT (active open).</dd>
          <dt>LISTEN</dt>
          <dd>INIT_RECV (INIT received) or CLOSED (abort).</dd>
          <dt>INIT_SENT</dt>
          <dd>OPEN (INIT+ACK received) or CLOSED (timeout/abort).</dd>
          <dt>INIT_RECV</dt>
          <dd>OPEN (handshake complete) or CLOSED (abort).</dd>
          <dt>OPEN</dt>
          <dd>HALF_CLOSED (FIN sent/received), DRAINING, or CLOSED (RST).</dd>
          <dt>HALF_CLOSED</dt>
          <dd>DRAINING or CLOSED.</dd>
          <dt>DRAINING</dt>
          <dd>CLOSED (all segments drained).</dd>
        </dl>
      </section>

      <section anchor="lazy-assoc">
        <name>Lazy Association Establishment</name>
        <t>
          The explicit INIT/INIT+ACK handshake defined in
          <xref target="assoc-transitions"/> is the fully specified,
          interoperable baseline.  Implementations that require
          mutual confirmation before data exchange
          <bcp14>MUST</bcp14> use this handshake.
        </t>
        <t>
          LISTEN exists to define the passive side of the explicit
          interoperable baseline; implementations that prefer lazy
          outbound establishment still need to accept incoming
          explicit INIT exchanges.
        </t>
        <t>
          As an optimization, implementations <bcp14>MAY</bcp14> use
          lazy association establishment: when a module needs to send
          a request to a peer with no existing association, it creates
          an association and transitions directly through INIT_SENT to
          OPEN without an explicit on-wire handshake.  This is an
          optimization profile for deployments whose lower layer
          (e.g., libp2p with peer authentication) already guarantees
          peer identity, making the INIT round-trip redundant.
        </t>
        <t>
          Implementations <bcp14>MUST</bcp14> document whether they
          use the explicit handshake or lazy establishment as their
          default mode, and <bcp14>MUST</bcp14> accept incoming INIT
          segments regardless of which mode they prefer for outgoing
          associations.  Interoperability claims for AITP
          <bcp14>MUST</bcp14> be evaluated against the explicit-
          handshake baseline.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 5 — RELIABILITY                                      -->
    <!-- ============================================================ -->

    <section anchor="reliability">
      <name>Reliability Engine</name>

      <t>
        AITP provides reliability through ACK-based tracking,
        retransmission with exponential backoff, and deduplication.
        The reliability engine operates on a per-request basis: each
        outgoing REQUEST that does not carry the NOACK flag is tracked
        until a matching RESPONSE arrives or the request times out.
      </t>

      <section anchor="ack-tracking">
        <name>ACK Tracking</name>
        <t>
          When a REQUEST segment is sent (without the NOACK flag),
          the sender registers the Request ID in a pending-request
          table.  When a RESPONSE segment arrives with a matching
          Request ID, the pending entry is removed and the response
          is delivered to the caller.
        </t>
        <t>
          If the NOACK flag is set, the sender does not track the
          request and does not expect a response.  The receiver
          <bcp14>SHOULD NOT</bcp14> send a response for NOACK
          requests, but <bcp14>MAY</bcp14> still invoke the method
          handler for side effects.
        </t>
      </section>

      <section anchor="retransmission">
        <name>Retransmission</name>
        <t>
          If no RESPONSE arrives within the retransmission timeout,
          the sender retransmits the REQUEST segment.  The
          retransmission timeout uses exponential backoff:
        </t>
        <artwork type="ascii-art"><![CDATA[
timeout(n) = InitialTimeout * BackoffFactor^n

where n = retransmission attempt number (0-based)
]]></artwork>
        <t>
          After MaxRetries retransmissions without a response, the
          reliability engine generates a local TIMEOUT response
          (Status = TIMEOUT) and delivers it to the caller.
          Deployment-specific defaults are expected for
          InitialTimeout, MaxRetries, and BackoffFactor;
          implementations <bcp14>SHOULD</bcp14> document their
          default values.
        </t>
      </section>

      <section anchor="deduplication">
        <name>Deduplication</name>
        <t>
          Retransmitted REQUEST segments carry the same Request ID as
          the original.  The receiver <bcp14>MUST</bcp14> maintain a
          deduplication cache keyed by Request ID.  If an incoming
          REQUEST matches a recently-seen Request ID, the receiver
          <bcp14>MUST</bcp14> silently discard it (the response to the
          original request will serve as the acknowledgment).
        </t>
        <t>
          Implementations <bcp14>MUST</bcp14> bound the deduplication
          cache size and entry lifetime to prevent unbounded resource
          consumption; deployment-specific defaults are expected.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 6 — FLOW CONTROL                                     -->
    <!-- ============================================================ -->

    <section anchor="flow-control">
      <name>Flow Control</name>

      <t>
        AITP flow control is request-concurrency based, not byte-volume
        based.  This is a key departure from traditional transports:
        the Window field counts outstanding REQUEST operations, not
        octets.
        The peer <bcp14>MUST</bcp14> track the remote window and
        <bcp14>MUST NOT</bcp14> have more in-flight requests than the
        advertised window allows.
      </t>
      <t>
        Before sending a REQUEST, the sender checks that its in-flight
        count is below the peer's advertised window and that the
        circuit breaker allows sending (see <xref target="circuit-breaker"/>).
        If either check fails, the send
        <bcp14>MUST</bcp14> be rejected with an appropriate error to
        the upper layer.
      </t>
      <t>
        When a RESPONSE arrives, the sender decrements its in-flight
        count and updates the peer's window from the RESPONSE's
        Window field.  This allows the receiver to dynamically adjust
        its capacity.
      </t>
      <t>
        The initial window size is deployment-specific.
        Implementations <bcp14>MAY</bcp14> advertise any value
        from 1 to 65535; a value of 16 is a reasonable starting
        point for general-purpose agents.
      </t>
      <t>
        The Window field governs concurrent in-flight REQUEST
        operations only.  STREAM chunks are subject to stream-
        specific bounded buffering and back-pressure (see
        <xref target="stream-backpressure"/>), not request-window
        accounting.  An active stream consumes one Request ID slot
        for its lifetime but does not consume additional window
        capacity for subsequent STREAM chunks.
      </t>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 7 — CIRCUIT BREAKER                                  -->
    <!-- ============================================================ -->

    <section anchor="circuit-breaker">
      <name>Circuit Breaker</name>

      <t>
        Each association maintains a per-peer circuit breaker to prevent
        cascading failures when a remote agent is unavailable or
        consistently failing.  The circuit breaker has three states:
      </t>

      <table anchor="tbl-cb-states">
        <name>Circuit Breaker States</name>
        <thead>
          <tr>
            <th>Value</th>
            <th>Name</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
          <tr><td>0</td><td>CLOSED</td><td>Normal operation.  Requests pass through.</td></tr>
          <tr><td>1</td><td>OPEN</td><td>Tripped.  All requests are rejected immediately without being sent.</td></tr>
          <tr><td>2</td><td>HALF_OPEN</td><td>Probing.  One request is allowed through to test recovery.</td></tr>
        </tbody>
      </table>

      <section anchor="cb-transitions">
        <name>Circuit Breaker Transitions</name>
        <artwork type="ascii-art"><![CDATA[
                  success
            +---<----------<---+
            |                  |
            v                  |
        +--------+        +----------+
        | CLOSED |------->| HALF_OPEN|
        +--------+  reset +----------+
            |        timer       |
            v                    v failure
        +--------+               |
        |  OPEN  |<--------------+
        +--------+
        (failures >= threshold)
]]></artwork>
        <t>
          <strong>CLOSED → OPEN:</strong> When the consecutive failure
          count reaches the failure threshold, the circuit breaker
          transitions to OPEN.  Implementations <bcp14>SHOULD</bcp14>
          use deployment-specific defaults for the threshold.
        </t>
        <t>
          <strong>OPEN → HALF_OPEN:</strong> After a reset timeout
          elapses since the last failure, the circuit breaker
          transitions to HALF_OPEN, allowing one probe request.
        </t>
        <t>
          <strong>HALF_OPEN → CLOSED:</strong> If the probe request
          succeeds, the circuit breaker resets to CLOSED and the
          failure count is cleared.
        </t>
        <t>
          <strong>HALF_OPEN → OPEN:</strong> If the probe request
          fails, the circuit breaker returns to OPEN.
        </t>
      </section>

      <section anchor="cb-flags">
        <name>Circuit Breaker Flag Bits</name>
        <t>
          The CBOPEN flag (bit 14) <bcp14>MAY</bcp14> be set on a
          probe request to inform the remote peer that this is a
          circuit-breaker probe.  The CBTRIP flag (bit 15)
          <bcp14>MAY</bcp14> be set by a peer to proactively notify
          the sender that it should trip its circuit breaker.
          These flags are advisory; implementations are not required
          to honor them.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 8 — STREAMING                                        -->
    <!-- ============================================================ -->

    <section anchor="streaming">
      <name>Streaming</name>

      <t>
        AITP supports bidirectional streaming for long-running exchanges
        such as inference generation, file transfer, or multi-turn
        conversations.  A stream is identified by its Request ID and
        uses STREAM segments (Type = 2).
      </t>

      <section anchor="stream-lifecycle">
        <name>Stream Lifecycle</name>
        <ol>
          <li>
            <t><strong>Initiation.</strong></t>
            <t>
              The initiator sends the first STREAM segment with a fresh
              Request ID and a method name.  If the receiver has a
              registered stream handler for that method, a new stream
              is created.  If not, the receiver returns a NOT_FOUND
              RESPONSE.
            </t>
          </li>
          <li>
            <t><strong>Data exchange.</strong></t>
            <t>
              Both sides send STREAM segments with the same Request ID.
              Each segment carries a body chunk.  The SEQ flag and
              SeqNum option <bcp14>MAY</bcp14> be used for ordered
              delivery within a stream.
            </t>
          </li>
          <li>
            <t><strong>Termination.</strong></t>
            <t>
              Either side sends a STREAM segment with the FIN flag to
              signal end of stream.  Upon receiving FIN, the receiving
              side closes its chunk channel.  Both sides
              <bcp14>SHOULD</bcp14> release stream resources after FIN.
            </t>
          </li>
        </ol>
      </section>

      <section anchor="stream-backpressure">
        <name>Back-Pressure</name>
        <t>
          Stream receivers maintain a bounded buffer for incoming chunks.
          If the buffer is full, incoming STREAM segments
          <bcp14>MAY</bcp14> be dropped (back-pressure).  The sender
          <bcp14>SHOULD</bcp14> use the association's flow control
          window and application-level acknowledgments to regulate
          sending rate.
        </t>
      </section>

      <section anchor="stream-large-payloads">
        <name>Large Payload Guidance</name>
        <t>
          AIP limits each datagram payload to 65535 octets.  Upper-layer
          protocols whose response objects may exceed this limit
          <bcp14>SHOULD</bcp14> use one of the following strategies:
        </t>
        <ol>
          <li>
            <t><strong>Streaming.</strong></t>
            <t>
              Use an AITP STREAM exchange to deliver the response
              incrementally.  This is appropriate for variable-size
              payloads such as large Agent Cards, discovery result
              sets, or inference outputs.  Each STREAM chunk carries
              a portion of the response; the receiver reassembles
              them in SeqNum order (when the SEQ flag is used) or
              in arrival order.
            </t>
          </li>
          <li>
            <t><strong>Application-level pagination.</strong></t>
            <t>
              Define "offset" and "limit" parameters in the
              REQUEST body so that the caller can page through
              a large result set with multiple REQUEST/RESPONSE
              round trips.  This is appropriate for enumeration
              operations (e.g., ans.lookup, adp.discover) where
              the total result count may be large but each page
              fits in a single datagram.
            </t>
          </li>
        </ol>
        <t>
          Upper-layer methods that are expected to return large
          payloads <bcp14>SHOULD</bcp14> document which strategy
          they use and whether the method's tool descriptor sets
          streaming = true.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 9 — SEGMENT PROCESSING                               -->
    <!-- ============================================================ -->

    <section anchor="segment-processing">
      <name>Segment Processing</name>

      <t>
        This section defines AITP's complete processing model.  The
        send and receive paths described below depend only on AIP's
        SEND/RECEIVE primitives and the local association/reliability
        state.  No knowledge of upper-layer application protocols is
        required to implement these paths.
      </t>

      <section anchor="sp-sending">
        <name>Sending a Request</name>
        <t>When the upper layer invokes SEND-REQUEST or SEND-ONEWAY:</t>
        <ol>
          <li>
            <t><strong>Ensure association.</strong></t>
            <t>
              Look up or create an association for the destination
              agent:// URI.  If lazy establishment is used, transition
              directly to OPEN.  If explicit handshake is required,
              send CONTROL+INIT and wait for CONTROL+INIT+ACK.
            </t>
          </li>
          <li>
            <t><strong>Check flow control.</strong></t>
            <t>
              Verify that the in-flight count is below the peer's
              advertised window and the circuit breaker allows sending.
              If not, return an error to the caller.
            </t>
          </li>
          <li>
            <t><strong>Construct the segment.</strong></t>
            <t>
              Build the 16-octet fixed header with Version = 1,
              Type = REQUEST (or STREAM), Status = OK, appropriate
              Flags, a fresh Request ID, Body Length, Method Len,
              Options Len, and the local receive Window.  Serialize
              method, options, and body.
            </t>
          </li>
          <li>
            <t><strong>Register for tracking (if not NOACK).</strong></t>
            <t>
              Add the Request ID to the reliability engine's pending
              table and start the retransmission timer.
            </t>
          </li>
          <li>
            <t><strong>Transmit via AIP.</strong></t>
            <t>
              Call AIP's SEND with source = local agent:// URI,
              destination = remote agent:// URI, protocol = 1 (AITP),
              and the serialized segment as payload.
            </t>
          </li>
        </ol>
      </section>

      <section anchor="sp-receiving">
        <name>Receiving a Segment</name>
        <t>
          When AIP delivers a datagram with Protocol = 1 to the AITP
          module:
        </t>
        <ol>
          <li>
            <t><strong>Deserialize.</strong></t>
            <t>
              Decode the fixed header.  If the Version is unrecognized
              or the data is truncated, discard.
            </t>
          </li>
          <li>
            <t><strong>Update association.</strong></t>
            <t>
              Look up or create the association for the source URI.
              Update the last-seen timestamp.  If the segment carries
              a non-zero Window, update the peer's advertised window.
            </t>
          </li>
          <li>
            <t><strong>Dispatch by Type.</strong></t>
            <t>
              <strong>REQUEST:</strong> Check deduplication.  If
              duplicate, discard.  Look up the method handler.  If not
              found, send a RESPONSE with Status = NOT_FOUND.  Otherwise,
              invoke the handler asynchronously.  When the handler
              completes, send a RESPONSE with the handler's status
              and response body (unless NOACK).
            </t>
            <t>
              <strong>RESPONSE:</strong> Deliver to the reliability
              engine, which matches by Request ID and wakes the
              waiting caller.  Update flow control: decrement in-flight
              count and record circuit-breaker success/failure based on
              the status code.
            </t>
            <t>
              <strong>STREAM:</strong> If the Request ID matches an
              active stream, deliver the chunk to the stream's buffer.
              If FIN is set, close the stream's input channel.  If no
              stream exists, check for a stream handler and create a
              new stream.  If no handler, send RESPONSE with
              NOT_FOUND.
            </t>
            <t>
              <strong>CONTROL:</strong> Verify that exactly one of
              INIT, FIN, or RST is set.  Invalid CONTROL flag
              combinations <bcp14>MUST NOT</bcp14> create, mutate,
              or tear down association state; discard the segment.
              INIT → transition association to INIT_RECV then OPEN,
              reply with CONTROL+INIT+ACK;
              FIN → transition to HALF_CLOSED then DRAINING, reply
              with CONTROL+FIN+ACK, then close;
              RST → transition immediately to CLOSED.
            </t>
          </li>
        </ol>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 10 — INTERFACES                                      -->
    <!-- ============================================================ -->

    <section anchor="interfaces">
      <name>Interfaces</name>

      <section anchor="upper-layer-interface">
        <name>Upper Layer Interface (Application Protocols)</name>
        <t>
          AITP provides the following abstract service primitives to
          upper-layer protocols.  These are protocol-level
          abstractions; actual API bindings are implementation-
          defined.
        </t>
        <dl>
          <dt>SEND-REQUEST(destination, method, request-body, timeout)
              -> (status, response-body)</dt>
          <dd>
            <t>Send a request and wait for a response.</t>
            <ul>
              <li><strong>destination</strong> -- agent:// URI of the remote agent.</li>
              <li><strong>method</strong> -- UTF-8 method name (max 255 octets).</li>
              <li><strong>request-body</strong> -- opaque payload bytes.</li>
              <li><strong>timeout</strong> -- optional request deadline.</li>
            </ul>
            <t>Returns: status code and response body, or a
            transport error.</t>
          </dd>

          <dt>SEND-ONEWAY(destination, method, request-body) -> error</dt>
          <dd>
            <t>
              Send a one-way message with no response expected.  Sets
              the NOACK flag.  Returns only a send error, not a
              remote result.
            </t>
          </dd>

          <dt>OPEN-STREAM(destination, method) -> stream</dt>
          <dd>
            <t>
              Initiate a bidirectional stream.  Returns a stream
              handle through which the caller sends and receives
              STREAM chunks.
            </t>
          </dd>

          <dt>REGISTER-HANDLER(method, handler)</dt>
          <dd>
            <t>
              Register a handler that will be invoked when an incoming
              REQUEST arrives for the given method.
            </t>
          </dd>

          <dt>REGISTER-STREAM-HANDLER(method, handler)</dt>
          <dd>
            <t>
              Register a handler that will be invoked when an incoming
              STREAM segment arrives for the given method with no
              active stream.
            </t>
          </dd>
        </dl>
        <t>
          Monitoring and statistics primitives (e.g., counters for
          requests sent, streams active) are implementation concerns
          and are not specified by this document.  Deployment-specific
          counters, tracing hooks, and operational telemetry are
          expected to be defined by implementation profiles rather
          than by this protocol specification.
        </t>
      </section>

      <section anchor="lower-layer-interface">
        <name>Lower Layer Interface (AIP)</name>
        <t>
          AITP depends on AIP for datagram delivery.  The interface
          consists of:
        </t>
        <dl>
          <dt>AIP.SEND(source, destination, protocol=1, payload)</dt>
          <dd>
            <t>
              Sends an AITP segment as an AIP datagram.  AITP always
              uses Protocol = 1.
            </t>
          </dd>

          <dt>AIP.RECEIVE callback (Protocol = 1)</dt>
          <dd>
            <t>
              AIP dispatches incoming datagrams with Protocol = 1
              to AITP's HandleSegment entry point.
            </t>
          </dd>
        </dl>
        <t>
          Note: AIP assigns Protocol values 2 (ANS) and 3 (ADP) for
          potential future direct-datagram exchanges that bypass AITP.
          In normal operation, ANS and ADP methods are carried as AITP
          segments with Protocol = 1.  See AIP
          <xref target="I-D.song-anp-aip"/>, Section 4.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 11 — SECURITY CONSIDERATIONS                         -->
    <!-- ============================================================ -->

    <section anchor="security">
      <name>Security Considerations</name>

      <section anchor="sec-auth">
        <name>Segment Authentication</name>
        <t>
          AITP defines the SIGNED flag and Signature option for segment-
          level authentication.  When the SIGNED flag is set,
          implementations <bcp14>SHOULD</bcp14> verify the signature
          before processing the segment.  The signature algorithm and
          key binding are defined by the deployment context; AITP does
          not mandate a specific algorithm.
        </t>
        <t>
          AITP segment signatures protect invocation-layer provenance
          and segment integrity, while AIP signatures protect the
          enclosing datagram.  Deployments <bcp14>MAY</bcp14> use
          either layer or both, depending on their threat model, and
          <bcp14>SHOULD</bcp14> use at least one.
        </t>
      </section>

      <section anchor="sec-replay">
        <name>Replay Attacks</name>
        <t>
          AITP's deduplication cache (<xref target="deduplication"/>)
          provides protection against replayed REQUEST segments.
          The Timestamp option provides an additional freshness
          signal.  Implementations <bcp14>SHOULD</bcp14> reject
          segments with timestamps outside a deployment-specific
          freshness window.
        </t>
      </section>

      <section anchor="sec-dos">
        <name>Resource Exhaustion</name>
        <t>
          Flow control (<xref target="flow-control"/>) limits the
          number of concurrent in-flight requests per association.
          The circuit breaker (<xref target="circuit-breaker"/>)
          prevents runaway retries to failing peers.
          Implementations <bcp14>MUST</bcp14> bound the deduplication
          cache, pending-request table, and stream buffer sizes to
          prevent unbounded memory growth.
        </t>
      </section>

      <section anchor="sec-method">
        <name>Method Authorization</name>
        <t>
          AITP provides the UNAUTHORIZED status code (5) for method-
          level access control.  The authorization mechanism is
          application-defined; AITP does not prescribe any particular
          access control model.  Implementations <bcp14>SHOULD</bcp14>
          document their authorization strategy.
        </t>
      </section>

      <section anchor="sec-privacy">
        <name>Privacy</name>
        <t>
          Method names and request/response bodies are visible to
          network participants that can observe AIP datagrams.  AITP
          does not provide payload confidentiality.  Applications
          requiring confidentiality <bcp14>SHOULD</bcp14> encrypt
          payloads at the application layer or use privacy-preserving
          lower-layer routing mechanisms.
        </t>
      </section>

      <section anchor="sec-assoc-spoofing">
        <name>Association State Attacks</name>
        <t>
          Because CONTROL segments (INIT, FIN, RST) can create,
          close, or abort associations, unauthenticated control
          segments can induce association churn or exhaust the
          association state table.
        </t>
        <t>
          Deployments <bcp14>SHOULD</bcp14> authenticate peers
          (via AIP SIG, AITP SIGNED, or lower-layer mechanisms)
          before creating persistent association state.
          Implementations <bcp14>SHOULD</bcp14> rate-limit new
          association creation per source URI and
          <bcp14>MUST</bcp14> bound the total number of concurrent
          associations to prevent unbounded state growth.
        </t>
      </section>

      <section anchor="sec-dispatch-leakage">
        <name>Dispatch-Level Information Leakage</name>
        <t>
          The dispatch-level status codes NOT_FOUND (2),
          UNAUTHORIZED (5), and NOT_IMPLEMENTED (8) reveal
          information about the methods registered on the remote
          agent.  An adversary can enumerate supported methods by
          sending probe requests and observing which status code is
          returned.
        </t>
        <t>
          Deployments concerned with method enumeration
          <bcp14>MAY</bcp14> coarsen dispatch-level status codes
          into a generic ERROR or UNAUTHORIZED response for
          unrecognized or unauthorized callers, at the cost of
          reduced diagnostic fidelity for legitimate clients.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 12 — IANA CONSIDERATIONS                             -->
    <!-- ============================================================ -->

    <section anchor="iana">
      <name>IANA Considerations</name>

      <t>
        This document requests the creation of four new IANA registries.
      </t>

      <section anchor="iana-types">
        <name>AITP Segment Type Registry</name>
        <t>
          Registry with 4-bit values (0-15).  Registration policy:
          Specification Required.  Initial values in
          <xref target="tbl-types"/>.
        </t>
      </section>

      <section anchor="iana-status">
        <name>AITP Status Code Registry</name>
        <t>
          Registry with 8-bit values (0-255).  Registration policy:
          Specification Required for 0-127, First Come First Served
          for 128-254.  Value 255 is reserved.  Initial values in
          <xref target="tbl-status"/>.
        </t>
      </section>

      <section anchor="iana-flags">
        <name>AITP Flag Bits Registry</name>
        <t>
          Registry with 16 bit positions (0-15).  Registration policy:
          Specification Required.  Initial values in
          <xref target="tbl-flags"/>.
        </t>
      </section>

      <section anchor="iana-options">
        <name>AITP Option Type Registry</name>
        <t>
          Registry with 8-bit values (0-255).  Registration policy:
          Specification Required for 0-127, First Come First Served for
          128-254, value 255 reserved.  Initial values in
          <xref target="tbl-options"/>.
        </t>
      </section>
    </section>

    <!-- ============================================================ -->
    <!--  SECTION 13 — IMPLEMENTATION STATUS                           -->
    <!-- ============================================================ -->

    <section anchor="impl-status">
      <name>Implementation Status</name>

      <t>
        Per <xref target="RFC7942"/>, this section records known
        implementations.
      </t>

      <section anchor="impl-clawnet">
        <name>ClawNet</name>
        <dl>
          <dt>Organization</dt><dd>ChatChatTech</dd>
          <dt>URL</dt>
          <dd><eref target="https://github.com/ChatChatTech/ClawNet"/></dd>
          <dt>Description</dt>
          <dd>
            Go implementation of the full ANP suite.  The AITP module
            (atp/ directory) implements the 16-octet fixed header,
            segment type demux, TLV options, association state machine,
            reliability engine with exponential-backoff retransmission,
            receiver-advertised flow control, per-association circuit
            breaker, bidirectional streaming, and the full 10-code
            status code set.  The reference implementation is being
            completed as part of the full ClawNet stack conforming to
            AIP, ANS, AITP, and ADP; protocol boundaries are exercised
            in integration tests across the stack.
          </dd>
          <dt>Maturity</dt><dd>Alpha</dd>
          <dt>Coverage</dt>
          <dd>
            <t>Implemented:</t>
            <ul>
              <li>Segment codec (16-octet header, type demux, TLV options)</li>
              <li>Association state machine (7 states, validated transitions)</li>
              <li>Reliability engine (ACK tracking, exponential-backoff retransmission, dedup)</li>
              <li>Receiver-advertised flow control (Window)</li>
              <li>Per-association circuit breaker (CLOSED/OPEN/HALF_OPEN)</li>
              <li>Synchronous invocation and fire-and-forget</li>
              <li>Bidirectional streaming with FIN termination</li>
              <li>Lazy association establishment</li>
            </ul>
            <t>Under integration:</t>
            <ul>
              <li>Segment-level signature verification (SIGNED flag)</li>
              <li>Body compression (COMPR flag)</li>
              <li>Explicit INIT/FIN handshake integration tests</li>
            </ul>
            <t>The items under integration affect robustness and
            efficiency only; they do not alter the wire format,
            segment semantics, or protocol boundaries defined in
            this document.</t>
          </dd>
          <dt>Language</dt><dd>Go</dd>
          <dt>License</dt><dd>Open source</dd>
          <dt>Contact</dt><dd>ink@chatchat.space</dd>
        </dl>
      </section>
    </section>

  </middle>

  <back>

    <references>
      <name>References</name>

      <references>
        <name>Normative References</name>

        <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119">
          <front>
            <title>Key words for use in RFCs to Indicate Requirement Levels</title>
            <author fullname="S. Bradner" initials="S." surname="Bradner"/>
            <date year="1997" month="March"/>
          </front>
          <seriesInfo name="BCP" value="14"/>
          <seriesInfo name="RFC" value="2119"/>
          <seriesInfo name="DOI" value="10.17487/RFC2119"/>
        </reference>

        <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174">
          <front>
            <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
            <author fullname="B. Leiba" initials="B." surname="Leiba"/>
            <date year="2017" month="May"/>
          </front>
          <seriesInfo name="BCP" value="14"/>
          <seriesInfo name="RFC" value="8174"/>
          <seriesInfo name="DOI" value="10.17487/RFC8174"/>
        </reference>

        <reference anchor="I-D.song-anp-aip">
          <front>
            <title>Agent Internet Protocol (AIP)</title>
            <author fullname="Jinke Song" initials="J." surname="Song">
              <organization>Department of CSE, HKUST</organization>
            </author>
            <date year="2026" month="March"/>
          </front>
          <seriesInfo name="Internet-Draft" value="draft-song-anp-aip-01"/>
        </reference>

      </references>

      <references>
        <name>Informative References</name>

        <reference anchor="RFC7942" target="https://www.rfc-editor.org/info/rfc7942">
          <front>
            <title>Improving Awareness of Running Code: The Implementation Status Section</title>
            <author fullname="Y. Sheffer" initials="Y." surname="Sheffer"/>
            <author fullname="A. Farrel" initials="A." surname="Farrel"/>
            <date year="2016" month="July"/>
          </front>
          <seriesInfo name="BCP" value="205"/>
          <seriesInfo name="RFC" value="7942"/>
          <seriesInfo name="DOI" value="10.17487/RFC7942"/>
        </reference>

        <reference anchor="I-D.song-anp-ans">
          <front>
            <title>Agent Name System (ANS)</title>
            <author fullname="Jinke Song" initials="J." surname="Song">
              <organization>Department of CSE, HKUST</organization>
            </author>
            <date year="2026" month="March"/>
          </front>
          <seriesInfo name="Internet-Draft" value="draft-song-anp-ans-00"/>
        </reference>

        <reference anchor="I-D.song-anp-adp">
          <front>
            <title>Agent Description Protocol (ADP)</title>
            <author fullname="Jinke Song" initials="J." surname="Song">
              <organization>Department of CSE, HKUST</organization>
            </author>
            <date year="2026" month="March"/>
          </front>
          <seriesInfo name="Internet-Draft" value="draft-song-anp-adp-00"/>
        </reference>

      </references>
    </references>

    <!-- ============================================================ -->
    <!--  APPENDIX A — IMPLEMENTATION ALIGNMENT NOTES                  -->
    <!-- ============================================================ -->

    <section anchor="appendix-alignment" numbered="true">
      <name>Implementation Alignment Notes</name>

      <t>
        This appendix documents the relationship between this
        specification and the reference implementation in the ClawNet
        atp/ directory.
      </t>

      <table anchor="tbl-alignment">
        <name>Spec-Implementation Mapping</name>
        <thead>
          <tr><th>Spec Concept</th><th>Go Symbol</th><th>Notes</th></tr>
        </thead>
        <tbody>
          <tr><td>Segment Type</td><td>atp.SegmentType</td><td>TypeRequest(0), TypeResponse(1), TypeStream(2), TypeControl(3).</td></tr>
          <tr><td>Status Code</td><td>atp.StatusCode</td><td>Full 10-code set: StatusOK(0) through StatusServiceShutdown(9).</td></tr>
          <tr><td>Flags</td><td>atp.Flags</td><td>FlagACK(0x1), FlagFIN(0x2), FlagINIT(0x4), FlagRST(0x8), FlagSEQ(0x10), FlagNOACK(0x20), FlagCOMPR(0x40), FlagSIGNED(0x80), FlagCBOPEN(0x4000), FlagCBTRIP(0x8000).</td></tr>
          <tr><td>Fixed Header</td><td>fixedHeaderSize = 16</td><td>Byte layout per <xref target="fig-header"/>.</td></tr>
          <tr><td>Options</td><td>atp.Option, OptTimeout..OptMetadata</td><td>TLV encoding with 4-byte alignment.</td></tr>
          <tr><td>Association</td><td>atp.Association</td><td>7-state FSM per <xref target="tbl-states"/>.</td></tr>
          <tr><td>Circuit Breaker</td><td>atp.CBState</td><td>CBClosed(0), CBOpen(1), CBHalfOpen(2).</td></tr>
          <tr><td>Reliability</td><td>atp.Reliability</td><td>Track(), Resolve(), IsDuplicate(), retransmitLoop().</td></tr>
          <tr><td>Flow Control</td><td>Association.AcquireSend/ReleaseSend</td><td>Window-based concurrency limiting.</td></tr>
          <tr><td>Module</td><td>atp.Module</td><td>SEND-REQUEST → Call(), SEND-ONEWAY → FireAndForget(), HandleSegment(), REGISTER-HANDLER → Handle(), REGISTER-STREAM-HANDLER → HandleStream().</td></tr>
          <tr><td>Stream</td><td>atp.Stream</td><td>Recv(), Send(), Close() with FIN termination.</td></tr>
          <tr><td>AIP Interface</td><td>atp.AIPSender</td><td>SendRaw(ctx, src, dst, proto, payload).</td></tr>
        </tbody>
      </table>
    </section>

  </back>

</rfc>
