Help us shape the future of Go! Take the 2026 Go Developer Survey

gcf

package module
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

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.

Jump to

Keyboard shortcuts

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