Documentation
¶
Overview ¶
Package bedrockagentcore emulates the Amazon Bedrock AgentCore data plane: agent runtime invocation, memory events and records, code interpreter and browser sessions, and workload identity tokens.
Index ¶
- Constants
- Variables
- type AccessToken
- type ConfigProvider
- type ContainerRuntime
- type Control
- type EngineConfig
- type Event
- type HTTPDoer
- type Handler
- func (h *Handler) ChaosOperations() []string
- func (h *Handler) ChaosRegions() []string
- func (h *Handler) ChaosServiceName() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(_ context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type InMemoryBackend
- func (b *InMemoryBackend) Close()
- func (b *InMemoryBackend) EnableEngine(cfg EngineConfig)
- func (b *InMemoryBackend) EngineEnabled() bool
- func (b *InMemoryBackend) ReapIdle()
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetControl(c Control)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- type MemoryInfo
- type MemoryRecord
- type Provider
- type ProviderInfo
- type ProviderKind
- type RuntimeInfo
- type Scope
- type Settings
- type StrategyInfo
- type ToolInfo
- type ToolKind
- type ToolSession
Constants ¶
const ( // EngineAuto runs containers when a container runtime is reachable. EngineAuto = "auto" // EngineNone never starts containers; invocations that need one fail. EngineNone = "none" )
Variables ¶
var ( ErrNotFound = errors.New("resource not found") ErrNotReady = errors.New("resource is not ready") )
Errors a Control reports for runtime lookups.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type AccessToken struct {
Expires time.Time `json:"expires"`
Token string `json:"token"`
Account string `json:"account"`
Region string `json:"region"`
Workload string `json:"workload"`
UserID string `json:"userId,omitempty"`
}
AccessToken is an issued workload access token.
type ConfigProvider ¶
ConfigProvider extracts AgentCore data-plane configuration from the AppContext Config.
type ContainerRuntime ¶
type ContainerRuntime interface {
CreateAndStart(ctx context.Context, spec container.Spec) (string, error)
StopAndRemove(ctx context.Context, containerID string) error
Exec(ctx context.Context, containerID string, cmd []string) (container.ExecResult, error)
}
ContainerRuntime is the slice of container.Runtime the engine uses.
type Control ¶
type Control interface {
Runtime(sc Scope, ref, qualifier string) (RuntimeInfo, error)
Memory(sc Scope, id string) (MemoryInfo, bool)
Tool(sc Scope, kind ToolKind, id string) (ToolInfo, bool)
WorkloadIdentity(sc Scope, name string) bool
Provider(sc Scope, kind ProviderKind, name string) (ProviderInfo, bool)
SecretValue(arn, jsonKey string) (string, bool)
}
Control resolves the control-plane resources the data plane operates on.
type EngineConfig ¶
type EngineConfig struct {
Runtime ContainerRuntime
// Ports hands out host ports for runtime containers; nil picks free OS ports.
Ports *portalloc.Allocator
// HTTP reaches agent containers; nil uses an isolated client.
HTTP HTTPDoer
// Host is the address published container ports are reached on; default 127.0.0.1.
Host string
// EndpointURL is the gopherstack URL as seen from containers (AWS_ENDPOINT_URL).
EndpointURL string
// RegistryHost, when set, replaces the host of ECR image URIs so images are pulled from the emulated registry.
RegistryHost string
// PythonImage is the code interpreter sandbox image.
PythonImage string
// StartTimeout bounds boot until a runtime container answers its health check.
StartTimeout time.Duration
PollInterval time.Duration
StopTimeout time.Duration
// IdleTimeout applies to runtimes that set no idleRuntimeSessionTimeout.
IdleTimeout time.Duration
}
EngineConfig configures container-backed runtimes and sandboxes.
type Event ¶
type Event struct {
Timestamp time.Time `json:"timestamp"`
Metadata map[string]any `json:"metadata,omitempty"`
Branch map[string]any `json:"branch,omitempty"`
Account string `json:"account"`
Region string `json:"region"`
MemoryID string `json:"memoryId"`
ActorID string `json:"actorId"`
SessionID string `json:"sessionId"`
EventID string `json:"eventId"`
ClientToken string `json:"clientToken,omitempty"`
Payload []any `json:"payload"`
Seq uint64 `json:"seq"`
}
Event is one memory event of an actor session.
type Handler ¶
type Handler struct {
Backend *InMemoryBackend
DefaultRegion string
// contains filtered or unexported fields
}
Handler serves the AgentCore data-plane REST API.
func (*Handler) ChaosOperations ¶
ChaosOperations lists the fault-injectable operations.
func (*Handler) ChaosRegions ¶
ChaosRegions lists the regions this handler serves.
func (*Handler) ChaosServiceName ¶
ChaosServiceName returns the lowercase service name for fault rules.
func (*Handler) ExtractOperation ¶
ExtractOperation returns the operation name.
func (*Handler) ExtractResource ¶
ExtractResource returns the memory, runtime or tool the request addresses.
func (*Handler) GetSupportedOperations ¶
GetSupportedOperations lists every implemented operation.
func (*Handler) Handler ¶
func (h *Handler) Handler() echo.HandlerFunc
Handler returns the echo handler.
func (*Handler) MatchPriority ¶
MatchPriority returns the routing priority.
func (*Handler) RouteMatcher ¶
RouteMatcher matches by SigV4 signing name (or the data-plane SDK user agent) plus a known path shape.
type InMemoryBackend ¶
type InMemoryBackend struct {
// contains filtered or unexported fields
}
InMemoryBackend is the AgentCore data-plane state; one coarse lock guards every table.
func NewInMemoryBackend ¶
func NewInMemoryBackend(accountID, region string) *InMemoryBackend
NewInMemoryBackend creates an empty backend.
func (*InMemoryBackend) Close ¶
func (b *InMemoryBackend) Close()
Close stops every runtime container and sandbox.
func (*InMemoryBackend) EnableEngine ¶
func (b *InMemoryBackend) EnableEngine(cfg EngineConfig)
EnableEngine switches the backend to container-backed runtimes and sandboxes. Call it before serving.
func (*InMemoryBackend) EngineEnabled ¶
func (b *InMemoryBackend) EngineEnabled() bool
EngineEnabled reports whether containers can be started.
func (*InMemoryBackend) ReapIdle ¶
func (b *InMemoryBackend) ReapIdle()
ReapIdle stops runtime sessions idle past their timeout and terminates expired tool sessions.
func (*InMemoryBackend) Reset ¶
func (b *InMemoryBackend) Reset()
Reset clears all state and stops every running runtime session and sandbox.
func (*InMemoryBackend) Restore ¶
func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
Restore loads a snapshot; an incompatible version is discarded. Sessions that were READY come back TERMINATED because their sandboxes did not survive the restart.
func (*InMemoryBackend) SetClock ¶
func (b *InMemoryBackend) SetClock(now func() time.Time)
SetClock replaces the time source, which drives idle expiry and token lifetimes.
func (*InMemoryBackend) SetControl ¶
func (b *InMemoryBackend) SetControl(c Control)
SetControl wires the control plane the data plane resolves resources from.
type MemoryInfo ¶
type MemoryInfo struct {
ID string
Strategies []StrategyInfo
ExpiryDays int
}
MemoryInfo is the control-plane definition of a memory.
type MemoryRecord ¶
type MemoryRecord struct {
Created time.Time `json:"created"`
Metadata map[string]any `json:"metadata,omitempty"`
Account string `json:"account"`
Region string `json:"region"`
MemoryID string `json:"memoryId"`
ID string `json:"id"`
StrategyID string `json:"strategyId,omitempty"`
Text string `json:"text"`
Namespaces []string `json:"namespaces"`
Seq uint64 `json:"seq"`
}
MemoryRecord is a long-term memory record.
type Provider ¶
type Provider struct{}
Provider implements service.Provider for the Bedrock AgentCore data plane.
func (*Provider) Init ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init builds the backend and handler, and enables containers when a runtime is reachable.
type ProviderInfo ¶
type ProviderInfo struct {
Config map[string]any
Name string
Vendor string
SecretARN string
SecretJSONID string
}
ProviderInfo is a credential provider with the references needed to resolve its secrets.
type ProviderKind ¶
type ProviderKind string
ProviderKind selects a credential provider family.
const ( ProviderAPIKey ProviderKind = "apiKey" ProviderOAuth2 ProviderKind = "oauth2" )
Credential provider families.
type RuntimeInfo ¶
type RuntimeInfo struct {
Env map[string]string
ID string
ImageURI string
Protocol string
IdleSeconds int
MaxLifetimeS int
}
RuntimeInfo is the deployable view of an agent runtime endpoint.
type Scope ¶
type Scope struct{ Account, Region string }
Scope identifies the account and Region a request operates in.
type Settings ¶
type Settings struct {
Engine string `` //nolint:lll // config struct tags are intentionally verbose
/* 218-byte string literal not displayed */
RegistryHost string `` //nolint:lll // config struct tags are intentionally verbose
/* 230-byte string literal not displayed */
PythonImage string `` //nolint:lll // config struct tags are intentionally verbose
/* 170-byte string literal not displayed */
IdleTimeout time.Duration `` //nolint:lll // config struct tags are intentionally verbose
/* 215-byte string literal not displayed */
}
Settings holds the data-plane configuration, embedded in the root CLI command as CLI.AgentCore.
type StrategyInfo ¶
type StrategyInfo struct{ ID, Name, Type string }
StrategyInfo is one memory strategy of a memory.
type ToolSession ¶
type ToolSession struct {
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
LastActive time.Time `json:"lastActive"`
Config doc `json:"config,omitempty"`
Account string `json:"account"`
Region string `json:"region"`
Kind ToolKind `json:"kind"`
ToolID string `json:"toolId"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
Status string `json:"status"`
Token string `json:"clientToken,omitempty"`
TimeoutSec int `json:"timeoutSec"`
}
ToolSession is a browser or code interpreter session.