message

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrIncompleteToolTurn = errors.New("message: incomplete tool turn")

ErrIncompleteToolTurn indicates that a message history contains a malformed or incomplete assistant tool-call exchange.

Functions

func CompleteTurnBoundary added in v0.10.0

func CompleteTurnBoundary(messages []Message, preferredStart int) (start int, err error)

CompleteTurnBoundary returns a valid cut point near preferredStart without splitting an assistant tool-call exchange. It validates the full history before choosing the boundary.

func ValidateCompleteTurns added in v0.10.0

func ValidateCompleteTurns(messages []Message) error

ValidateCompleteTurns verifies that every assistant tool-call message is immediately followed by exactly one matching tool result per call.

Types

type JSONSchema

type JSONSchema struct {
	Type                 string                `json:"type,omitempty"`
	Description          string                `json:"description,omitempty"`
	Properties           map[string]JSONSchema `json:"properties,omitempty"`
	Required             []string              `json:"required,omitempty"`
	Items                *JSONSchema           `json:"items,omitempty"`
	Enum                 []string              `json:"enum,omitempty"`
	AdditionalProperties *bool                 `json:"additionalProperties,omitempty"`
}

type Kind

type Kind string
const (
	KindStandard          Kind = "standard"
	KindBranchSummary     Kind = "branch_summary"
	KindCompactionSummary Kind = "compaction_summary"
	KindCommandOutput     Kind = "command_output"
	KindCustom            Kind = "custom"
)

type Message

type Message struct {
	ID       string `json:"id,omitempty"`
	Role     Role   `json:"role"`
	Kind     Kind   `json:"kind,omitempty"`
	Name     string `json:"name,omitempty"`
	Text     string `json:"text,omitempty"`
	Thinking string `json:"thinking,omitempty"`
	// ThinkingSignature is the opaque signature Anthropic attaches to a
	// thinking block; it must be round-tripped verbatim on the next request
	// when extended thinking is combined with tool use, or the API rejects
	// the assistant turn. Empty for providers that do not sign reasoning.
	ThinkingSignature string `json:"thinkingSignature,omitempty"`
	// RedactedThinking carries the opaque payload of a redacted_thinking
	// block (reasoning encrypted by Anthropic's safety systems) so it can be
	// replayed verbatim on a later turn. Empty in the common case.
	RedactedThinking string `json:"redactedThinking,omitempty"`
	// ProviderState carries opaque provider output that must be replayed
	// verbatim on the next turn. Empty for providers that do not require it.
	ProviderState json.RawMessage   `json:"providerState,omitempty"`
	ToolCalls     []ToolCall        `json:"toolCalls,omitempty"`
	ToolResult    *ToolResult       `json:"toolResult,omitempty"`
	TeamID        string            `json:"teamId,omitempty"`
	AgentID       string            `json:"agentId,omitempty"`
	RunID         string            `json:"runId,omitempty"`
	ParentRunID   string            `json:"parentRunId,omitempty"`
	Visibility    Visibility        `json:"visibility,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	CreatedAt     time.Time         `json:"createdAt,omitempty"`
}

func NewText

func NewText(role Role, text string) Message
Example

ExampleNewText demonstrates building a user-authored conversation turn. CreatedAt is intentionally not part of the printed output because NewText stamps it with time.Now() — only the deterministic fields are shown.

package main

import (
	"fmt"

	"github.com/Viking602/go-hydaelyn/message"
)

func main() {
	msg := message.NewText(message.RoleUser, "What is the weather today?")
	fmt.Printf("role=%s kind=%s visibility=%s text=%q\n",
		msg.Role, msg.Kind, msg.Visibility, msg.Text)
}
Output:
role=user kind=standard visibility=shared text="What is the weather today?"

func NewToolResult

func NewToolResult(result ToolResult) Message
Example

ExampleNewToolResult demonstrates wrapping a tool's structured output into a message that the runtime can route back to the calling agent.

package main

import (
	"encoding/json"
	"fmt"

	"github.com/Viking602/go-hydaelyn/message"
)

func main() {
	structured, _ := json.Marshal(map[string]any{
		"temp_c":    21,
		"condition": "sunny",
	})
	msg := message.NewToolResult(message.ToolResult{
		ToolCallID: "call_abc123",
		Name:       "get_weather",
		Content:    "21°C, sunny",
		Structured: structured,
	})
	fmt.Printf("role=%s name=%s tool_id=%s content=%q\n",
		msg.Role, msg.Name, msg.ToolResult.ToolCallID, msg.ToolResult.Content)
}
Output:
role=tool name=get_weather tool_id=call_abc123 content="21°C, sunny"

type Role

type Role string
const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
	RoleCustom    Role = "custom"
)

type ToolCall

type ToolCall struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

type ToolDefinition

type ToolDefinition struct {
	Name                string            `json:"name"`
	Description         string            `json:"description,omitempty"`
	InputSchema         JSONSchema        `json:"inputSchema"`
	Terminal            bool              `json:"terminal,omitempty"`
	Tags                []string          `json:"tags,omitempty"`
	Metadata            map[string]string `json:"metadata,omitempty"`
	Origin              string            `json:"origin,omitempty"`
	Security            ToolSecurity      `json:"security,omitempty"`
	RequiredPermissions []string          `json:"requiredPermissions,omitempty"`
	RequiresApproval    bool              `json:"requiresApproval,omitempty"`
	RiskLevel           string            `json:"riskLevel,omitempty"`
	EffectType          ToolEffectType    `json:"effectType,omitempty"`
	RequiresActionTask  bool              `json:"requiresActionTask,omitempty"`
	Idempotent          bool              `json:"idempotent,omitempty"`
	Timeout             time.Duration     `json:"timeout,omitempty"`
	RetryPolicy         ToolRetryPolicy   `json:"retryPolicy,omitempty"`
	PolicyTags          []string          `json:"policyTags,omitempty"`
}

type ToolEffectType added in v0.7.0

type ToolEffectType string
const (
	ToolEffectReadOnly           ToolEffectType = "read_only"
	ToolEffectWrite              ToolEffectType = "write"
	ToolEffectExternalSideEffect ToolEffectType = "external_side_effect"
)

type ToolResult

type ToolResult struct {
	ToolCallID string          `json:"toolCallId,omitempty"`
	Name       string          `json:"name"`
	Content    string          `json:"content,omitempty"`
	Structured json.RawMessage `json:"structured,omitempty"`
	IsError    bool            `json:"isError,omitempty"`
}

type ToolRetryPolicy added in v0.7.0

type ToolRetryPolicy struct {
	MaxAttempts int           `json:"maxAttempts,omitempty"`
	Backoff     time.Duration `json:"backoff,omitempty"`
}

type ToolSecurity

type ToolSecurity struct {
	RequiredPermissions []string `json:"requiredPermissions,omitempty"`
	RequiresApproval    bool     `json:"requiresApproval,omitempty"`
	RiskLevel           string   `json:"riskLevel,omitempty"`
	Idempotent          bool     `json:"idempotent,omitempty"`
}

type Visibility

type Visibility string
const (
	VisibilityShared  Visibility = "shared"
	VisibilityPrivate Visibility = "private"
)

Jump to

Keyboard shortcuts

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