core

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Name = "llm/core"

Variables

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

ErrContextLimitExceeded signals that a provider/model rejected the request due to exceeding the maximum context window (prompt too long / too many tokens).

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

IsContinuationContextLimit reports whether the error is a continuation context-limit failure.

Types

type ContinuationContextLimitError

type ContinuationContextLimitError struct {
	Err error
}

ContinuationContextLimitError marks context-limit failures during continuation (previous_response_id) calls. It unwraps to ErrContextLimitExceeded so existing recovery flows still trigger.

func (ContinuationContextLimitError) Error

func (ContinuationContextLimitError) Unwrap

type ExpandUserPromptInput

type ExpandUserPromptInput struct {
	Prompt  *prompt.Prompt  `json:"prompt,omitempty"`
	Binding *prompt.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 *prompt.Prompt
	Instruction  *prompt.Prompt

	Prompt  *prompt.Prompt
	Binding *prompt.Binding
	Message []llm.Message
	// Instructions holds expanded top-level model instructions, when provided.
	Instructions string
	// ExpandedUserPrompt holds the fully expanded user task text
	// produced from the user template and binding. Callers that
	// wish to persist the expanded task as the canonical user
	// message (instead of the raw input) can read this value
	// after Init completes.
	ExpandedUserPrompt string `yaml:"expandedUserPrompt,omitempty" json:"expandedUserPrompt,omitempty"`

	// UserPromptAlreadyInHistory, when true, signals that the caller has
	// already persisted the expanded user prompt as the latest user
	// message in Binding.History.Past. In that case, Init will not
	// append a synthetic chat_user message into History.Current. When
	// false (default), Init may add a synthetic user message for the
	// current turn.
	UserPromptAlreadyInHistory bool `yaml:"userPromptAlreadyInHistory,omitempty" json:"userPromptAlreadyInHistory,omitempty"`

	// IncludeCurrentHistory controls whether History.Current (in-flight
	// turn messages) should be included when building the LLM request
	// messages. When false, only Past (committed) turns participate;
	// when true (default), Past then Current are flattened.
	IncludeCurrentHistory bool `yaml:"includeCurrentHistory,omitempty" json:"includeCurrentHistory,omitempty"`
	// Participant identities for multi-user/agent attribution
	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 *prompt.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.

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) 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).

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