Documentation
¶
Overview ¶
Package gcf provides a provider.ToolResultCodec that encodes tool results as GCF (Graph Compact Format) instead of JSON when they are sent to the model. GCF is more token-efficient and better comprehended by frontier models than JSON for structured data, so this can cut prompt tokens on tool output. It is opt-in per model (model adapters default to JSON), and it changes only what the model reads: bide's journal and audit trail keep the canonical JSON.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() provider.ToolResultCodec
New returns a GCF tool-result codec. Wire it into a model adapter with that adapter's WithToolResultCodec option, for example:
openai.New(key, openai.WithToolResultCodec(gcf.New()))
Types ¶
type Codec ¶
type Codec struct{}
Codec renders a tool result's JSON bytes as a GCF document.
func (Codec) EncodeToolResult ¶
func (Codec) EncodeToolResult(raw json.RawMessage) (string, error)
EncodeToolResult encodes the canonical JSON as GCF, keeping object keys in the tool's order and every number at exactly the value the tool returned. Integers are carried as int64 and other numbers as float64, in GCF's canonical spelling (1e20 is written 1e+20, 1.50 as 1.5). A number GCF cannot carry exactly (an integer outside int64, or a decimal such as 0.30000000000000000001 that no float64 equals) is an error rather than a silently different value, as is input that is not exactly one valid JSON value (invalid JSON, or trailing data after the value), so the caller can fall back to JSON (provider.EncodeToolResultOr does this). Empty input yields an empty string.