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

core

package
v0.1.21 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Name = "llm/core"

Variables

View Source
var ErrContextLimitExceeded = errors.New("llm/core: context limit exceeded")

Functions

func ContainsContextLimitError

func ContainsContextLimitError(input string) bool

func IsAnchorContinuationEnabled

func IsAnchorContinuationEnabled(model llm.Model) bool

IsAnchorContinuationEnabled reports whether previous_response_id-style anchor continuation should be used. Some providers/endpoints (e.g. ChatGPT backend HTTP responses) support Responses API transport but not anchor continuation.

func IsContextContinuationEnabled

func IsContextContinuationEnabled(model llm.Model) bool

IsContextContinuationEnabled reports whether the provided model supports server-side context continuation (i.e. continuation by response id by open ai). The current core only gates this by the model capability flag; per-request overrides are not handled here.

func IsContinuationContextLimit

func IsContinuationContextLimit(err error) bool

func WriteLLMRequestDebugPayload added in v0.1.8

func WriteLLMRequestDebugPayload(ctx context.Context, modelName string, request *llm.GenerateRequest, extraDebugContext map[string]interface{}, traceSuffix string)

Types

type ContinuationContextLimitError

type ContinuationContextLimitError struct {
	Err error
}

func (ContinuationContextLimitError) Error

func (ContinuationContextLimitError) Unwrap

type ExpandUserPromptInput

type ExpandUserPromptInput struct {
	Prompt  *binding.Prompt  `json:"prompt,omitempty"`
	Binding *binding.Binding `json:"binding,omitempty"`
}

ExpandUserPromptInput represents a lightweight request to expand only the user prompt template given a binding, without constructing a full GenerateRequest or calling the model. It mirrors the user-facing portion of GenerateInput.

type ExpandUserPromptOutput

type ExpandUserPromptOutput struct {
	ExpandedUserPrompt string `json:"expandedUserPrompt"`
}

ExpandUserPromptOutput carries the expanded user prompt text.

type GenerateInput

type GenerateInput struct {
	llm.ModelSelection
	SystemPrompt *binding.Prompt
	Instruction  *binding.Prompt
	Prompt       *binding.Prompt
	Binding      *binding.Binding
	Message      []llm.Message
	Instructions string

	ExpandedUserPrompt    string `yaml:"expandedUserPrompt,omitempty" json:"expandedUserPrompt,omitempty"`
	IncludeCurrentHistory bool   `yaml:"includeCurrentHistory,omitempty" json:"includeCurrentHistory,omitempty"`
	UserID                string `yaml:"userID" json:"userID"`
	AgentID               string `yaml:"agentID" json:"agentID"`
}

func (*GenerateInput) Init

func (i *GenerateInput) Init(ctx context.Context) error

func (*GenerateInput) MatchModelIfNeeded

func (i *GenerateInput) MatchModelIfNeeded(matcher llm.Matcher)

func (*GenerateInput) Validate

func (i *GenerateInput) Validate(ctx context.Context) error

type GenerateOutput

type GenerateOutput struct {
	Response  *llm.GenerateResponse
	Content   string
	MessageID string
}

GenerateOutput represents output from extraction

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(finder llm.Finder, registry tool.Registry, convClient apiconv.Client) *Service

New creates a new extractor service

func (*Service) AttachmentUsage

func (s *Service) AttachmentUsage(convID string) int64

AttachmentUsage returns cumulative attachment bytes recorded for a conversation.

func (*Service) BuildContinuationRequest

func (s *Service) BuildContinuationRequest(ctx context.Context, req *llm.GenerateRequest, history *binding.History) *llm.GenerateRequest

BuildContinuationRequest constructs a continuation request by selecting the latest assistant response anchor (resp.id) and including only tool-call messages that map to that anchor.

Continuation replays the exact tool-call/tool-result slice for the latest anchored provider response. If replay state is wrong, the producer needs to emit the missing tool-call trace or tool result rather than teaching the continuation layer to guess around the gap.

func (*Service) EnrichToolDefinition

func (s *Service) EnrichToolDefinition(def *llm.ToolDefinition)

EnrichToolDefinition mutates def in place, replacing its Parameters with an enriched copy when overlays match.

func (*Service) EnrichedToolDefinitions

func (s *Service) EnrichedToolDefinitions() []llm.ToolDefinition

EnrichedToolDefinitions exposes the executor definitions with overlay enrichment so callers return UI-ready schemas.

func (*Service) EnrichedToolDefinitionsWithContext added in v0.1.15

func (s *Service) EnrichedToolDefinitionsWithContext(ctx context.Context) []llm.ToolDefinition

EnrichedToolDefinitionsWithContext exposes executor definitions with overlay enrichment using request-scoped context when the registry supports it.

func (*Service) ExpandUserPrompt

func (s *Service) ExpandUserPrompt(ctx context.Context, in *ExpandUserPromptInput, out *ExpandUserPromptOutput) error

ExpandUserPrompt provides a typed helper around the internal expandUserPrompt executable so callers within this process can expand only the user prompt template without invoking a full generate call.

func (*Service) Generate

func (s *Service) Generate(ctx context.Context, input *GenerateInput, output *GenerateOutput) (retErr error)

func (*Service) Method

func (s *Service) Method(name string) (svc.Executable, error)

Method returns the specified method

func (*Service) Methods

func (s *Service) Methods() svc.Signatures

Methods returns the service methods

func (*Service) ModelFinder

func (s *Service) ModelFinder() llm.Finder

func (*Service) ModelImplements

func (s *Service) ModelImplements(ctx context.Context, modelName, feature string) bool

ModelImplements reports whether a given model supports a feature. When modelName is empty or not found, it returns false.

func (*Service) ModelMatcher

func (s *Service) ModelMatcher() llm.Matcher

func (*Service) ModelToolPreviewLimit

func (s *Service) ModelToolPreviewLimit(model string) int

ModelToolPreviewLimit returns the preview limit in bytes for a model or 0 when not configured.

func (*Service) Name

func (s *Service) Name() string

Name returns the service Name

func (*Service) ProviderAttachmentLimit

func (s *Service) ProviderAttachmentLimit(model llm.Model) int64

ProviderAttachmentLimit returns the provider-configured attachment cap for the given model. Zero means unlimited/not enforced by this provider.

func (*Service) SetAttachmentUsage

func (s *Service) SetAttachmentUsage(convID string, used int64)

SetAttachmentUsage sets cumulative attachment bytes for a conversation.

func (*Service) SetConversationClient

func (s *Service) SetConversationClient(c apiconv.Client)

func (*Service) SetModelPreviewLimits

func (s *Service) SetModelPreviewLimits(m map[string]int)

SetModelPreviewLimits sets per-model preview byte limits used by binding to trim tool results.

func (*Service) SetStreamPublisher

func (s *Service) SetStreamPublisher(p modelcallctx.StreamPublisher)

SetStreamPublisher injects a stream publisher used for token-level deltas.

func (*Service) Stream

func (s *Service) Stream(ctx context.Context, in, out interface{}) (func(), error)

Stream handles streaming LLM responses, structuring JSON output for text chunks, function calls and finish reasons.

func (*Service) ToolDefinitions

func (s *Service) ToolDefinitions() []llm.ToolDefinition

ToolDefinitions returns every tool definition registered in the tool registry. The slice may be empty when no registry is configured (unit tests or mis-configuration).

func (*Service) ToolDefinitionsWithContext added in v0.1.15

func (s *Service) ToolDefinitionsWithContext(ctx context.Context) []llm.ToolDefinition

type StreamInput

type StreamInput struct {
	*GenerateInput
	StreamID string
}

type StreamOutput

type StreamOutput struct {
	Events    []streaming.Event `json:"events"`
	MessageID string            `json:"messageId,omitempty"`
}

StreamOutput aggregates streaming events into a slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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