message

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package message provides typed agent-to-agent message contracts for LoopKit. A Contract carries the name shared between parent and child loops, and provides compile-time-checked helpers for creating Spawn actions and parsing responses.

Usage:

// Define a typed contract (shared between producer and consumer):
var ResearchContract = message.Contract[ResearchReq, ResearchResp]{Name: "researcher"}

// In a parent transition (produce a Spawn action):
act := message.SpawnReq(ResearchContract, ResearchReq{Query: "..."}, budget, grant)

// In a parent transition (consume a SubAgentCompleted event):
resp, err := message.ParseResp(ResearchContract, ev)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseResp

func ParseResp[Req, Resp any](c Contract[Req, Resp], ev event.Envelope) (Resp, error)

ParseResp extracts the typed response from a SubAgentCompleted event. Returns (zero, *ContractMismatchError) if the event is not a SubAgentCompleted, (zero, *OutcomeMismatchError) if the child did not complete successfully, or (resp, nil) on success.

func SpawnReq

func SpawnReq[Req, Resp any](c Contract[Req, Resp], req Req, b budget.Budget, g policy.Grant) action.Spawn

SpawnReq constructs an action.Spawn from a typed contract and request value. The request is JSON-marshalled; marshalling errors produce a panic (same pattern as json.Must helpers — callers must ensure Req is marshallable). Budget and grant are passed through verbatim for the runtime to validate.

Types

type Contract

type Contract[Req, Resp any] struct {
	// Name is the registered child definition name.
	Name string
}

Contract is a typed channel identity that binds a Definition name to its request and response types. It is a zero-cost abstraction — only the Name field is stored at runtime; the type parameters enforce correctness at compile time.

type EventKindMismatchError

type EventKindMismatchError struct {
	WantKind string
	GotKind  string
}

EventKindMismatchError is returned by ParseResp when the event is not a SubAgentCompleted.

func (*EventKindMismatchError) Error

func (e *EventKindMismatchError) Error() string

type OutcomeMismatchError

type OutcomeMismatchError struct {
	Contract    string
	OutcomeKind string
	ErrDetail   string
}

OutcomeMismatchError is returned when the child loop did not complete successfully. The OutcomeKind field carries the actual child outcome (BudgetExceeded, Stuck, etc.).

func (*OutcomeMismatchError) Error

func (e *OutcomeMismatchError) Error() string

type RespUnmarshalError

type RespUnmarshalError struct {
	Contract string
	Cause    error
}

RespUnmarshalError is returned when the response JSON cannot be unmarshalled into Resp. This catches compile-time-impossible mismatches surfaced at runtime (e.g., via reflection).

func (*RespUnmarshalError) Error

func (e *RespUnmarshalError) Error() string

func (*RespUnmarshalError) Unwrap

func (e *RespUnmarshalError) Unwrap() error

Jump to

Keyboard shortcuts

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