Documentation
¶
Overview ¶
Package contract defines Ozy's agent-facing response and error models.
These types are the wire shapes for the findTool, describeTool, and callTool contracts described in SPEC.md §9. They are shared by the broker, the CLI, and the MCP adapter so that every adapter emits the same instructional responses.
Index ¶
- Constants
- type Alternative
- type CallNextAction
- type CallResult
- type Candidate
- type CatalogStats
- type DescribeResult
- type DoctorCheck
- type DoctorResult
- type Error
- type ErrorEnvelope
- type Example
- type FindResult
- type FollowupTool
- type ListResult
- type ListedTool
- type Message
- type NextAction
- type RecommendedCall
- type RelatedTool
- type Renderable
- type SchemaPreview
- type SelectedTool
- type ToolStatus
Constants ¶
const ( ErrTypeToolNotFound = "TOOL_NOT_FOUND" ErrTypeDownstreamServerOffline = "DOWNSTREAM_SERVER_OFFLINE" ErrTypeArgumentValidationFailed = "ARGUMENT_VALIDATION_FAILED" // ErrTypeToolSchemaChanged is reserved: the live broker does not emit it // yet. It names the planned schema-drift failure (cataloged schema no // longer matching the live tool) that the eval corpus already exercises. ErrTypeToolSchemaChanged = "TOOL_SCHEMA_CHANGED" ErrTypeDownstreamCallFailed = "DOWNSTREAM_CALL_FAILED" ErrTypeConfigError = "CONFIG_ERROR" // ErrTypeNotImplemented is a skeleton-only marker for operations whose broker // behavior is deferred to a later change. It is not part of the durable §9.3 // error set and is expected to disappear as behavior is implemented. ErrTypeNotImplemented = "NOT_IMPLEMENTED" )
Error type values returned in structured failures (SPEC.md §9.3).
const ( FormatHuman = "human" FormatJSON = "json" FormatConcise = "concise" )
Output format identifiers shared by every adapter (SPEC.md §15). Human is the default; JSON is a single machine-readable document for agents and evals; concise is a terse mode for token-sensitive use.
const ( DecisionUse = "use" DecisionNoGoodMatch = "no_good_match" DecisionAmbiguous = "ambiguous" DecisionCatalogEmpty = "catalog_empty" )
Decision values for findTool (SPEC.md §9.1). They are explicit so an agent can branch on intent rather than parsing prose. Every value listed here is emittable by the live broker — advertised-but-unreachable states are the lying-interface failure this contract exists to prevent.
const ( CheckOK = "ok" CheckWarn = "warn" CheckError = "error" )
Doctor check status values.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alternative ¶
Alternative is a secondary candidate tool, included only when useful.
type CallNextAction ¶
type CallNextAction struct {
Recommended bool `json:"recommended,omitempty"`
ToolRef string `json:"toolRef,omitempty"`
Reason string `json:"reason,omitempty"`
ExampleCall *RecommendedCall `json:"exampleCall,omitempty"`
}
CallNextAction is a recommended follow-up after a successful call.
type CallResult ¶
type CallResult struct {
OK bool `json:"ok"`
ToolRef string `json:"toolRef"`
Result any `json:"result,omitempty"`
ResultSummary string `json:"resultSummary,omitempty"`
NextActions []CallNextAction `json:"nextActions,omitempty"`
// Notices are actionable, in-band messages the agent must see alongside the
// result (truncation recovery, staleness). Adapters render them inside the
// response content — never only in out-of-band metadata.
Notices []string `json:"notices,omitempty"`
// CachedAgeSeconds is set when this result was served from the result cache:
// the age of the cached entry at serve time. readOnlyHint asserts absence of
// side effects, not temporal validity, so a cached observation must be
// distinguishable from a live one. Nil means the call was invoked live.
CachedAgeSeconds *int64 `json:"cachedAgeSeconds,omitempty"`
}
CallResult is the callTool success response (SPEC.md §9.3).
func (*CallResult) AllNotices ¶
func (r *CallResult) AllNotices() []string
AllNotices returns the notices to surface in-band, including the cache-hit stamp derived from CachedAgeSeconds, so every renderer shows the same set.
func (*CallResult) Render ¶
func (r *CallResult) Render(format string) string
Render produces the human/concise form of a callTool success result.
type Candidate ¶
type Candidate struct {
ToolRef string `json:"toolRef"`
ServerID string `json:"serverId"`
DownstreamToolName string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
}
Candidate is a close-match tool surfaced in a findTool ambiguous response. Each candidate carries enough metadata — including its full input schema — for the agent to compare the candidates and invoke the chosen one directly.
type CatalogStats ¶
type CatalogStats struct {
ConfiguredServers int `json:"configuredServers"`
IndexedTools int `json:"indexedTools"`
FreshTools int `json:"freshTools"`
StaleTools int `json:"staleTools"`
// CatalogAgeSeconds is the time since the last successful index run, so an
// agent can weigh how current the reported tool set and statuses are. Nil
// (omitted) means the catalog has never been indexed — distinct from a
// just-indexed age of 0.
CatalogAgeSeconds *int64 `json:"catalogAgeSeconds,omitempty"`
}
CatalogStats is lightweight catalog health surfaced when it affects confidence.
type DescribeResult ¶
type DescribeResult struct {
ToolRef string `json:"toolRef"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
UsageHints []string `json:"usageHints,omitempty"`
Examples []Example `json:"examples,omitempty"`
RecommendedCall *RecommendedCall `json:"recommendedCall,omitempty"`
RelatedTools []RelatedTool `json:"relatedTools,omitempty"`
Status *ToolStatus `json:"status,omitempty"`
}
DescribeResult is the describeTool response (SPEC.md §9.2): one tool's exact schema, usage guidance, examples, and recommended call shape.
func (*DescribeResult) Render ¶
func (r *DescribeResult) Render(format string) string
Render produces the human/concise form of a describeTool result.
type DoctorCheck ¶
type DoctorCheck struct {
Name string `json:"name"`
Status string `json:"status"` // ok | warn | error
Detail string `json:"detail,omitempty"`
}
DoctorCheck is a single diagnostic result.
type DoctorResult ¶
type DoctorResult struct {
OK bool `json:"ok"`
Checks []DoctorCheck `json:"checks"`
AgentInstruction string `json:"agentInstruction,omitempty"`
}
DoctorResult is the aggregate diagnostics report (SPEC.md §17).
func (*DoctorResult) Render ¶
func (r *DoctorResult) Render(format string) string
Render produces the human/concise form of a doctor report.
type Error ¶
type Error struct {
Type string `json:"type"`
ToolRef string `json:"toolRef,omitempty"`
ServerID string `json:"serverId,omitempty"`
Retryable bool `json:"retryable"`
Message string `json:"message"`
AgentInstruction string `json:"agentInstruction"`
}
Error is a structured, repair-oriented failure (SPEC.md §9.3). AgentInstruction must state, in grounded terms, whether the agent should retry, choose an alternative, ask the user, refresh, or report the failure.
func NotImplemented ¶
NotImplemented builds a skeleton-only structured error for an operation that is not yet wired to real behavior.
type ErrorEnvelope ¶
ErrorEnvelope is the {ok:false,error} failure response shape (SPEC.md §9.3).
func NewErrorEnvelope ¶
func NewErrorEnvelope(e *Error) *ErrorEnvelope
NewErrorEnvelope wraps a structured error in its failure envelope.
func (*ErrorEnvelope) Render ¶
func (env *ErrorEnvelope) Render(format string) string
Render produces the human/concise text form of a failure envelope.
type Example ¶
type Example struct {
Request string `json:"request,omitempty"`
Arguments map[string]any `json:"arguments,omitempty"`
}
Example is a worked invocation example for describeTool.
type FindResult ¶
type FindResult struct {
Query string `json:"query"`
Decision string `json:"decision"`
SelectedToolRef string `json:"selectedToolRef,omitempty"`
Confidence string `json:"confidence,omitempty"`
Reason string `json:"reason,omitempty"`
Selected *SelectedTool `json:"selected,omitempty"`
Candidates []Candidate `json:"candidates,omitempty"`
Errors []Error `json:"errors,omitempty"`
CatalogStats *CatalogStats `json:"catalogStats,omitempty"`
NextAction *NextAction `json:"nextAction,omitempty"`
LikelyFollowupTools []FollowupTool `json:"likelyFollowupTools,omitempty"`
Alternatives []Alternative `json:"alternatives,omitempty"`
Avoid []string `json:"avoid,omitempty"`
AgentInstruction string `json:"agentInstruction,omitempty"`
}
FindResult is the findTool response (SPEC.md §9.1). It is a decision, not just a list, and is always instructional.
func (*FindResult) Render ¶
func (r *FindResult) Render(format string) string
Render produces the human/concise form of a findTool result.
type FollowupTool ¶
FollowupTool is an obvious follow-up suggestion (e.g. read after search).
type ListResult ¶
type ListResult struct {
Tools []ListedTool `json:"tools"`
CatalogStats *CatalogStats `json:"catalogStats,omitempty"`
AgentInstruction string `json:"agentInstruction,omitempty"`
}
ListResult is the catalog listing returned by `ozy list`.
func (*ListResult) Render ¶
func (r *ListResult) Render(format string) string
Render produces the human/concise form of a catalog listing.
type ListedTool ¶
type ListedTool struct {
ToolRef string `json:"toolRef"`
Title string `json:"title,omitempty"`
ServerID string `json:"serverId"`
Freshness string `json:"freshness,omitempty"`
CallableNow bool `json:"callableNow"`
}
ListedTool is one row of the catalog listing.
type NextAction ¶
type NextAction struct {
Tool string `json:"tool,omitempty"`
ToolRef string `json:"toolRef,omitempty"`
Arguments map[string]any `json:"arguments,omitempty"`
Reason string `json:"reason,omitempty"`
}
NextAction tells the agent the next concrete Ozy call to make.
type RecommendedCall ¶
type RecommendedCall struct {
Tool string `json:"tool"`
Arguments map[string]any `json:"arguments"`
}
RecommendedCall is the suggested callTool shape for a tool.
type RelatedTool ¶
type RelatedTool struct {
ToolRef string `json:"toolRef"`
Relationship string `json:"relationship,omitempty"`
}
RelatedTool links a tool to one commonly used alongside it.
type Renderable ¶
Renderable is implemented by every contract result so the render layer can produce human and concise text. JSON output is handled by marshaling the value directly and does not go through Render.
type SchemaPreview ¶
type SchemaPreview struct {
Required []string `json:"required,omitempty"`
Properties []string `json:"properties,omitempty"`
}
SchemaPreview is the field-name preview returned by findTool instead of a full schema, to keep response size bounded (SPEC.md §13).
type SelectedTool ¶
type SelectedTool struct {
ToolRef string `json:"toolRef"`
Title string `json:"title,omitempty"`
CallableNow bool `json:"callableNow"`
ServerStatus string `json:"serverStatus,omitempty"`
SchemaPreview *SchemaPreview `json:"schemaPreview,omitempty"`
InputSchema map[string]any `json:"inputSchema,omitempty"`
RecommendedCall *RecommendedCall `json:"recommendedCall,omitempty"`
}
SelectedTool is the best-match summary embedded in a findTool response. Small schemas ride inline (fast path): when InputSchema is set the agent can go straight to callTool using RecommendedCall, skipping the describeTool hop; SchemaPreview is the bounded fallback for schemas too large to inline.
type ToolStatus ¶
type ToolStatus struct {
CallableNow bool `json:"callableNow"`
ServerStatus string `json:"serverStatus,omitempty"`
CatalogFreshness string `json:"catalogFreshness,omitempty"`
}
ToolStatus reports live/freshness state for a described tool.