Documentation
¶
Overview ¶
Package extension composes trusted, application-compiled Agent extensions into immutable runtime generations.
An Extension prepares declarative contributions. A Runtime validates the complete set, starts its lifecycles, and only then atomically publishes a Snapshot. Acquired Activations pin their generation until Release, so a reload never mutates an in-flight Agent or Harness.
This package is not a dynamic code loader or a process sandbox. Embedding applications decide which Go Extensions are compiled and registered.
Index ¶
- Variables
- type Activation
- type Asset
- type AssetEntry
- type Capabilities
- type Capability
- type Contribution
- type Definition
- type Descriptor
- type Diagnostic
- type Extension
- type Hooks
- type Lifecycle
- type Option
- type Origin
- type PromptEntry
- type Runtime
- func (r *Runtime) Acquire() (*Activation, error)
- func (r *Runtime) Activate(ctx context.Context, extensions ...Extension) (*Activation, error)
- func (r *Runtime) Capabilities() Capabilities
- func (r *Runtime) Resolve(ids ...string) ([]Extension, error)
- func (r *Runtime) Shutdown(ctx context.Context) error
- type Severity
- type SkillEntry
- type Snapshot
- func (s Snapshot) AgentOptions(ctx context.Context, policy catalog.Policy) ([]agent.Option, error)
- func (s Snapshot) Assets() []AssetEntry
- func (s Snapshot) Catalog() *catalog.Catalog
- func (s Snapshot) Descriptors() []Descriptor
- func (s Snapshot) Diagnostics() []Diagnostic
- func (s Snapshot) Generation() uint64
- func (s Snapshot) HarnessOptions(ctx context.Context, policy catalog.Policy) ([]harness.Option, error)
- func (s Snapshot) Hooks() Hooks
- func (s Snapshot) Model(model ai.LanguageModel) ai.LanguageModel
- func (s Snapshot) PromptEntries() []PromptEntry
- func (s Snapshot) Prompts() []harness.PromptTemplate
- func (s Snapshot) SkillEntries() []SkillEntry
- func (s Snapshot) Skills() []harness.Skill
- type Tool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalid reports an invalid descriptor, contribution, or runtime // configuration. ErrInvalid = errors.New("extension: invalid") // the Runtime. ErrCapabilityUnavailable = errors.New("extension: capability unavailable") // ErrNotRegistered reports a requested Extension ID absent from the // Runtime's immutable registry. ErrNotRegistered = errors.New("extension: not registered") // ErrNotActive reports an Acquire call before the first successful // activation. ErrNotActive = errors.New("extension: not active") // ErrClosed reports an operation attempted after Runtime.Shutdown. ErrClosed = errors.New("extension: runtime closed") )
Functions ¶
This section is empty.
Types ¶
type Activation ¶
type Activation struct {
// contains filtered or unexported fields
}
Activation is a lease on one immutable Extension generation.
func (*Activation) Release ¶
func (a *Activation) Release(ctx context.Context) error
Release drops this generation lease. A retired generation's lifecycles stop in reverse order when its final lease is released. Release is idempotent.
func (*Activation) Snapshot ¶
func (a *Activation) Snapshot() Snapshot
Snapshot returns a defensive immutable view of the leased generation.
type Asset ¶
Asset is opaque, typed data for an optional application adapter. Core extension code never interprets or executes its Data.
type AssetEntry ¶
AssetEntry attaches immutable Extension provenance to an Asset.
type Capabilities ¶
type Capabilities struct {
// contains filtered or unexported fields
}
Capabilities is an immutable set of feature names. Its zero value is an empty set.
func NewCapabilities ¶
func NewCapabilities(values ...Capability) Capabilities
NewCapabilities creates a set, ignoring duplicate values.
func (Capabilities) Has ¶
func (c Capabilities) Has(capability Capability) bool
Has reports whether capability is present.
func (Capabilities) List ¶
func (c Capabilities) List() []Capability
List returns sorted capability names.
type Capability ¶
type Capability string
Capability is one stable feature name understood by a Runtime or Bundle.
const ( CapabilityTools Capability = "agent.tools" CapabilityHooks Capability = "agent.hooks" CapabilitySkills Capability = "harness.skills" CapabilityPrompts Capability = "harness.prompts" CapabilityMiddleware Capability = "ai.middleware" CapabilityLifecycle Capability = "extension.lifecycle" CapabilityTypedAssets Capability = "extension.assets" )
Capabilities implemented directly by this package.
type Contribution ¶
type Contribution struct {
Tools []Tool
Skills []harness.Skill
Prompts []harness.PromptTemplate
Assets []Asset
Middleware []ai.Middleware
Hooks Hooks
Lifecycle Lifecycle
}
Contribution is the complete declarative output of one Extension.
type Definition ¶
type Definition struct {
// contains filtered or unexported fields
}
Definition is a function-backed Extension for small integrations and declarative Bundle resources.
func NewDefinition ¶
func NewDefinition( descriptor Descriptor, prepare func(context.Context) (Contribution, error), ) (*Definition, error)
NewDefinition validates descriptor and creates a function-backed Extension.
func (*Definition) Descriptor ¶
func (d *Definition) Descriptor() Descriptor
Descriptor returns a defensive copy of the Extension metadata.
func (*Definition) Prepare ¶
func (d *Definition) Prepare(ctx context.Context) (Contribution, error)
Prepare invokes the configured contribution function.
type Descriptor ¶
type Descriptor struct {
ID string
Version string
Requires []Capability
Optional []Capability
}
Descriptor identifies one compiled Extension and its capability contract.
type Diagnostic ¶
type Diagnostic struct {
Severity Severity
Origin Origin
Capability Capability
Message string
}
Diagnostic reports an optional capability or resource condition that did not prevent activation.
type Extension ¶
type Extension interface {
Descriptor() Descriptor
Prepare(context.Context) (Contribution, error)
}
Extension prepares one declarative Contribution. Prepare must not start long-lived resources; use Contribution.Lifecycle for that work.
type Hooks ¶
type Hooks struct {
Observe func(context.Context, agent.Event)
BeforeTool func(context.Context, agent.ToolCallInfo) agent.ToolDecision
AfterTool func(context.Context, agent.ToolResultInfo) *agent.ToolResultOverride
PrepareTurn func(context.Context, agent.RunInfo) agent.TurnUpdate
TransformContext func(context.Context, []ai.Message) ([]ai.Message, error)
}
Hooks are the Agent lifecycle functions contributed by an Extension. ComposeHooks defines their deterministic composition semantics.
func ComposeHooks ¶
ComposeHooks combines Hook sets in argument order. Observers fan out; gates stop at the first non-Allow decision; mutators form ordered pipelines.
func (Hooks) AgentOptions ¶
AgentOptions returns one Agent option for each configured Hook family.
type Option ¶
type Option func(*config) error
Option configures a Runtime.
func WithCapabilities ¶
func WithCapabilities(capabilities ...Capability) Option
WithCapabilities adds application-specific capability names used during Extension negotiation.
func WithExtensions ¶
WithExtensions registers trusted, application-compiled Extensions. The registry is immutable after New returns.
type PromptEntry ¶
type PromptEntry struct {
Origin Origin
Template harness.PromptTemplate
}
PromptEntry attaches immutable Extension provenance to a prompt template.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime validates and atomically publishes immutable Extension generations. It is safe for concurrent Acquire and activation, creates no goroutines, and never invokes Extension callbacks while holding its state mutex.
Example ¶
package main
import (
"context"
"fmt"
"github.com/rsbin1178/pips/agent/extension"
"github.com/rsbin1178/pips/agent/harness"
)
func main() {
ctx := context.Background()
review, _ := extension.NewDefinition(extension.Descriptor{
ID: "review",
Version: "1.0.0",
}, func(context.Context) (extension.Contribution, error) {
return extension.Contribution{Skills: []harness.Skill{{
Name: "review",
Description: "Review a code change.",
Content: "Review carefully.",
}}}, nil
})
runtime, _ := extension.New()
activation, _ := runtime.Activate(ctx, review)
snapshot := activation.Snapshot()
fmt.Println(snapshot.Generation(), snapshot.Descriptors()[0].ID, snapshot.Skills()[0].Name)
_ = activation.Release(ctx)
_ = runtime.Shutdown(ctx)
}
Output: 1 review review
func (*Runtime) Acquire ¶
func (r *Runtime) Acquire() (*Activation, error)
Acquire leases the current generation. Release the returned Activation when its Agent or Harness run has finished.
func (*Runtime) Activate ¶
Activate prepares, validates, starts, and publishes one complete generation. The returned Activation is a lease and must be released. When retirement of an unleased prior generation fails, both the installed Activation and a cleanup error are returned.
func (*Runtime) Capabilities ¶
func (r *Runtime) Capabilities() Capabilities
Capabilities returns the immutable Runtime capability set.
type SkillEntry ¶
SkillEntry attaches immutable Extension provenance to a Harness Skill.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is an immutable view of one successfully activated generation. Keep the Activation that produced it leased until every user of the Snapshot has finished.
func (Snapshot) AgentOptions ¶
func (s Snapshot) AgentOptions( ctx context.Context, policy catalog.Policy, ) ([]agent.Option, error)
AgentOptions authorizes Extension tools and returns the complete Agent option set for this Snapshot.
func (Snapshot) Assets ¶
func (s Snapshot) Assets() []AssetEntry
Assets returns opaque typed assets with Extension provenance and defensive copies of their data.
func (Snapshot) Descriptors ¶
func (s Snapshot) Descriptors() []Descriptor
Descriptors returns the activated Extension descriptors in registration order.
func (Snapshot) Diagnostics ¶
func (s Snapshot) Diagnostics() []Diagnostic
Diagnostics returns non-fatal activation diagnostics.
func (Snapshot) Generation ¶
Generation returns the monotonically increasing Runtime generation.
func (Snapshot) HarnessOptions ¶
func (s Snapshot) HarnessOptions( ctx context.Context, policy catalog.Policy, ) ([]harness.Option, error)
HarnessOptions authorizes Extension tools and returns Harness resources and Agent hooks. The Harness owns its event recorder, so observers are installed through harness.WithOnEvent rather than agent.WithOnEvent.
func (Snapshot) Model ¶
func (s Snapshot) Model(model ai.LanguageModel) ai.LanguageModel
Model wraps model with activated AI middleware in registration order.
func (Snapshot) PromptEntries ¶
func (s Snapshot) PromptEntries() []PromptEntry
PromptEntries returns prompt templates with Extension provenance.
func (Snapshot) Prompts ¶
func (s Snapshot) Prompts() []harness.PromptTemplate
Prompts returns the activated prompt templates without provenance wrappers.
func (Snapshot) SkillEntries ¶
func (s Snapshot) SkillEntries() []SkillEntry
SkillEntries returns activated Skills with Extension provenance.