agent

package
v0.0.0-...-9be4777 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ExecutionModeRegular routes the profile through the built-in runtime agent.
	ExecutionModeRegular = ap.ExecutionModeRegular
	// ExecutionModeACPStdio routes the profile through an ACP-compatible stdio command.
	ExecutionModeACPStdio = ap.ExecutionModeACPStdio
)

Variables

View Source
var ErrAgentProfileNameConflict = ap.ErrAgentProfileNameConflict

ErrAgentProfileNameConflict is returned when a profile with the given name already exists.

View Source
var ErrAgentProfileNotFound = ap.ErrAgentProfileNotFound

ErrAgentProfileNotFound is returned when a profile with the given name does not exist.

Functions

This section is empty.

Types

type ACPStdioAgentCommand

type ACPStdioAgentCommand = ap.ACPStdioAgentCommand

ACPStdioAgentCommand stores command defaults used to launch an ACP stdio agent.

type AgentProfile

type AgentProfile = ap.AgentProfile

AgentProfile is a persisted general-purpose agent profile definition.

type AgentProfilesService

type AgentProfilesService = ap.AgentProfilesService

AgentProfilesService manages persisted agent profiles.

func NewDatabaseAgentProfilesService

func NewDatabaseAgentProfilesService(
	dsn string,
	logger *slog.Logger,
	tablePrefix string,
) (AgentProfilesService, error)

NewDatabaseAgentProfilesService creates a database-backed AgentProfilesService that stores profile definitions in a relational database identified by the given DSN. tablePrefix sets the prefix for persisted SQL table names; empty means no prefix.

func NewFileAgentProfilesService

func NewFileAgentProfilesService(
	baseDir string,
	logger *slog.Logger,
) (AgentProfilesService, error)

NewFileAgentProfilesService creates a file-based AgentProfilesService that stores profile definitions as YAML files under {baseDir}/agent-profiles/{name}.yaml.

type AgentRunner

type AgentRunner interface {
	Run(ctx context.Context, params RunParams) (*RunResult, error)
	ReadSession(ctx context.Context, params ReadSessionParams) (*ReadSessionResult, error)
	ListSessions(ctx context.Context, params ListSessionsParams) (*ListSessionsResult, error)
}

AgentRunner is the embedder-facing contract for agent runs, session reads, and session listing. Session listing returns paginated SessionMetadata via ListSessionsResult. *Runner implements it; internal adapters such as the background runner satisfy it as well.

type CreateAgentProfileParams

type CreateAgentProfileParams = ap.CreateAgentProfileParams

CreateAgentProfileParams contains parameters required to create a profile.

type CreateProviderConfigParams

type CreateProviderConfigParams = lp.CreateProviderConfigParams

CreateProviderConfigParams holds the parameters for creating a new provider config.

type DefinedTool

type DefinedTool interface {
	// contains filtered or unexported methods
}

type ExecutionMode

type ExecutionMode = ap.ExecutionMode

ExecutionMode identifies how a profile executes.

type ExecutionSettings

type ExecutionSettings = ap.ExecutionSettings

ExecutionSettings stores runtime-owned execution defaults for a profile.

type ListSessionsParams

type ListSessionsParams = internal.ListSessionMetadataParams

ListSessionsParams filters and paginates session metadata for the configured app.

type ListSessionsResult

type ListSessionsResult = internal.ListSessionMetadataResult

ListSessionsResult is a page of session metadata plus total count for pagination.

type MockAgentRunner

type MockAgentRunner struct {
	mock.Mock
}

MockAgentRunner is an autogenerated mock type for the AgentRunner type

func NewMockAgentRunner

func NewMockAgentRunner(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAgentRunner

NewMockAgentRunner creates a new instance of MockAgentRunner. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAgentRunner) EXPECT

func (*MockAgentRunner) ListSessions

func (_mock *MockAgentRunner) ListSessions(ctx context.Context, params ListSessionsParams) (*ListSessionsResult, error)

ListSessions provides a mock function for the type MockAgentRunner

func (*MockAgentRunner) ReadSession

func (_mock *MockAgentRunner) ReadSession(ctx context.Context, params ReadSessionParams) (*ReadSessionResult, error)

ReadSession provides a mock function for the type MockAgentRunner

func (*MockAgentRunner) Run

func (_mock *MockAgentRunner) Run(ctx context.Context, params RunParams) (*RunResult, error)

Run provides a mock function for the type MockAgentRunner

type MockAgentRunner_Expecter

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

func (*MockAgentRunner_Expecter) ListSessions

func (_e *MockAgentRunner_Expecter) ListSessions(ctx interface{}, params interface{}) *MockAgentRunner_ListSessions_Call

ListSessions is a helper method to define mock.On call

  • ctx context.Context
  • params ListSessionsParams

func (*MockAgentRunner_Expecter) ReadSession

func (_e *MockAgentRunner_Expecter) ReadSession(ctx interface{}, params interface{}) *MockAgentRunner_ReadSession_Call

ReadSession is a helper method to define mock.On call

  • ctx context.Context
  • params ReadSessionParams

func (*MockAgentRunner_Expecter) Run

func (_e *MockAgentRunner_Expecter) Run(ctx interface{}, params interface{}) *MockAgentRunner_Run_Call

Run is a helper method to define mock.On call

  • ctx context.Context
  • params RunParams

type MockAgentRunner_ListSessions_Call

type MockAgentRunner_ListSessions_Call struct {
	*mock.Call
}

MockAgentRunner_ListSessions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListSessions'

func (*MockAgentRunner_ListSessions_Call) Return

func (*MockAgentRunner_ListSessions_Call) Run

func (*MockAgentRunner_ListSessions_Call) RunAndReturn

type MockAgentRunner_ReadSession_Call

type MockAgentRunner_ReadSession_Call struct {
	*mock.Call
}

MockAgentRunner_ReadSession_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReadSession'

func (*MockAgentRunner_ReadSession_Call) Return

func (*MockAgentRunner_ReadSession_Call) Run

func (*MockAgentRunner_ReadSession_Call) RunAndReturn

type MockAgentRunner_Run_Call

type MockAgentRunner_Run_Call struct {
	*mock.Call
}

MockAgentRunner_Run_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Run'

func (*MockAgentRunner_Run_Call) Return

func (*MockAgentRunner_Run_Call) Run

func (*MockAgentRunner_Run_Call) RunAndReturn

func (_c *MockAgentRunner_Run_Call) RunAndReturn(run func(ctx context.Context, params RunParams) (*RunResult, error)) *MockAgentRunner_Run_Call

type ModelConfig

type ModelConfig = lp.ModelConfig

ModelConfig represents a single model available through a provider.

type ModelInfo

type ModelInfo = internal.ModelInfo

ModelInfo describes a single model available through a provider.

type ModelsLister

type ModelsLister interface {
	ListModels(ctx context.Context) ([]ModelInfo, error)
}

ModelsLister lists available models across all configured providers. *Runner.ModelsLocator returns a value satisfying this interface for runners constructed with NewRunner and a non-nil [RunnerArgs.ProvidersConfigService].

type OpenAICompatibleLLMProviderArgs

type OpenAICompatibleLLMProviderArgs struct {
	// Name is the name of the provider.
	// This will be used as a prefix for model names (e.g., "myprovider/model-name").
	Name string

	// APIKey is the API key to use with the provider.
	APIKey string `json:"-"`

	// BaseURL is the base URL to use with the provider.
	BaseURL string
}

type OpenAICompatibleLLMProviderOpt

type OpenAICompatibleLLMProviderOpt func(*oai.OpenAICompatible)

func OpenAIWithHTTPClient

func OpenAIWithHTTPClient(client *http.Client) OpenAICompatibleLLMProviderOpt

OpenAIWithHTTPClient sets the HTTP client to use with the provider.

type Provider

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

Provider allows defining various LLM providers.

type ProvidersConfigService

type ProvidersConfigService = lp.ProvidersConfigService

ProvidersConfigService is the provider configuration management contract.

func NewDatabaseProvidersConfigService

func NewDatabaseProvidersConfigService(
	dsn string,
	logger *slog.Logger,
	tablePrefix string,
) (ProvidersConfigService, error)

NewDatabaseProvidersConfigService creates a database-backed ProvidersConfigService that stores provider configurations in a relational database identified by the given DSN. tablePrefix sets the prefix for persisted SQL table names; empty means no prefix.

func NewFileProvidersConfigService

func NewFileProvidersConfigService(
	baseDir string,
	logger *slog.Logger,
) (ProvidersConfigService, error)

NewFileProvidersConfigService creates a file-based ProvidersConfigService that stores provider configurations as YAML files under {baseDir}/providers/ (canonical {name}.yaml; optional same-named {name}.yml for discovery and reads).

type ReadSessionParams

type ReadSessionParams = internal.ReadSessionParams

type ReadSessionResult

type ReadSessionResult = internal.ReadSessionResult

type RunParams

type RunParams = internal.RunParams

type RunParamsBuilder

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

RunParamsBuilder constructs RunParams for Runner.Run with required user identity and model.

func NewRunParams

func NewRunParams(userID, sessionID, model string) RunParamsBuilder

NewRunParams starts a builder with userID, sessionID, and fully qualified model ("provider/model-name").

func (RunParamsBuilder) WithText

func (b RunParamsBuilder) WithText(text string) RunParams

WithText sets the user message to a single text part and returns the final RunParams.

type RunResult

type RunResult = internal.RunResult

type Runner

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

func NewRunner

func NewRunner(args RunnerArgs, opts ...RunnerOpt) (*Runner, error)

func (*Runner) AutoMigrate

func (r *Runner) AutoMigrate() error

AutoMigrate runs schema migrations for database-backed session storage when configured. It is a no-op when file or in-memory storage is in use. Call this once after constructing the runner and before serving requests.

func (*Runner) ListSessions

func (r *Runner) ListSessions(ctx context.Context, params ListSessionsParams) (*ListSessionsResult, error)

ListSessions returns a page of session metadata for the configured app and user. AppName in params is ignored; the runner uses its fixed app name (same as Run and ReadSession).

func (*Runner) ModelsLocator

func (r *Runner) ModelsLocator() ModelsLister

ModelsLocator returns the runner's [ModelsLocator] for listing models (e.g. GET /models). The returned value satisfies ModelsLister and can be passed to [httpapi.HandlerArgs.ModelsLister].

func (*Runner) ReadSession

func (r *Runner) ReadSession(ctx context.Context, params ReadSessionParams) (*ReadSessionResult, error)

ReadSession reads the events for a session from the configured session service.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, params RunParams) (*RunResult, error)

type RunnerArgs

type RunnerArgs struct {
	// ProvidersConfigService is required. NewRunner wires a ModelsLocator for LLM resolution.
	ProvidersConfigService ProvidersConfigService
	// AgentProfilesService is required. NewRunner wires profile-backed execution from it.
	AgentProfilesService AgentProfilesService
	// contains filtered or unexported fields
}

type RunnerOpt

type RunnerOpt func(*runnerOpts)

func WithDatabaseStorage

func WithDatabaseStorage(dsn string) RunnerOpt

WithDatabaseStorage configures the runner to persist session state in a database identified by dsn. When this option is omitted, storage defaults to in-memory. WithDatabaseStorage and WithFileSystemStorage are mutually exclusive; the last one set wins.

func WithDatabaseTablePrefix

func WithDatabaseTablePrefix(prefix string) RunnerOpt

WithDatabaseTablePrefix sets the SQL table name prefix used when database-backed session storage is enabled. When empty, no prefix is applied. This option has no effect when storage is not database-backed.

func WithFileSystemStorage

func WithFileSystemStorage(baseDir string) RunnerOpt

WithFileSystemStorage configures the runner to persist state under baseDir on disk. The directory is created if it does not exist. When this option is omitted, storage is in-memory only. If WithFileSystemStorage is passed multiple times, the last call wins. WithFileSystemStorage and WithDatabaseStorage are mutually exclusive; the last one set wins.

func WithLogger

func WithLogger(logger *slog.Logger) RunnerOpt

WithLogger sets the logger to use for the runner.

func WithSystemPromptFragments

func WithSystemPromptFragments(fragments ...SystemPromptFragment) RunnerOpt

WithSystemPromptFragments appends extra system prompt sections after the base template and the default assistant instruction fragment. Multiple calls append in order.

func WithToolsRegistry

func WithToolsRegistry(reg *ToolsRegistry) RunnerOpt

WithToolsRegistry sets an optional tools registry. When non-nil, Genkit tool stubs are registered on each provider Genkit instance as models are resolved, and ADK tools are supplied from the registry.

type SessionMetadata

type SessionMetadata = internal.SessionMetadata

SessionMetadata is lightweight session listing data (id, title, timestamps).

type SystemPromptFragment

type SystemPromptFragment = internal.SystemPromptFragment

SystemPromptFragment is an extra section appended after the runtime base system prompt.

type ToolContext

type ToolContext struct {
	context.Context
	// contains filtered or unexported fields
}

ToolContext is the invocation context passed to agent tool handlers. It is created only inside this package (ADK bridge or test-only helpers). It embeds context.Context so a *ToolContext may be passed where a context.Context is required. ADK-specific state is not exposed on the public type.

type ToolDef

type ToolDef[TArgs, TResults any] struct {
	Name        string
	Description string
	Handler     func(ctx *ToolContext, input TArgs) (TResults, error)
	// contains filtered or unexported fields
}

ToolDef is a generic tool definition for LLM agents with typed args and results.

func NewToolDef

func NewToolDef[TArgs, TResults any](
	name, description string,
	handler func(ctx *ToolContext, input TArgs) (TResults, error),
) ToolDef[TArgs, TResults]

func (ToolDef[TArgs, TResults]) WithOutputSchema

func (t ToolDef[TArgs, TResults]) WithOutputSchema(schemaJSON []byte) ToolDef[TArgs, TResults]

WithOutputSchema returns a copy of the tool definition with a custom output schema provided as raw JSON bytes. Use this when the output type cannot be inferred automatically (e.g., recursive types that would cause cycle-detection errors).

type ToolsRegistry

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

ToolsRegistry allows to register tools available to the agent.

func NewToolsRegistry

func NewToolsRegistry() *ToolsRegistry

NewToolsRegistry creates a new ToolsRegistry.

func (*ToolsRegistry) AddTools

func (r *ToolsRegistry) AddTools(tools ...DefinedTool)

type UpdateAgentProfileParams

type UpdateAgentProfileParams = ap.UpdateAgentProfileParams

UpdateAgentProfileParams contains mutable parameters for profile updates.

Jump to

Keyboard shortcuts

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