Documentation
¶
Overview ¶
LangChainLLM adapts a langchain-golang language.ChatModel to ladyM's LLMProvider — the Go equivalent of Python's LangChainLLMProvider (adapter.py on the main branch). Structured output goes through language.InvokeStructured with a real JSON Schema, so providers enforce it natively (OpenAI json_schema response_format, Anthropic tool use, Ollama format schema) instead of ladyM's former prompt-only fallback.
Package providers holds LadyM's LLM provider abstraction and per-operation agent configuration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NAMED_OPS = []string{
"consolidate",
"proceduralize",
"attention_gate",
"l5_mental_model",
"l6_forward_intent",
}
NAMED_OPS is the set of cognitive operations that can bind an LLM provider.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
Op string
Provider string
BaseURL string
Model string
APIKeyEnv string
PromptTemplate string
MaxTokens int
Temperature float64
StructuredMethod string
ReasoningEffort string
TimeoutS float64
APIKey string
}
AgentConfig is the resolved per-operation LLM configuration. Provider == "none" (or "") means heuristic mode — no LLM call is made.
type AgentRegistry ¶
type AgentRegistry struct {
// contains filtered or unexported fields
}
AgentRegistry builds AgentConfig by layering per-op overrides on [llm] globals.
func NewAgentRegistry ¶
func NewAgentRegistry(cfg *config.Config) *AgentRegistry
NewAgentRegistry builds an AgentRegistry over cfg.
func (*AgentRegistry) Get ¶
func (r *AgentRegistry) Get(op string) (*AgentConfig, error)
Get resolves the AgentConfig for op.
type FakeLLMProvider ¶
type FakeLLMProvider struct {
CompleteFn func([]Message) (string, error)
StructuredFn func([]Message, JSONSchema) (map[string]any, error)
}
FakeLLMProvider is a scriptable test double.
func (*FakeLLMProvider) Close ¶
func (f *FakeLLMProvider) Close() error
func (*FakeLLMProvider) Complete ¶
func (f *FakeLLMProvider) Complete(messages []Message) (string, error)
func (*FakeLLMProvider) CompleteStructured ¶
func (f *FakeLLMProvider) CompleteStructured(messages []Message, schema JSONSchema) (map[string]any, error)
func (*FakeLLMProvider) Name ¶
func (f *FakeLLMProvider) Name() string
type HTTPLLM ¶
type HTTPLLM struct {
// contains filtered or unexported fields
}
HTTPLLM is a net/http-backed provider supporting OpenAI-compatible, Anthropic, and Ollama chat endpoints.
func (*HTTPLLM) CompleteStructured ¶
type JSONSchema ¶
JSONSchema is a JSON-Schema-shaped object describing the expected structured output. It matches langchain-golang's core/schema.Schema (which is itself map[string]any), so callers can pass either.
type LLMProvider ¶
type LLMProvider interface {
Name() string
// Complete returns the model's text reply.
Complete(messages []Message) (string, error)
// CompleteStructured returns a parsed JSON object conforming to schema,
// a real JSON Schema object (mirroring Python's Pydantic-derived schema
// passed to LangChain's with_structured_output).
CompleteStructured(messages []Message, schema JSONSchema) (map[string]any, error)
Close() error
}
LLMProvider is the abstract base for LLM providers.
func MakeAgent ¶
func MakeAgent(cfg *config.Config, op string) (LLMProvider, error)
MakeAgent builds (or skips) the LLM provider bound to one operation. Returns nil for heuristic mode (provider "none"). Fails fast (ConfigError) when a provider is configured but no key resolves.
func MakeLLMProvider ¶
func MakeLLMProvider(kind, baseURL, model, apiKey, structuredMethod, reasoningEffort string, maxTokens int, temperature, timeoutS float64) (LLMProvider, error)
MakeLLMProvider builds a provider for the given kind. Returns nil for "none". "openai" / "anthropic" / "ollama" are backed by langchain-golang partner chat models (mirroring Python's LangChain-based construction); "http" selects the legacy hand-rolled HTTPLLM (OpenAI-compatible /chat/completions) as a zero-framework escape hatch. reasoningEffort ("low"|"medium"|"high"|"") applies only to the OpenAI partner; the other kinds accept and ignore it.
type LangChainLLM ¶
type LangChainLLM struct {
// contains filtered or unexported fields
}
LangChainLLM wraps a langchain-golang ChatModel as an LLMProvider.
func WrapChatModel ¶
func WrapChatModel(cm language.ChatModel, structuredMethod string) *LangChainLLM
WrapChatModel adapts a host-owned langchain-golang ChatModel, mirroring Python's LangChainLLMProvider(chat_model, structured_method).
func (*LangChainLLM) Close ¶
func (l *LangChainLLM) Close() error
func (*LangChainLLM) CompleteStructured ¶
func (l *LangChainLLM) CompleteStructured(messages []Message, sc JSONSchema) (map[string]any, error)
func (*LangChainLLM) Name ¶
func (l *LangChainLLM) Name() string