api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultModelKey = "genkit/defaultModel"
	PromptDirKey    = "genkit/promptDir"
)

Registry constants

Variables

This section is empty.

Functions

func NewKey

func NewKey(typ ActionType, provider, id string) string

NewKey creates a new action key for the given type, provider, and name.

func NewName

func NewName(provider, id string) string

NewName creates a new action name for the given provider and id.

func ParseName

func ParseName(name string) (string, string)

ParseName parses an action name into a provider and id.

Types

type Action

type Action interface {
	Registerable
	// Name returns the name of the action.
	Name() string
	// RunJSON runs the action with the given JSON input and streaming callback and returns the output as JSON.
	RunJSON(ctx context.Context, input json.RawMessage, cb func(context.Context, json.RawMessage) error) (json.RawMessage, error)
	// Desc returns a descriptor of the action.
	Desc() ActionDesc
}

Action is the interface that all Genkit primitives (e.g. flows, models, tools) have in common.

type ActionDesc

type ActionDesc struct {
	Type         ActionType     `json:"type"`         // Type of the action.
	Key          string         `json:"key"`          // Key of the action.
	Name         string         `json:"name"`         // Name of the action.
	Description  string         `json:"description"`  // Description of the action.
	InputSchema  map[string]any `json:"inputSchema"`  // JSON schema to validate against the action's input.
	OutputSchema map[string]any `json:"outputSchema"` // JSON schema to validate against the action's output.
	Metadata     map[string]any `json:"metadata"`     // Metadata for the action.
}

ActionDesc is a descriptor of an action.

type ActionType

type ActionType string

An ActionType is the kind of an action.

const (
	ActionTypeRetriever        ActionType = "retriever"
	ActionTypeIndexer          ActionType = "indexer"
	ActionTypeEmbedder         ActionType = "embedder"
	ActionTypeEvaluator        ActionType = "evaluator"
	ActionTypeFlow             ActionType = "flow"
	ActionTypeModel            ActionType = "model"
	ActionTypeExecutablePrompt ActionType = "executable-prompt"
	ActionTypeResource         ActionType = "resource"
	ActionTypeTool             ActionType = "tool"
	ActionTypeUtil             ActionType = "util"
	ActionTypeCustom           ActionType = "custom"
)

func ParseKey

func ParseKey(key string) (ActionType, string, string)

ParseKey parses an action key into a type, provider, and name.

type DynamicPlugin

type DynamicPlugin interface {
	Plugin
	// ListActions returns a list of action descriptors that the plugin is capable of resolving to [Action]s.
	ListActions(ctx context.Context) []ActionDesc
	// ResolveAction resolves an action type and name to a [Action].
	ResolveAction(atype ActionType, name string) Action
}

DynamicPlugin is a Plugin that can dynamically resolve actions.

type Environment

type Environment string

An Environment is the execution context in which the program is running.

const (
	EnvironmentDev  Environment = "dev"  // development: testing, debugging, etc.
	EnvironmentProd Environment = "prod" // production: user data, SLOs, etc.
)

func CurrentEnvironment

func CurrentEnvironment() Environment

CurrentEnvironment returns the currently active environment.

type Plugin

type Plugin interface {
	// Name returns the unique identifier for the plugin.
	// This name is used for registration and lookup.
	Name() string
	// Init initializes the plugin. It is called once during [Init].
	Init(ctx context.Context) []Action
}

Plugin is the interface implemented by types that extend Genkit's functionality. Plugins are typically used to integrate external services like model providers, vector databases, or monitoring tools. They are registered and initialized via [WithPlugins] during [Init].

type Registerable

type Registerable interface {
	Register(r Registry)
}

Registerable allows a primitive to be registered with a registry.

type Registry

type Registry interface {
	// NewChild creates a new child registry that inherits from this registry.
	// Child registries are cheap to create and will fall back to the parent
	// for lookups if a value is not found in the child.
	NewChild() Registry

	// IsChild returns true if the registry is a child of another registry.
	IsChild() bool

	// RegisterPlugin records the plugin in the registry.
	// It panics if a plugin with the same name is already registered.
	RegisterPlugin(name string, p Plugin)

	// RegisterAction records the action in the registry.
	// It panics if an action with the same type, provider and name is already
	// registered.
	RegisterAction(key string, action Action)

	// RegisterValue records an arbitrary value in the registry.
	// It panics if a value with the same name is already registered.
	RegisterValue(name string, value any)

	// LookupPlugin returns the plugin for the given name.
	// It first checks the current registry, then falls back to the parent if not found.
	// Returns nil if the plugin is not found in the registry hierarchy.
	LookupPlugin(name string) Plugin

	// LookupAction returns the action for the given key.
	// It first checks the current registry, then falls back to the parent if not found.
	LookupAction(key string) Action

	// LookupValue returns the value for the given name.
	// It first checks the current registry, then falls back to the parent if not found.
	// Returns nil if the value is not found in the registry hierarchy.
	LookupValue(name string) any

	// ResolveAction looks up an action by key. If the action is not found, it attempts dynamic resolution.
	// Returns the action if found, or nil if not found.
	ResolveAction(key string) Action

	// ListActions returns a list of all registered actions.
	// This includes actions from both the current registry and its parent hierarchy.
	// Child registry actions take precedence over parent actions with the same key.
	ListActions() []Action

	// ListPlugins returns a list of all registered plugins.
	ListPlugins() []Plugin

	// ListValues returns a list of values of all registered values.
	// This includes values from both the current registry and its parent hierarchy.
	// Child registry values take precedence over parent values with the same key.
	ListValues() map[string]any

	// RegisterPartial adds the partial to the list of partials to the dotprompt instance
	RegisterPartial(name string, source string)

	// RegisterHelper adds a helper function to the dotprompt instance
	RegisterHelper(name string, fn any)

	// Dotprompt returns the dotprompt instance.
	Dotprompt() *dotprompt.Dotprompt
}

Registry holds all registered actions and associated types, and provides methods to register, query, and look up actions.

Jump to

Keyboard shortcuts

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