protocolpolicy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package protocolpolicy holds the preferred-strategy missing-completion-signal policy as pure values.

The policy decides one canonical terminal candidate and returns only the bounded terminaldecision.Decision plus the protocol state the caller should commit afterwards. It has no provider, runtime, terminal, transcript, verifier, placement, lifecycle, or admission authority, and it starts no goroutine, stores no context, keeps no request-local registry, and holds no globals. Context cancellation, deadline handling, provider dispatch, and platform continuation admission belong to the provider dispatch task, not here.

Counting contract: Reprompts is incremented exactly once, in the proposed state attached to a successfully SDK-validated Continue decision. Every stop path, every encode failure, and every intent-build failure returns the prior state unchanged, so no bounded vocabulary stop consumes a reprompt. The number of admitted platform continuations is core-owned and is not counted here.

No prose heuristic, semantic guess, verifier verdict, or candidate-text inspection participates in any decision. Only canonical evidence fields and canonical protocol state do.

Index

Constants

View Source
const (
	// ReasonInvalidInput reports invalid or incomplete SDK input, limits, or
	// platform snapshot.
	ReasonInvalidInput = "invalid_input"
	// ReasonInvalidState reports unusable preferred protocol state.
	ReasonInvalidState = "invalid_protocol_state"
	// ReasonAuthoritative reports an authoritative non-continuable cause.
	ReasonAuthoritative = "authoritative_candidate"
	// ReasonExplicitCompletion reports a trusted explicit completion signal.
	ReasonExplicitCompletion = "explicit_completion"
	// ReasonPreOutputFailure reports a pre-output transport or provider
	// failure, which stays with the existing stream-recovery owner.
	ReasonPreOutputFailure = "pre_output_failure"
	// ReasonUnsafeAction reports incomplete or ambiguous ordinary tool state.
	ReasonUnsafeAction = "unsafe_action_state"
	// ReasonMissingTrajectory reports a missing resumable trajectory.
	ReasonMissingTrajectory = "missing_trajectory"
	// ReasonMissingObjective reports a missing bounded objective.
	ReasonMissingObjective = "missing_objective"
	// ReasonProtocolInactive reports that no completion protocol was active for
	// this candidate, so a missing signal is not missing work.
	ReasonProtocolInactive = "completion_protocol_inactive"
	// ReasonProtocolTerminal reports an absorbing protocol stop state.
	ReasonProtocolTerminal = "protocol_terminal"
	// ReasonNoProgress reports the consecutive no-progress breaker.
	ReasonNoProgress = "no_progress"
	// ReasonBudgetExhausted reports configured-cap or platform-cap exhaustion.
	ReasonBudgetExhausted = "budget_exhausted"
	// ReasonIntentBuildFailed reports a state-token or intent build failure. It
	// consumes no reprompt.
	ReasonIntentBuildFailed = "intent_build_failed"
	// ReasonMissingSignal is the only fixed reason for an emitted repair.
	ReasonMissingSignal = "missing_completion_signal"
)

Bounded reason codes. Every value is a fixed classification well inside the SDK reason bound and never carries candidate text, raw identifiers, arguments, results, or provider payloads.

Variables

View Source
var ErrInvalidIntent = errors.New("agent-loop-guard protocol policy: invalid recovery intent")

ErrInvalidIntent is the bounded sentinel for a failed intent build. Its message never contains candidate text, identifiers, arguments, or results.

Functions

func BuildIntent

func BuildIntent(in terminaldecision.Input, controlToken string) (terminaldecision.ContinuationIntent, error)

BuildIntent builds the bounded missing-signal continuation intent from the existing objective, the existing trajectory reference, the caller's encoded preferred control reference, and the fixed bounded reason.

The intent carries no A-leg append, placement, execution, or recovery ownership change: it is only canonical references, internal-control provenance, and control text. Completed ordinary tool facts are never carried into the instruction, so nothing is replayed. If the objective would exceed the SDK instruction bound it is truncated on a UTF-8 boundary; the fixed clauses are never shortened or omitted to make room. The complete result is validated against the SDK intent bounds before it is returned.

func LoadState

LoadState resolves the preferred protocol state carried by the candidate's lineage.

Every reserved state namespace is checked first. A reference belonging to the preferred or legacy token family is either decoded strictly, when it carries exactly the current supported preferred prefix, or refused as invalid state: an unsupported version, a malformed payload, a noncanonical spelling, and any legacy reference are rejected even when they match the live b-leg or the existing trajectory on an initial candidate. Legacy state is never translated, and corrupted counters are never reset.

An otherwise unmatched reference is an opaque initial lineage reference. An exact, byte-for-byte match with the current request B-leg denotes the initial zero state, including an initial b-leg sequence or attempt above one after a retry. With a missing B-leg, only an exact existing trajectory reference is recognized. Only an empty reference bootstraps, and only for an initial attempt of zero or one; a later empty or mismatched foreign reference stops conservatively.

No reference value is trimmed, normalized, or rewritten before comparison or decoding. No request-local registry, map, or cross-call memory is consulted: the decision uses only this candidate's bounded values.

Types

type Result

type Result struct {
	Decision  terminaldecision.Decision
	NextState protocolstate.State
	// Committed reports that NextState records one emitted intent.
	Committed bool
}

Result is the pure policy outcome.

NextState is the state the caller commits after the platform accepts the decision. It equals the proposed state only for a committed Continue decision and equals the prior state for every stop and every build failure, so an allow_stop never silently rewrites protocol counters.

func Evaluate

Evaluate is the pure missing-signal policy.

An authoritative cause, a trusted explicit completion signal, a pre-output failure, unsafe ordinary tool state, a missing objective, a missing resumable trajectory, an inactive protocol expectation, an absorbing terminal state, and cap or no-progress exhaustion all stop conservatively with a bounded reason.

Otherwise the evidence is observed once, the resulting state is checked for eligibility against the configured and platform budgets, a proposed state advances the total exactly once, and that proposed state is what the returned Continue decision carries as its control reference. The caller commits NextState only after the platform accepts the decision.

Evaluation never contacts a provider, never constructs or calls a verifier, and issues no auxiliary request. An empty or prose candidate text is never inspected for meaning: classifying an actually empty failure that canonical facts report as Normal remains the dispatch task's responsibility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL