afx

package
v0.8.0 Latest Latest
Warning

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

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

Documentation

Overview

Package afx holds small ergonomics over the AgentField Go SDK that every reasoner handler in the port reuses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](input map[string]any) (T, error)

Bind decodes a reasoner's untyped input map into a typed value T.

Handlers registered with the SDK receive input as map[string]any. Bind round-trips that map through JSON (marshal then unmarshal into T), which mirrors how the Python port materializes a Pydantic model from the request body: field-name matching is by the json struct tags (the exact snake_case pydantic field names), and any custom UnmarshalJSON on T runs — so a T whose UnmarshalJSON seeds non-zero Pydantic defaults gets those defaults for keys absent from input (design §2.2, §8).

Plain encoding/json is deliberate: no json.Decoder/UseNumber. Numbers in the input map are already Go float64/int (they came from the SDK's own JSON decode or from a Go caller), and re-marshaling then unmarshaling into the typed fields of T yields the correct concrete types without number-precision gymnastics (design §8).

func ToMap

func ToMap(v any) (map[string]any, error)

ToMap is Bind's inverse: it renders a typed input struct as the map[string]any shape the SDK's reasoner handlers (and Agent.CallLocal) accept. Top-level exported fields become map entries keyed by their json tag, and the field VALUES stay typed — deliberately NOT a marshal→unmarshal round trip, which would decode nested values into plain Go maps and lose what their custom marshalers encode. The concrete casualty would be reasoners.OrderedPatches: its object-order MarshalJSON preserves Python's dict insertion order, but flattened into a map[string]any it re-marshals with sorted keys and the meta/obligation prompts would render patches in the wrong order. Keeping values typed lets Bind on the handler side (and the SDK's workflow-event emitter) re-marshal them through the same custom marshalers, so ToMap→Bind is lossless.

The reasoner input structs are flat, fully json-tagged, and carry no omitempty (every key is emitted, so Bind-side default seeding never overrides a deliberately zero field); ToMap ignores omitempty accordingly. Anonymous embedded structs without their own json tag are flattened the way encoding/json flattens them.

Types

This section is empty.

Jump to

Keyboard shortcuts

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