Documentation
¶
Overview ¶
Package core is the module overview for the Scope narrow waist. It declares no API of its own; every capability lives in a sibling package listed below.
Core owns the serializable, provider-neutral protocols that every provider implements and every capability module consumes: the protocol values, the minimal calling SPI of each modality, and the pure composition around them. It owns no provider SDK, no network backend, no tokenizer vocabulary, no agent control flow, and no telemetry.
Protocol packages ¶
Each modality package owns one request/response protocol and the minimal github.com/Tangerg/scope/core/chat.Model-shaped SPI that carries it:
- chat: messages, parts, tool calls, usage, and output format.
- embedding: text-to-vector requests and vectors.
- image: image generation.
- moderation: content classification.
- rerank: query-to-document relevance ranking.
- speech: text-to-speech, with an independent Streamer.
- transcription: audio-to-text.
Every one of them exports the same three sentinels — ErrInvalidOptions, ErrInvalidRequest, and ErrInvalidResponse — so providers and integrations classify failures identically. Chat extends that triple with its own protocol errors because its wire additionally models tool calls, parts, and usage. Classify protocol errors with errors.Is; never match on message text. Chat's invocation.Failure owns execution evidence for one complete model invocation. Its ClassifyFailure function preserves that scope across composed calls while errors.Is and errors.As retain the underlying diagnostics. JSON decoders reject unknown struct members before replacing the receiver, including nested protocol values. Metadata, namespaced extensions, JSON schemas, and tool-defined payloads retain their open data contracts. Protocol validation rejects strings and timestamps that cannot be encoded losslessly, so accepted values can cross the JSON boundary without repair.
Shared values ¶
The content, document, media, and metadata packages own the values the protocols embed: ordered text/media blocks and citations, the canonical Document, the Media container shared by every modality, and the JSON-safe typed extension values. The timestamp package owns lossless JSON admission for time.Time without introducing a competing time representation. A protocol DTO never carries a closure, reader, logger, tracer, registry, or native client.
Cross-protocol capabilities ¶
The jsonschema, tool, tokenizer, history, and vectorstore packages own the capabilities that are not specific to one modality: schema derivation and validation, the executable tool contract with its binding and authorization boundary, token counting and encoding, conversation history, and semantic indexing and search.
Direct clients ¶
The chatclient and embeddingclient packages add the ordinary-path conveniences — request admission, prompt templates, and structured output — without changing the SPI; chat.Wrap is the one way to compose middleware. Option defaults stay with the provider that owns them. The safeguard package screens input and output as fail-closed chat middleware. The httpclient package binds a borrowed HTTP client to its configured API origin so credentials cannot cross that boundary through redirects. The Host retains transport, retry, authentication, and resource-lifetime ownership.
Streaming ¶
A modality's Model has only Call. Real streaming is a separate Streamer, so a provider that cannot stream never has to pretend it can. Streams are iter.Seq2 values; early caller stop, context cancellation, and first-error termination are all part of the contract.
Reference implementations and contract suites ¶
The history/inmemory and vectorstore/inmemory packages are in-process reference stores. The modeltest, history/storetest, and vectorstore/storetest packages hold the reusable conformance suites an implementor runs to be held to the same protocol as every other provider. They contain no provider implementation and are never a dependency of production code.
Boundaries ¶
Core never imports a sibling module, a provider SDK, a concrete tokenizer vocabulary, or OpenTelemetry. Instrumentation lives in the otel module and decorates Core from the outside. Retries, approvals, planning, and durable execution are Agent or Host concerns.
Example ¶
package main
import (
"context"
"fmt"
"github.com/Tangerg/scope/core/chat"
"github.com/Tangerg/scope/core/chatclient"
)
type echoModel struct{}
func (echoModel) Call(_ context.Context, request *chat.Request) (*chat.Response, error) {
message := chat.NewAssistantMessage(chat.NewTextPart(request.Messages[0].Text()))
output, err := chat.NewOutput(&message, chat.FinishReasonStop, nil)
if err != nil {
return nil, err
}
return chat.NewResponse(output, nil)
}
func main() {
client, err := chatclient.New(echoModel{})
if err != nil {
panic(err)
}
request := &chat.Request{
Messages: []chat.Message{
chat.NewUserMessage(chat.NewTextPart("hello")),
},
Options: chat.Options{Model: "example-model"},
}
response, err := client.Call(context.Background(), request)
if err != nil {
panic(err)
}
fmt.Println(response.Text())
}
Output: hello
Directories
¶
| Path | Synopsis |
|---|---|
|
Package chat defines the serializable provider-neutral chat protocol and its minimal synchronous Model and optional Streamer capabilities.
|
Package chat defines the serializable provider-neutral chat protocol and its minimal synchronous Model and optional Streamer capabilities. |
|
Package chatclient provides direct, optional conveniences around the minimal chat protocols and model capabilities defined by Core.
|
Package chatclient provides direct, optional conveniences around the minimal chat protocols and model capabilities defined by Core. |
|
Package content owns the ordered text, media, and citation values shared by chat and tool output.
|
Package content owns the ordered text, media, and citation values shared by chat and tool output. |
|
Package document defines the canonical serializable Document content value shared by extraction, retrieval, and model-facing components.
|
Package document defines the canonical serializable Document content value shared by extraction, retrieval, and model-facing components. |
|
Package embedding defines the stable text-to-vector protocol and its single-method provider SPI.
|
Package embedding defines the stable text-to-vector protocol and its single-method provider SPI. |
|
Package embeddingclient projects validated Core embedding responses into independently owned single or batch vectors.
|
Package embeddingclient projects validated Core embedding responses into independently owned single or batch vectors. |
|
Package history defines provider-neutral conversation history contracts and model middleware.
|
Package history defines provider-neutral conversation history contracts and model middleware. |
|
inmemory
Package inmemory provides the in-process reference history store.
|
Package inmemory provides the in-process reference history store. |
|
storetest
Package storetest provides reusable conformance checks for history stores.
|
Package storetest provides reusable conformance checks for history stores. |
|
Package httpclient bounds an API client's requests to its configured origin.
|
Package httpclient bounds an API client's requests to its configured origin. |
|
Package image defines the serializable image-generation protocol and its single-method Model capability.
|
Package image defines the serializable image-generation protocol and its single-method Model capability. |
|
internal
|
|
|
modelid
Package modelid owns the one admission rule shared by every modality's model identifier: an empty value is allowed, and a non-empty value must be valid UTF-8 without surrounding whitespace.
|
Package modelid owns the one admission rule shared by every modality's model identifier: an empty value is allowed, and a non-empty value must be valid UTF-8 without surrounding whitespace. |
|
ptr
Package ptr holds pointer helpers shared across Core's protocol packages.
|
Package ptr holds pointer helpers shared across Core's protocol packages. |
|
Package invocation preserves execution evidence at a complete model-call boundary.
|
Package invocation preserves execution evidence at a complete model-call boundary. |
|
Package jsonschema derives, parses, and validates JSON Schema contracts.
|
Package jsonschema derives, parses, and validates JSON Schema contracts. |
|
Package media defines the serializable Media container shared by every modality that accepts non-text payloads.
|
Package media defines the serializable Media container shared by every modality that accepts non-text payloads. |
|
Package metadata provides JSON-safe extension values for Core protocol types.
|
Package metadata provides JSON-safe extension values for Core protocol types. |
|
Package modeltest provides reusable contract tests for Core model interfaces.
|
Package modeltest provides reusable contract tests for Core model interfaces. |
|
Package moderation defines the serializable content-moderation protocol and its single-method Model capability.
|
Package moderation defines the serializable content-moderation protocol and its single-method Model capability. |
|
Package rerank defines the provider-neutral protocol for ranking documents against one query.
|
Package rerank defines the provider-neutral protocol for ranking documents against one query. |
|
Package safeguard provides fail-closed input and output screening as Core chat middleware.
|
Package safeguard provides fail-closed input and output screening as Core chat middleware. |
|
Package speech defines the stable text-to-speech protocol and independent synchronous Model and optional Streamer provider capabilities.
|
Package speech defines the stable text-to-speech protocol and independent synchronous Model and optional Streamer provider capabilities. |
|
Package timestamp owns lossless RFC 3339 admission for protocol timestamps.
|
Package timestamp owns lossless RFC 3339 admission for protocol timestamps. |
|
Package tokenizer defines small, provider-neutral capabilities for counting and encoding text tokens.
|
Package tokenizer defines small, provider-neutral capabilities for counting and encoding text tokens. |
|
Package tool defines the provider-neutral executable Tool protocol, its immutable Contract and execution Binding, authorization boundary, typed typed signature, function adapter, and instance-scoped registry.
|
Package tool defines the provider-neutral executable Tool protocol, its immutable Contract and execution Binding, authorization boundary, typed typed signature, function adapter, and instance-scoped registry. |
|
Package transcription defines the serializable audio-to-text protocol and its single-method Model capability.
|
Package transcription defines the serializable audio-to-text protocol and its single-method Model capability. |
|
Package vectorstore defines the raw, space-bound database capabilities.
|
Package vectorstore defines the raw, space-bound database capabilities. |
|
filter
Package filter defines the stable metadata-filter expression vocabulary used by vector stores.
|
Package filter defines the stable metadata-filter expression vocabulary used by vector stores. |
|
filter/keyword
Package keyword derives exact, indexable string terms from canonical document metadata for native indexes that support keyword membership.
|
Package keyword derives exact, indexable string terms from canonical document metadata for native indexes that support keyword membership. |
|
inmemory
Package inmemory implements exact vector search over process-local records.
|
Package inmemory implements exact vector search over process-local records. |
|
storetest
Package storetest provides conformance suites for vector stores and filters.
|
Package storetest provides conformance suites for vector stores and filters. |