llmwrap

package
v1.0.0-beta.94 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package llmwrap holds JSON-extraction and truncation helpers shared across the LLM-wrapping components of the ADR-045 Phase 1 research- graph chain (route_search, assess_sufficiency, synthesize_answer).

Scope is deliberately small: extracting a balanced JSON object out of a model's response (markdown fences + prose preface), and capping a string at N bytes with an ellipsis suffix for error-line readability. The chat-completion adapter stays per-component so each component can keep a narrowly-purposed Router/Assessor/ Synthesizer interface in its handler; only the response-shape helpers live here.

Promoted to a shared package in ADR-045 Phase 1 PR 5 (the second and third LLM-wrapping components). Previously inlined in processor/research-graph-route/handler.go; that copy is removed in the same PR.

Index

Constants

View Source
const ErrPayloadTruncateBytes = 512

ErrPayloadTruncateBytes caps the raw-payload snippet rendered in error messages. 512 keeps the structured-emit JSON's action enum, per-action arg keys, and short rationales visible even when the model wrapped its emit in long prose.

Variables

This section is empty.

Functions

func ExtractJSON

func ExtractJSON(content string) ([]byte, error)

ExtractJSON pulls a balanced JSON object out of an LLM response. Many models wrap structured emits in ```json fences or prose preface; this helper strips fences, then walks the first balanced {...} substring while tracking JSON string-literal context (so a `}` inside a string value, e.g. a rationale field like "axes spanning {time, entity_type}", does not truncate the extraction mid-object). Backslash-escaped quotes inside strings do not toggle the string-context flag.

Returns an error if the trimmed content contains no `{`, or if the balanced-brace walker reaches end-of-input with unmatched depth.

func Truncate

func Truncate(s string, n int) string

Truncate returns s capped at n bytes with an ellipsis suffix on over-long input. Used in error-message construction so an over-long LLM response doesn't blow up log lines or trajectory captures.

Types

This section is empty.

Jump to

Keyboard shortcuts

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