registry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 36 Imported by: 1 module, 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 registry has the providers of models, by names which the registry gives them, and finds the models across them

Index

Constants

View Source
const (
	// DefaultMaxIterations is how many times the agent loop asks a model for
	// its reply, when it isn't told how many
	DefaultMaxIterations = 10

	// DefaultToolTimeout is the most time a tool the agent loop runs has to
	// return, when it isn't told how long
	DefaultToolTimeout = 30 * time.Second
)
View Source
const (
	// EventSchema is the schema of the registry's events, which the
	// toolkit's events share
	EventSchema = "llm"

	// ProviderTable is the table of the events of providers, whose rows are
	// their names in the registry
	ProviderTable = "provider"

	// SessionTable is the table of the events of sessions, whose rows are
	// their identifiers
	SessionTable = "session"
)
View Source
const (
	// AgentNamespace is the name of the namespace of the toolkit's tools
	// which are the registry's agents
	AgentNamespace = "agent"
)
View Source
const DefaultMaxDepth = 3

DefaultMaxDepth is the most agents which run in one another, as an agent calls another, or itself, as a tool, when the max_depth option of the session, or agent, which runs them, doesn't say

View Source
const (
	// DefaultToolResultLimit is the most tokens of a tool's result the agent
	// loop sends to the model, when the model's context isn't known
	DefaultToolResultLimit = 8192
)

Variables

View Source
var (
	// PingInterval is how long the result of a provider's ping is used, and
	// how often Run pings the providers, so whether one can be reached is
	// known within it. A provider decides how often it asks its server, so
	// one of an API, such as OpenAI's, which is rarely unreachable, can keep
	// its ping's result for longer. A provider which downloads models, such
	// as Ollama, has its models listed again as often, as they can be
	// downloaded or deleted without the registry, and listing them is quick.
	PingInterval = 30 * time.Second

	// ModelCacheInterval is how long a provider's models are cached, unless
	// it downloads models
	ModelCacheInterval = 6 * time.Hour
)
View Source
var TypingTimeout = 10 * time.Second

TypingTimeout is how long a session is typing, after a client last says someone is, before it's idle, so a client which goes away doesn't leave it typing

Functions

This section is empty.

Types

type AgentStore added in v0.6.0

type AgentStore interface {
	// Create creates an agent with the definition, and returns it, with its
	// serial, and when it was created. Returns ErrConflict when there's an
	// agent with its name.
	Create(context.Context, schema.AgentMeta) (schema.Agent, error)

	// Get returns the agent with the name. Returns ErrNotFound when there's
	// none.
	Get(ctx context.Context, name string) (schema.Agent, error)

	// List returns the agents, in the store's order, from the request's
	// offset, and at most its limit of them, and how many there are
	List(context.Context, schema.AgentListRequest) (schema.AgentList, error)

	// Put replaces the agent with its name, when its serial is that agent's,
	// and returns it, with its new serial, and when it was modified. Returns
	// ErrNotFound when there's none, and ErrConflict when its serial isn't
	// the agent's, as it was changed since it was seen.
	Put(context.Context, schema.Agent) (schema.Agent, error)

	// Delete deletes the agent with the name, when the serial is its serial,
	// or does nothing when there's none. Returns ErrConflict when the serial
	// isn't its serial, as it was changed since it was seen.
	Delete(ctx context.Context, name string, serial uint64) error
}

AgentStore has agents, each by its name, with its serial, which the store sets, and changes each time the agent is stored, so a change is made to the agent as it was last seen, rather than a newer one, such as one which another server made. An agent's serial is never one which an agent with its name had before, including one which was deleted, and created again, so a change to the agent as it was isn't made to the new one.

type CredentialsProvider

type CredentialsProvider interface {
	// Expand returns the value with each placeholder replaced with its
	// credential, or an error when a credential doesn't exist
	Expand(ctx context.Context, value string) (string, error)
}

CredentialsProvider expands credentials, such as a provider's API key, whose placeholders, such as ${OPENAI_KEY} or $OPENAI_KEY, are replaced with the credentials they name

type Opt

type Opt func(*opt) error

Opt is a functional option for the registry

func WithAgentStore added in v0.6.0

func WithAgentStore(store AgentStore) Opt

WithAgentStore sets the store of the agents, such as a database, which other servers share, or files, so they're kept when the server restarts

func WithBroadcaster added in v0.6.0

func WithBroadcaster(b *broadcaster.Broadcaster) Opt

WithBroadcaster sets the broadcaster which the registry publishes its events to, such as one which others share, so a server's events are served together. Its owner runs it. Without it, the registry has its own, which isn't run, so its watches end only when they're cancelled.

func WithClientOpts

func WithClientOpts(opts ...client.ClientOpt) Opt

WithClientOpts sets the options of the HTTP clients of the providers which the registry creates, such as their tracer, user agent and timeout

func WithCredentialsProvider

func WithCredentialsProvider(credentials CredentialsProvider) Opt

WithCredentialsProvider sets the provider which expands credentials, such as the API key of a provider which is created, whose placeholders, such as ${OPENAI_KEY}, are replaced with the credentials they name. Without one, or with nil, the credentials are environment variables.

func WithProviderStore added in v0.6.0

func WithProviderStore(store ProviderStore) Opt

WithProviderStore sets the store of the providers, which the registry's providers are kept the same as, both ways, as Run syncs them, such as a database, which other servers share, or a file, so they're kept when the server restarts

func WithSessionStore added in v0.6.0

func WithSessionStore(store SessionStore) Opt

WithSessionStore sets the store of the sessions, such as a database, which other servers share, or files, so they're kept when the server restarts

func WithToolkit

func WithToolkit(tools *toolkit.Toolkit) Opt

WithToolkit sets the toolkit of the tools which the registry's models can call

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer, which traces the registry's operations, such as listing models, and generating messages

type ProviderOpt

type ProviderOpt func(*cached) error

ProviderOpt is an option of a provider which is added to the registry

func WithExclude

func WithExclude(patterns ...string) ProviderOpt

WithExclude excludes the models whose names match one of the patterns, which are regular expressions, such as -mini$

func WithInclude

func WithInclude(patterns ...string) ProviderOpt

WithInclude includes only the models whose names match one of the patterns, which are regular expressions, such as ^gpt-, or every model when there are none

type ProviderStore added in v0.6.0

type ProviderStore interface {
	// List returns the providers, with their serials, in any order
	List(context.Context) ([]schema.Provider, error)

	// Put creates the provider, when its serial is zero, and the store has
	// no provider with its name, or replaces the provider with its name,
	// when its serial is that provider's, and returns it, with its new
	// serial. Returns ErrConflict when its serial isn't the provider's, as
	// the provider was changed, or created, since it was seen.
	Put(context.Context, schema.Provider) (schema.Provider, error)

	// Delete deletes the provider with the name, when the serial is its
	// serial, or does nothing when there's none. Returns ErrConflict when
	// the serial isn't its serial, as it was changed since it was seen.
	Delete(ctx context.Context, name string, serial uint64) error

	// Watch sends the store's events to the channel, when its providers are
	// changed by others, such as other servers, from when it returns, until
	// the context is cancelled, as the registry's Watch does. It returns a
	// channel which is sent nil, or an error when the store stops, once the
	// watch has ended. A store which isn't changed by others, such as a
	// file, sends no events, as its providers are listed periodically.
	Watch(context.Context, chan<- eventschema.Event) (<-chan error, error)
}

ProviderStore has the definitions of providers, with their names, and their API keys' placeholders, such as ${OPENAI_KEY}, rather than their credentials, by their names, each with its serial, which the store sets, and changes each time the provider does, so a change is made to the provider as it was last seen, rather than a newer one, such as one which another server made

type Registry

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

Registry is the providers of models, by names which it gives them, so there can be more than one provider of a type, such as two Ollama servers. Providers can be added and removed. It's safe to use concurrently.

func New

func New(opts ...Opt) (*Registry, error)

New returns a registry without providers, which are added with Add, with the options, such as its tracer

func (*Registry) Add

func (r *Registry) Add(name string, provider llm.Provider, opts ...ProviderOpt) error

Add adds the provider, with the name, which must be an identifier, such as my-ollama, which starts with a letter, followed by letters, numbers, underscores or hyphens, or with its own name, such as its type, when the name is empty, and the options, such as the patterns of the names of the models which are included, or excluded. Returns ErrConflict when a provider with the name, or the provider itself, is added already, and ErrBadParameter when a pattern isn't valid. Watchers are sent that it was created.

func (*Registry) AgentLoop added in v0.6.0

func (r *Registry) AgentLoop(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (_ []providerschema.Message, _ llm.Usage, err error)

AgentLoop asks the model for its reply to the messages, runs the tools it calls, and asks it again with their results, until it replies, its reply is truncated as it reached the most tokens it can generate, or it's been asked as many times as the max_iterations option, or DefaultMaxIterations times when it isn't set.

When the json_schema option is set, the model replies by calling the respond tool, which is added to the tools, with a result which conforms to the schema, and the system prompt says so. The reply is then the result, as JSON text, rather than the call, so each tool call in the conversation has its result. A model which replies with text is asked to call the tool, and a result which doesn't conform, or a call with other tools, is returned to the model as an error, each of which counts as an iteration, until it's been asked as many times as it can be.

Each tool has the tool_timeout option to return, or DefaultToolTimeout when it isn't set, after which its result is that it timed out. The results are truncated, as toolkit.TruncateResult does, as the model's provider measures them, or as they're estimated, so the model's context, which is the smaller of its input token limit and the context_window option, is at most two thirds full with them, or to DefaultToolResultLimit tokens each, when the model's context isn't known.

The max_iterations, tool_timeout and json_schema options are the loop's, so aren't passed to the model, unlike the other options. Returns the messages added to the conversation: each of the model's replies, followed by the results of the tools it called, or the request to call the respond tool, except the last, which is the model's last reply, whose result is why the loop stopped: stop, or another reason the model stopped; or max_tokens, blocked, error or max_iterations, when the tools it called aren't run, as its input may be incomplete, or it didn't finish, or it's been asked as many times as it can be, so are left out of it. So each tool call has its result, and the messages can be sent to a model again, as the rest of a conversation. When the reply has a schema, its result is stop only when it's the result. A tool which the model calls, and which isn't one of the tools, or fails, has its error returned to the model as its result. The replies are streamed to the function as they're generated, when it isn't nil, each separated by a blank line, until the loop returns, when nothing more is streamed, though a tool which didn't return in time may still log. Returns ErrBadParameter when a message is nil, an option isn't valid, or a tool is named as the respond tool when the reply has a schema, the errors of WithoutSession, and the context's error when it's done while a tool runs.

func (*Registry) AgentStore added in v0.6.0

func (r *Registry) AgentStore() AgentStore

AgentStore returns the store of the registry's agents, or nil when it has none, when it has no agents

func (*Registry) Ask

Ask returns the reply of the request's model to its messages, which include earlier turns of the conversation, as the agent loop does, but which stops when the model calls tools, whose calls are in its reply, for the caller to run, rather than run. The model replies after the system prompt, with the options, and can call the tools, which are got from the registry's toolkit. When the request has a schema, the model replies by calling the respond tool, whose result is the reply's result: a model which replies with text is asked to call it, and a result which doesn't conform to the schema is returned to the model to correct, until it's been asked respondAttempts times, or as many times as the max_iterations option. The messages are compacted, as the agent loop does, to fit the model's context, without changing them, and when they don't fit, however compacted, the model isn't asked, and the reply is empty, with max_context as its result. The reply is streamed to the function as it's generated, when it isn't nil, with each of the model's replies separated by a blank line. Returns ErrBadParameter when the request isn't valid, ErrNotFound when the model, or a tool, isn't found, and the errors of WithoutSession.

func (*Registry) Broadcaster added in v0.6.0

func (r *Registry) Broadcaster() *broadcaster.Broadcaster

Broadcaster returns the broadcaster which the registry publishes its events to, so its events can be served, and it can be run

func (*Registry) Chat added in v0.6.0

func (r *Registry) Chat(ctx context.Context, id uuid.UUID, messages []llm.Message, stream llm.GeneratorStreamFn) (_ *schema.ChatResponse, err error)

Chat adds the messages to the session with the identifier, and the messages which its model, asked as WithSession asks it, adds, which are its reply, the results of the tools it called, and the rest, and stores it, with its usage: the tokens used by every request to its model, and the tokens of its conversation, as of the reply. The reply is streamed to the function as it's generated, when it isn't nil. Returns what was added, with the session's serial, as it was stored. Returns ErrNotFound when there's no session, ErrConflict when it was changed as the model replied, as the reply is to the conversation as it was, so isn't stored, ErrServiceUnavailable when the registry has no session store, and the errors of WithSession. The session is replying until the model has replied, and its reply is stored.

func (*Registry) CreateAgent added in v0.6.0

func (r *Registry) CreateAgent(ctx context.Context, meta schema.AgentMeta) (_ *schema.Agent, created bool, err error)

CreateAgent creates an agent with the definition, in the registry's agent store, or replaces the agent with its name, with the definition, as it is, rather than merging them, when it's changed, and returns it, as it's stored, or the agent as it is, when it hasn't changed, so creating agents each time a server starts, such as its examples, changes only those which have, and whether it was created, rather than replaced, or kept. Its name must be an identifier, such as segment, which refers to it. Its input, when it has one, must be a JSON schema of an object, and its prompt a Go template, which is executed with the input. Its model, when it has one, is the registry's, by its canonical name, and its tools are the toolkit's, by their canonical names, as a session's are. It needn't have a model, as one can be given when it's run. Returns ErrBadParameter when the definition isn't valid, ErrNotFound when the model isn't the registry's, or a tool isn't the toolkit's, ErrConflict when the agent was changed as it was replaced, or a name is ambiguous, and ErrServiceUnavailable when the registry has no agent store.

func (*Registry) CreateProvider

func (r *Registry) CreateProvider(ctx context.Context, req schema.Provider) (_ *schema.ProviderStatus, err error)

CreateProvider creates a provider of the type, such as ollama, and adds it to the registry, with its name, or its type when it has none, once it's validated, as newProvider does, and pinged. The request is kept, as the provider's definition, with its API key's placeholder, rather than its credentials, and its serial is 1, whatever the request's. Returns ErrBadParameter when the type is unknown, ErrServiceUnavailable when it can't be reached, as it can't be used, and ErrConflict when a provider with its name is added already.

func (*Registry) CreateSession added in v0.6.0

func (r *Registry) CreateSession(ctx context.Context, meta schema.SessionMeta) (_ *schema.Session, err error)

CreateSession creates a session with the settings, in the registry's session store, and returns it, with no messages. Its model, when it has one, is the registry's, by its canonical name, such as ollama:llama3.2:latest, and its tools are the toolkit's, by their canonical names, such as weatherapi:current, or a namespace and "*", or "*", as they are. It needn't have a model, as it can be inherited. Returns ErrBadParameter when the settings aren't valid, ErrNotFound when the model isn't the registry's, or a tool isn't the toolkit's, ErrConflict when a name is ambiguous, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) DeleteAgent added in v0.6.0

func (r *Registry) DeleteAgent(ctx context.Context, name string) (_ *schema.Agent, err error)

DeleteAgent deletes the agent with the name, and returns it, as it was. Returns ErrNotFound when there's none, ErrConflict when it was changed as it was deleted, and ErrServiceUnavailable when the registry has no agent store.

func (*Registry) DeleteModel

func (r *Registry) DeleteModel(ctx context.Context, model llm.Model) (err error)

DeleteModel deletes the model, with its provider, which must be in the registry, and download models

func (*Registry) DeleteProvider

func (r *Registry) DeleteProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)

DeleteProvider removes the provider with the name from the registry, and returns it, or returns ErrNotFound when there's none. It isn't pinged.

func (*Registry) DeleteSession added in v0.6.0

func (r *Registry) DeleteSession(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)

DeleteSession deletes the session with the identifier, with its messages, and returns it, as it was, without them. Returns ErrNotFound when there's none, ErrConflict when it was changed as it was deleted, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) Embed

func (r *Registry) Embed(ctx context.Context, model llm.Model, messages []llm.Message, opts ...llm.Opt) (_ []llm.Vector, _ llm.Usage, err error)

Embed returns a vector for each of the messages, from the model's provider, which must be in the registry, and embed messages. Returns ErrNotImplemented when the model is known not to embed, and the provider's error as providerErr does.

func (*Registry) ForgetSessionMessages added in v1.0.0

func (r *Registry) ForgetSessionMessages(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)

ForgetSessionMessages forgets the messages of the session with the identifier, keeping its settings, so its conversation starts again, and returns it, without them. The tokens of its conversation are none, and the tokens used by every request to its model are kept. Returns ErrNotFound when there's none, ErrConflict when it was changed as they were forgotten, and ErrServiceUnavailable when the registry has no session store. A reply which is being waited for, as they're forgotten, isn't stored.

func (*Registry) GetAgent added in v0.6.0

func (r *Registry) GetAgent(ctx context.Context, name string) (_ *schema.Agent, err error)

GetAgent returns the agent with the name. Returns ErrNotFound when there's none, and ErrServiceUnavailable when the registry has no agent store.

func (*Registry) GetModel

func (r *Registry) GetModel(ctx context.Context, name string) (_ llm.Model, err error)

GetModel returns the model with the name, which is its canonical name, such as ollama:llama3.2:latest, which is its provider's name in the registry, and its name, or otherwise its name, or an alias, which every provider's models are searched for at once. A model must match its provider's patterns. The models are cached, as ListModels does. Returns ErrNotFound when no provider has it, and ErrConflict when more than one does, so its canonical name is needed. When no provider has it, and a provider can't be asked, such as when it can't be reached, that provider's error is returned.

func (*Registry) GetProvider

func (r *Registry) GetProvider(ctx context.Context, name string) (_ *schema.ProviderStatus, err error)

GetProvider returns the provider with the name, with whether it can be reached, when it was last pinged, within PingInterval, or ErrNotFound when there's none

func (*Registry) GetSession added in v0.6.0

func (r *Registry) GetSession(ctx context.Context, id uuid.UUID) (_ *schema.Session, err error)

GetSession returns the session with the identifier, without its messages, which ListSessionMessages lists. Returns ErrNotFound when there's none, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) ListAgents added in v0.6.0

func (r *Registry) ListAgents(ctx context.Context, req schema.AgentListRequest) (_ *schema.AgentList, err error)

ListAgents returns the agents, in the store's order, as the request selects. Returns ErrServiceUnavailable when the registry has no agent store.

func (*Registry) ListModels

func (r *Registry) ListModels(ctx context.Context, providers ...string) (_ []llm.Model, err error)

ListModels returns the models of every provider, or of the providers with the names, when there are any, which must exist, which match their patterns, in order of their providers' names, and then their names. The models are cached, and are listed again, at once, when they're stale. When a provider's models can't be listed, such as when it can't be reached, and none are cached, the others' models are returned, with an error saying which providers' couldn't be.

func (*Registry) ListProviders

func (r *Registry) ListProviders(ctx context.Context, req schema.ProviderListRequest) (_ *schema.ProviderList, err error)

ListProviders returns the providers, in order of their names, of the type which the request selects, or every type, which are pinged at once, so it's known which can't be reached

func (*Registry) ListSessionMessages added in v0.6.0

func (r *Registry) ListSessionMessages(ctx context.Context, id uuid.UUID, req schema.MessageListRequest) (_ *schema.MessageList, err error)

ListSessionMessages returns the messages of the session with the identifier, oldest first, as the request selects: of its role, or every role, from its offset, and at most its limit of them, and how many there are. Returns ErrNotFound when there's no session, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) ListSessions added in v0.6.0

func (r *Registry) ListSessions(ctx context.Context, req schema.SessionListRequest) (_ *schema.SessionList, err error)

ListSessions returns the sessions, without their messages, most recently modified first, as the request selects. Returns ErrServiceUnavailable when the registry has no session store.

func (*Registry) LoadModel

func (r *Registry) LoadModel(ctx context.Context, name string, progress llm.DownloadProgressFn) (_ llm.Model, err error)

LoadModel downloads the model with the name, with its provider, which must download models, and returns it. As the model may not exist yet, the name must be its canonical name, such as ollama:llama3.2:latest, unless only one of the providers downloads models.

func (*Registry) Measure added in v0.6.0

func (r *Registry) Measure(ctx context.Context, model llm.Model, text string) (_ uint, err error)

Measure returns how many tokens the text is, for the model, from the model's provider, which must be in the registry, when it measures text, or otherwise an estimate, of a token for every bytesPerToken bytes, or part of one. Returns the provider's error as providerErr does.

func (*Registry) Model

func (r *Registry) Model(model llm.Model) *schema.Model

Model returns the model, with the name of its provider in the registry, and its canonical name

func (*Registry) Name

func (r *Registry) Name(model llm.Model) string

Name returns the canonical name of the model, which is the name of its provider in the registry, and its name, such as my-ollama:llama3.2:latest, or its provider's own name, when its provider isn't in the registry

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the names of the providers, in order

func (*Registry) Ping

func (r *Registry) Ping(ctx context.Context) (err error)

Ping pings every provider at once, and returns when they've replied, with the errors of those which failed joined, each saying which provider it is, or nil when every ping succeeded. The providers are pinged, whenever they were last.

func (*Registry) Provider

func (r *Registry) Provider(name string) llm.Provider

Provider returns the provider with the name, or nil when there's none

func (*Registry) Providers

func (r *Registry) Providers() []llm.Provider

Providers returns the providers, in order of their names

func (*Registry) Recognize

func (r *Registry) Recognize(ctx context.Context, model llm.Model, resource llm.Resource, opts ...llm.Opt) (_ llm.Document, _ llm.Usage, err error)

Recognize returns the text in the resource, such as an image or a PDF, as a document, from the model's provider, which must be in the registry, and recognize text. Returns ErrNotImplemented when the model is known not to recognize text, and the provider's error as providerErr does.

func (*Registry) Remove

func (r *Registry) Remove(name string) (llm.Provider, error)

Remove removes the provider with the name, and returns it, so it can be closed, or returns ErrNotFound when there's none. Calls which have started already, such as listing models, still use it. Watchers are sent that it was deleted.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, logger *slog.Logger) error

Run keeps the registry current, until the context is cancelled, when it returns nil: it pings the providers, and lists the models of those whose models are stale, when it starts, and every PingInterval, so the providers' state, and their models, are kept current, and with a store, it syncs the registry's providers with the store's, when it starts, as either changes, and every PingInterval, as an event can be missed. The errors syncing them, which are synced again later, are logged with the logger, or aren't when it's nil. When the store stops, it returns its error. The registry is used without it, when its models are listed as they're needed. With a store of sessions, the changes others make to them, which it sends as events, are published as the registry's own. With a store of agents, and a toolkit, the stored agents are made tools, when it starts.

func (*Registry) RunAgent added in v0.6.0

func (r *Registry) RunAgent(ctx context.Context, name string, req schema.RunAgentRequest, stream llm.GeneratorStreamFn) (_ *schema.RunAgentResponse, err error)

RunAgent runs the agent with the name: the request's input is validated against its input schema, and its prompt is executed with it, as the message to its model, which is its own, or, when it has none, the model of the session it's run from, which is asked as its settings say, without its history, and runs the tools it calls, until it replies. Its reply is streamed to the function as it's generated, when it isn't nil. Returns what the agent did: the messages it added, the tokens used, and its reply, as JSON, which is its text, or what it replied, when it has a schema.

The agents which are running, as an agent calls another, or itself, as a tool, are in the context, with the most which can run in one another, which is the max_depth option of the session, or agent, which runs them, or the least of them, or DefaultMaxDepth, so an agent isn't run deeper, as agents could call one another without end.

Returns ErrNotFound when there's no agent with the name, or session, ErrForbidden when it would run deeper than the most agents which can run in one another, ErrBadParameter when its input isn't valid, or its prompt can't be executed with it, or it has no model, nor has the session it's run from, and ErrServiceUnavailable when the registry has no agent store, and the errors of WithSession.

func (*Registry) SessionStore added in v0.6.0

func (r *Registry) SessionStore() SessionStore

SessionStore returns the store of the registry's sessions, or nil when it has none, when it has no sessions

func (*Registry) SetSessionStatus added in v0.6.0

func (r *Registry) SetSessionStatus(ctx context.Context, id uuid.UUID, value schema.SessionStatus) (_ *schema.Session, err error)

SetSessionStatus sets the status of the session with the identifier, as a client says someone is typing a message, which it is until TypingTimeout after it was last said, or they stopped, when it's idle, unless its model is replying, which it is until it has replied. A change of the status is published as an update of the session. Returns the session, without its messages, with its status. Returns ErrBadParameter when the status isn't typing or idle, ErrNotFound when there's no session, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) Toolkit

func (r *Registry) Toolkit() *toolkit.Toolkit

Toolkit returns the toolkit of the tools which the registry's models can call, or nil when it has none

func (*Registry) Transcribe

func (r *Registry) Transcribe(ctx context.Context, model llm.Model, audio llm.Resource, stream llm.TranscriberStreamFn, opts ...llm.Opt) (_ llm.Transcript, _ llm.Usage, err error)

Transcribe returns the speech in the audio, from the model's provider, which must be in the registry, and transcribe audio, and streams its pieces to the function, when it isn't nil. Returns ErrNotImplemented when the model is known not to transcribe, and the provider's error as providerErr does.

func (*Registry) Translate

func (r *Registry) Translate(ctx context.Context, model llm.Model, audio llm.Resource, stream llm.TranscriberStreamFn, opts ...llm.Opt) (_ llm.Transcript, _ llm.Usage, err error)

Translate returns the speech in the audio as English text, from the model's provider, which must be in the registry, and transcribe audio. Returns ErrNotImplemented when the model can't translate, or is known not to, and the provider's error as providerErr does.

func (*Registry) UnloadModel

func (r *Registry) UnloadModel(ctx context.Context, model llm.Model) (err error)

UnloadModel unloads the model from memory, with its provider, which must be in the registry, and load models, keeping it stored, so its provider's models aren't listed again. Returns ErrNotImplemented when the provider doesn't load models, or can't unload them.

func (*Registry) UpdateAgent added in v0.6.0

func (r *Registry) UpdateAgent(ctx context.Context, name string, meta schema.AgentMeta) (_ *schema.Agent, err error)

UpdateAgent changes the definition of the agent with the name, as AgentMeta.Merge does: what the update sets is changed, its options are set, or removed, when they're null, and the rest is kept. Its name isn't changed: the update has no name, or the agent's, such as when it's the agent's whole definition. The definition, as changed, must be valid, as CreateAgent says, and a model, or tools, which are changed are the registry's, by their canonical names. Returns the agent. Returns ErrBadParameter when the update has another name, or changes nothing, or the definition, as changed, isn't valid, ErrNotFound when there's no agent, or the model, or a tool, isn't the registry's, ErrConflict when it was changed as it was updated, or a name is ambiguous, and ErrServiceUnavailable when the registry has no agent store.

func (*Registry) UpdateProvider

func (r *Registry) UpdateProvider(ctx context.Context, name string, meta schema.ProviderMeta) (_ *schema.ProviderStatus, err error)

UpdateProvider changes the provider with the name: its fields which can be set are replaced with the meta, apart from its API key, which is kept when the meta has none, as it isn't returned. Its type and name aren't changed. The provider is created again, as CreateProvider does, and replaces it, whether it can be reached or not, which it says, with its serial incremented, and watchers are sent that it was updated. A provider whose fields are the same is left as it is. Returns ErrNotFound when there's no provider with the name, ErrBadParameter when the meta isn't valid, and ErrConflict when the provider was added without a definition, such as with Add.

func (*Registry) UpdateSession added in v0.6.0

func (r *Registry) UpdateSession(ctx context.Context, id uuid.UUID, meta schema.SessionMeta) (_ *schema.Session, err error)

UpdateSession changes the settings of the session with the identifier, as SessionMeta.Merge does: what the update sets is changed, its options are set, or removed, when they're null, and the rest is kept, as are the session's messages. A model, or tools, which are changed are the registry's, by their canonical names, as CreateSession says. Returns the session. Returns ErrBadParameter when the update changes nothing, or the settings, as changed, aren't valid, ErrNotFound when there's no session, or the model, or a tool, isn't the registry's, ErrConflict when it was changed as it was updated, and ErrServiceUnavailable when the registry has no session store.

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, ch chan<- schema.Event) (<-chan error, error)

Watch sends the registry's broadcaster's events to the channel, as the broadcaster's Watch does. The registry's events are of providers: when one is created, or deleted, and updated, when whether it can be reached changes, or its models do, and of sessions: when one is created, deleted, or updated, as its settings change, messages are added to it, or its status changes. A broadcaster which others share sends their events too.

func (*Registry) WithSession added in v0.6.0

func (r *Registry) WithSession(ctx context.Context, session schema.Session, messages []llm.Message, stream llm.GeneratorStreamFn) (_ *schema.SessionResponse, err error)

WithSession asks the session's model, after its system prompt, with its options, tools and the schema of the reply, for its reply to the conversation, which is the session's messages, each with its tokens, when it has them, and the messages, as the agent loop does, which runs the tools the model calls. The messages can be any messages, which are kept as messages of the provider schema, with the data of their attachments read. Returns the messages to add to the session: the messages, and those the loop added, the last of which is the model's reply, each with its tokens; the tokens of the conversation, with them, of the messages sent to the model, of its replies, and of what's sent with them; and the usage. With a schema, the model's reply, when its result is stop, is JSON which conforms to it. The session isn't changed. The reply is streamed to the function as it's generated, when it isn't nil. Returns ErrBadParameter when the session, or the messages, aren't valid, ErrNotFound when the model, or a tool, isn't found, and the errors of AgentLoop.

func (*Registry) WithoutSession

func (r *Registry) WithoutSession(ctx context.Context, model llm.Model, messages []llm.Message, tools []llm.Tool, stream llm.GeneratorStreamFn, opts ...llm.Opt) (_ llm.Message, _ llm.Usage, err error)

WithoutSession returns the model's reply to the messages, from the model's provider, which must be in the registry, and generate messages, or the provider's error as providerErr does. Returns ErrNotImplemented, without asking the provider, when the model is known not to reply, or there are tools, and it's known not to call them, or it's asked to think, and it's known not to, or the messages have images, and it's known not to see them.

type SessionStore added in v0.6.0

type SessionStore interface {
	// Create creates a session with the settings, and no messages, and
	// returns it, with its identifier, serial, and when it was created
	Create(context.Context, schema.SessionMeta) (schema.Session, error)

	// Get returns the session with the identifier, with its messages.
	// Returns ErrNotFound when there's none.
	Get(ctx context.Context, id uuid.UUID) (schema.Session, error)

	// List returns the sessions, without their messages, most recently
	// modified first, from the request's offset, and at most its limit of
	// them, and how many there are
	List(context.Context, schema.SessionListRequest) (schema.SessionList, error)

	// Put replaces the session with its identifier, when its serial is that
	// session's, and returns it, with its new serial, and when it was
	// modified. Returns ErrNotFound when there's none, and ErrConflict when
	// its serial isn't the session's, as it was changed since it was seen.
	Put(context.Context, schema.Session) (schema.Session, error)

	// Delete deletes the session with the identifier, when the serial is its
	// serial, or does nothing when there's none. Returns ErrConflict when the
	// serial isn't its serial, as it was changed since it was seen.
	Delete(ctx context.Context, id uuid.UUID, serial uint64) error

	// Watch sends the store's events to the channel, when its sessions are
	// changed by others, such as other servers, from when it returns, until
	// the context is cancelled, as the registry's Watch does: the table is
	// SessionTable, the row the session's identifier, and when it was
	// created or updated, the data is its serial, as a SessionEvent. It
	// returns a channel which is sent nil, or an error when the store stops,
	// once the watch has ended. A store which isn't changed by others, such
	// as files which only its server writes, sends no events.
	Watch(context.Context, chan<- eventschema.Event) (<-chan error, error)
}

SessionStore has sessions, each with its identifier and serial, which the store sets, and changes each time the session is stored, so a change is made to the session as it was last seen, rather than a newer one, such as when two replies are added to it at once

Directories

Path Synopsis
cmd
Package cmd has the registry's commands and flags
Package cmd has the registry's commands and flags
tui
Package tui is a terminal interface to chat in a session, which is a throwaway, until there's a better one
Package tui is a terminal interface to chat in a session, which is a throwaway, until there's a better one
Package httpclient is a client of the registry's HTTP API
Package httpclient is a client of the registry's HTTP API
Package httphandler has the registry's HTTP API
Package httphandler has the registry's HTTP API
Package schema has the requests and responses of the registry's API
Package schema has the requests and responses of the registry's API
Package test has a registry and a HTTP server of its API, for tests
Package test has a registry and a HTTP server of its API, for tests

Jump to

Keyboard shortcuts

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