Documentation
¶
Index ¶
- Variables
- func CompleteTurnBoundary(messages []Message, preferredStart int) (start int, err error)
- func ValidateCompleteTurns(messages []Message) error
- type JSONSchema
- type Kind
- type Message
- type Role
- type ToolCall
- type ToolDefinition
- type ToolEffectType
- type ToolResult
- type ToolRetryPolicy
- type ToolSecurity
- type Visibility
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
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
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 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 ¶
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 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" )