Expand description
Canonical, provider-neutral protocol types for agent runtimes.
Protocol compatibility is versioned independently from this crate’s semantic version. This crate contains data and validation only; it does not perform model requests, tool execution, policy evaluation, or persistence.
§Example
use std::str::FromStr;
use tea_protocol::{
AgentCommand, CommandEnvelope, CommandId, ProfileId, ProtocolMetadata,
ProtocolTimestamp,
};
let command = CommandEnvelope::new(
CommandId::from_str("0195a0b1-5e3b-7ef0-8ec1-0aa7aa000001")?,
None,
ProtocolTimestamp::from_str("2026-07-23T09:30:12.123Z")?,
AgentCommand::CreateSession {
profile_id: ProfileId::from_str("minimal-assistant")?,
metadata: ProtocolMetadata::default(),
},
)?;
let json = serde_json::to_string(&command)?;
assert!(json.contains(r#""type":"create_session""#));Structs§
- Approval
Id - A stable approval request identifier.
- Branch
Id - A stable session branch identifier.
- Causation
Id - A stable identifier for the command or record that caused a fact.
- Code
Change - Bounded, structured presentation of one changed file.
- Code
Change Hunk - One grouped hunk of a code-change presentation.
- Code
Change Line - One bounded, line-numbered source line in a diff hunk.
- Command
Envelope - A versioned command transport envelope.
- Command
Id - A stable command identifier.
- Command
Text - Bounded command text that rejects controls unsafe for logs and transports.
- Correlation
Id - A stable diagnostic correlation identifier.
- Currency
Code - A three-letter uppercase ISO-style currency code.
- Currency
Code Parse Error - Error returned when parsing a currency code.
- Decimal
Amount - A canonical, non-negative decimal amount encoded as text.
- Event
Envelope - A versioned observable event envelope.
- EventId
- A stable observable event identifier.
- Exact
Cost - An exact persisted monetary amount.
- External
Source - A normalized external source returned by search or another hosted tool.
- Hosted
Tool Activity - One complete provider-hosted tool activity retained in assistant content.
- Hosted
Tool Error - Provider-reported hosted tool failure.
- Message
Id - A stable canonical message identifier.
- ModelId
- A bounded canonical model selector.
- Model
Ref - Complete canonical identity of one model advertised by one provider.
- Profile
Id - A bounded product profile selector.
- Protocol
Error - A safe, localizable protocol error payload.
- Protocol
Error Envelope - Versioned protocol-error transport envelope.
- Protocol
Metadata - Bounded extension metadata keyed by collision-resistant namespaces.
- Protocol
Timestamp - An RFC 3339 timestamp normalized to UTC with millisecond precision.
- Protocol
Version - A canonical
major.minoragent protocol version. - Provider
Continuation - Bounded provider-owned data needed to reconstruct a later request.
- Provider
Id - A bounded canonical model-provider selector.
- Reasoning
Effort Parse Error - Error returned for an unknown reasoning effort spelling.
- Record
Envelope - Versioned durable session-record envelope.
- Record
Id - A stable durable session record identifier.
- RunId
- A stable agent run identifier.
- Session
Id - A stable agent session identifier.
- Session
Sequence - A monotonically increasing, session-local record or event sequence.
- Source
Citation - A normalized citation associated with assistant text and an external source.
- Token
Count - A token count safe to encode as a JSON number for JavaScript consumers.
- Tool
Call Id - A stable canonical tool-call identifier.
- Tool
Failure - Machine-readable failure returned by a tool.
- TurnId
- A stable agent turn identifier.
- Unknown
Skippable Event - Validated common fields retained when skipping an unknown observation.
- Usage
- Provider-neutral token usage.
- WebFetch
Presentation - Bounded provider-neutral presentation of one client web-fetch result.
- WebFetch
Redirect - One bounded redirect in a normalized client web-fetch result.
Enums§
- Agent
Command - A provider- and transport-neutral agent command payload.
- Agent
Command Type - Stable initial command discriminators.
- Agent
Error Code - Stable machine-readable protocol error code.
- Agent
Event - A provider- and UI-neutral observable runtime event.
- Agent
Event Type - Stable known event discriminators.
- Approval
Decision - A user decision for a pending approval.
- Canonical
Message - A provider-neutral conversation message.
- Code
Change Kind - Kind of file change represented by a code-change presentation.
- Code
Change Line Kind - Kind of one line in a code-change hunk.
- Code
Change Truncation - Reason a code-change presentation was deterministically truncated.
- Code
Change Validation Error - Validation failure for a structured code-change presentation.
- Command
Decode Error - Failure while decoding an untrusted command envelope.
- Command
Validation Error - Error returned when validating command data.
- Content
Block - A provider-neutral message content block.
- Content
Validation Error - Error returned when validating content blocks.
- Cost
Unit - Unit used by exact currency amounts.
- Decimal
Amount Parse Error - Error returned when parsing an exact decimal amount.
- Event
Compatibility - Compatibility classification for observable events.
- Event
Decode Error - Failure while inspecting an untrusted observable event.
- Event
Delta - A bounded streaming content delta.
- Event
Inspection - Result of inspecting a known or forward-compatible observable event.
- Event
Validation Error - Error returned when validating event data.
- Execution
Target - Tool executor boundary used for a durable invocation.
- External
Content Error - Validation failure for hosted tool, source, citation, or continuation content.
- Hosted
Tool Outcome - Terminal provider-hosted tool outcome.
- Image
Source - Source of an image content block.
- Message
Role - Role of a canonical message.
- Message
Validation Error - Error returned when validating canonical messages.
- Next
Turn Action - Kernel action allowed after a durable turn checkpoint.
- Policy
Decision - Policy outcome persisted before an approval or execution transition.
- Protocol
Error Validation Error - Error returned when validating a safe protocol error.
- Protocol
IdParse Error - Error returned when parsing a canonical protocol identifier.
- Protocol
Metadata Error - Error returned when validating extension metadata.
- Protocol
Timestamp Parse Error - Error returned when parsing a protocol timestamp.
- Protocol
Version Parse Error - Error returned when parsing a protocol version.
- Reasoning
Effort - Provider-neutral reasoning effort ordered from disabled to maximum.
- Record
Decode Error - Failure while decoding an untrusted durable record.
- Record
Validation Error - Error returned when validating a durable record payload.
- Retry
Class - Whether and how a caller may retry an operation.
- RunStatus
- Terminal status of an observable run.
- Selector
Parse Error - Error returned when parsing a model or profile selector.
- Session
Record - A typed durable fact used for deterministic session replay.
- Session
Record Type - Stable initial durable record discriminators.
- Session
Sequence Parse Error - Error returned when parsing a session sequence.
- Stop
Reason - Normalized assistant stop reason with forward-compatible unknown values.
- Tool
Idempotency - Declared retry semantics of a tool execution.
- Tool
Presentation - UI-only presentation attached to a tool result or preview.
- Usage
Error - Error returned when validating token usage.
- WebFetch
Truncation - Why a normalized client web-fetch body was truncated.
Constants§
- CURRENT_
PROTOCOL_ VERSION - The protocol version written by this crate.
- MAX_
APPROVAL_ ITEMS - Maximum capabilities or resources in one approval observation.
- MAX_
APPROVAL_ ITEM_ BYTES - Maximum UTF-8 bytes in one capability or resource string.
- MAX_
CODE_ CHANGE_ HUNKS - Maximum hunks retained for one code-change presentation.
- MAX_
CODE_ CHANGE_ LINES - Maximum lines retained across one code-change presentation.
- MAX_
CODE_ CHANGE_ LINES_ PER_ HUNK - Maximum lines retained in one hunk.
- MAX_
CODE_ CHANGE_ LINE_ BYTES - Maximum UTF-8 byte length of one retained source line.
- MAX_
CODE_ CHANGE_ PATCH_ BYTES - Maximum UTF-8 byte length of an optional unified patch.
- MAX_
CODE_ CHANGE_ PATH_ BYTES - Maximum UTF-8 byte length of a workspace-relative changed-file path.
- MAX_
COMMAND_ TEXT_ BYTES - Maximum UTF-8 bytes in a command text fragment.
- MAX_
ERROR_ MESSAGE_ BYTES - Maximum UTF-8 bytes in an English technical error message.
- MAX_
EVENT_ DELTA_ BYTES - Maximum UTF-8 bytes in one streaming delta.
- MAX_
EXTERNAL_ SOURCE_ TEXT_ BYTES - Maximum UTF-8 bytes in a source snippet or cited text.
- MAX_
EXTERNAL_ SOURCE_ TITLE_ BYTES - Maximum UTF-8 bytes in one external source title.
- MAX_
EXTERNAL_ SOURCE_ URL_ BYTES - Maximum UTF-8 bytes in one external source URL.
- MAX_
HOSTED_ TOOL_ SOURCES - Maximum normalized sources retained for one hosted tool activity.
- MAX_
INLINE_ IMAGE_ BASE64_ BYTES - Maximum encoded bytes in one inline Base64 image.
- MAX_
METADATA_ BYTES - Maximum encoded JSON bytes for one metadata map.
- MAX_
METADATA_ DEPTH - Maximum JSON container nesting depth inside metadata values.
- MAX_
METADATA_ NAMESPACES - Maximum number of metadata namespaces on one protocol value.
- MAX_
PROGRESS_ MESSAGE_ BYTES - Maximum UTF-8 bytes in one progress diagnostic.
- MAX_
PROVIDER_ CONTINUATION_ BYTES - Maximum encoded JSON bytes in one opaque provider continuation envelope.
- MAX_
PROVIDER_ CONTINUATION_ DEPTH - Maximum nesting depth in provider continuation JSON.
- MAX_
RECORD_ CONTENT_ BLOCKS - Maximum result content blocks stored for one tool execution.
- MAX_
SAFE_ INTEGER - Largest integer exactly representable by a JavaScript
Number. - MAX_
SELECTOR_ BYTES - Maximum UTF-8 bytes in a model or profile selector.
- MAX_
TEXT_ BLOCK_ BYTES - Maximum UTF-8 bytes in one text or thinking content block.
- MAX_
TOOL_ ARGUMENT_ BYTES - Maximum encoded JSON bytes for tool arguments.
- MAX_
TOOL_ ARGUMENT_ DEPTH - Maximum nesting depth for tool arguments.
- MAX_
UNKNOWN_ EVENT_ BYTES - Maximum encoded JSON bytes retained while inspecting an unknown event.
- MAX_
WEB_ FETCH_ BODY_ BYTES - Maximum UTF-8 bytes in an extracted client web-fetch body.
- MAX_
WEB_ FETCH_ BODY_ CHARS - Maximum Unicode scalar values in an extracted client web-fetch body.
- MAX_
WEB_ FETCH_ MIME_ BYTES - Maximum UTF-8 bytes in a normalized client web-fetch MIME type.
- MAX_
WEB_ FETCH_ REDIRECTS - Maximum redirect records retained by a normalized client web-fetch result.
- MAX_
WEB_ FETCH_ TITLE_ BYTES - Maximum UTF-8 bytes in a normalized client web-fetch title.
- MAX_
WEB_ FETCH_ URL_ BYTES - Maximum UTF-8 bytes in a normalized client web-fetch URL.
- PROTOCOL_
V1_ 0 - Protocol version 1.0.