Documentation
¶
Overview ¶
Package agentcore provides a runtime adapter for AWS Bedrock AgentCore.
AgentCore is AWS's serverless runtime for AI agents, providing:
- Firecracker microVM isolation per session
- Automatic scaling from zero
- Built-in session memory and identity
- Pay-per-use pricing (only active CPU time)
This package implements the AgentCore HTTP contract (/ping, /invocations) and allows AgentKit agents to run on AgentCore without code changes.
Note: Helm/Kubernetes configuration does NOT apply to AgentCore. Use AWS CDK, CloudFormation, or Terraform for AgentCore deployment.
Index ¶
- func NewSessionContext(ctx context.Context, sessionID string, req *Request) context.Context
- func SessionID(ctx context.Context) string
- func SessionMetadata(ctx context.Context, key string) string
- func WithRequest(ctx context.Context, req *Request) context.Context
- func WithSession(ctx context.Context, session *Session) context.Context
- type ADKAgentAdapter
- type ADKAgentConfig
- type Agent
- type AgentFunc
- type Builder
- func (b *Builder) Build(ctx context.Context) (*Server, error)
- func (b *Builder) MustBuild(ctx context.Context) *Server
- func (b *Builder) WithAgent(agent Agent) *Builder
- func (b *Builder) WithAgents(agents ...Agent) *Builder
- func (b *Builder) WithConfig(cfg Config) *Builder
- func (b *Builder) WithDefaultAgent(name string) *Builder
- func (b *Builder) WithPort(port int) *Builder
- func (b *Builder) WithRegistry(registry *Registry) *Builder
- type Closer
- type Config
- type ExecutorAdapter
- func NewExecutorAdapter[I, O any](cfg ExecutorAdapterConfig[I, O]) *ExecutorAdapter[I, O]
- func WrapExecutor[I, O any](name string, executor *orchestration.Executor[I, O]) *ExecutorAdapter[I, O]
- func WrapExecutorWithPrompt[I, O any](name string, executor *orchestration.Executor[I, O], ...) *ExecutorAdapter[I, O]
- type ExecutorAdapterConfig
- type HandlerAdapter
- type HealthChecker
- type Initializer
- type MultiAgentRouter
- type Registry
- func (r *Registry) Close() error
- func (r *Registry) Count() int
- func (r *Registry) Get(name string) (Agent, error)
- func (r *Registry) HealthCheck(ctx context.Context) map[string]error
- func (r *Registry) Invoke(ctx context.Context, req Request) (Response, error)
- func (r *Registry) List() []string
- func (r *Registry) MustRegister(ctx context.Context, agent Agent)
- func (r *Registry) Register(ctx context.Context, agent Agent) error
- func (r *Registry) RegisterAll(ctx context.Context, agents ...Agent) error
- func (r *Registry) SetDefault(name string) error
- type Request
- type Response
- type Server
- func (s *Server) MustRegister(ctx context.Context, agent Agent)
- func (s *Server) Register(ctx context.Context, agent Agent) error
- func (s *Server) RegisterAll(ctx context.Context, agents ...Agent) error
- func (s *Server) Registry() *Registry
- func (s *Server) SetDefaultAgent(name string) error
- func (s *Server) Start() error
- func (s *Server) StartAsync()
- func (s *Server) Stop(ctx context.Context) error
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSessionContext ¶
NewSessionContext creates a context with session and request information. This is a convenience function that combines WithSession and WithRequest.
func SessionID ¶
SessionID retrieves the session ID from the context. Returns empty string if no session is present.
func SessionMetadata ¶
SessionMetadata retrieves a metadata value from the session. Returns empty string if the key doesn't exist or no session is present.
func WithRequest ¶
WithRequest adds the original request to the context. Useful for agents that need access to the full request.
Types ¶
type ADKAgentAdapter ¶
type ADKAgentAdapter struct {
// contains filtered or unexported fields
}
ADKAgentAdapter wraps a Google ADK agent for AgentCore. Note: This is a placeholder - actual implementation depends on ADK's Go API.
func NewADKAgentAdapter ¶
func NewADKAgentAdapter(cfg ADKAgentConfig) *ADKAgentAdapter
NewADKAgentAdapter creates an Agent that wraps a Google ADK agent.
type ADKAgentConfig ¶
type ADKAgentConfig struct {
Name string
Description string
// Invoke is the function that calls the ADK agent.
// This abstraction allows different ADK agent implementations.
Invoke func(ctx context.Context, prompt string) (string, error)
}
ADKAgentConfig configures an ADKAgentAdapter.
type Agent ¶
type Agent interface {
// Name returns the unique identifier for this agent.
// Used for routing in multi-agent setups.
Name() string
// Invoke processes a request and returns a response.
// The context carries session information and cancellation signals.
Invoke(ctx context.Context, req Request) (Response, error)
}
Agent is the interface that AgentCore-compatible agents must implement. This interface is designed to be simple and runtime-agnostic.
type AgentFunc ¶
type AgentFunc struct {
// contains filtered or unexported fields
}
AgentFunc is a function type that implements the Agent interface. Useful for simple agents that don't need state.
func NewAgentFunc ¶
func NewAgentFunc(name string, fn func(ctx context.Context, req Request) (Response, error)) *AgentFunc
NewAgentFunc creates an Agent from a function.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent interface for building an AgentCore server.
func (*Builder) WithAgents ¶
WithAgents adds multiple agents to the server.
func (*Builder) WithConfig ¶
WithConfig sets the server configuration.
func (*Builder) WithDefaultAgent ¶
WithDefaultAgent sets the default agent name.
func (*Builder) WithRegistry ¶
WithRegistry uses an existing registry instead of creating a new one.
type Closer ¶
type Closer interface {
// Close releases resources held by the agent.
Close() error
}
Closer is an optional interface for agents that need cleanup. Called when the server is shutting down.
type Config ¶
type Config struct {
// Port is the port to listen on. Default is 8080 (AgentCore standard).
Port int
// ReadTimeout is the maximum duration for reading requests.
// Default is 30 seconds.
ReadTimeout time.Duration
// WriteTimeout is the maximum duration for writing responses.
// Default is 300 seconds (5 minutes) for long-running agent operations.
WriteTimeout time.Duration
// IdleTimeout is the maximum time to wait for the next request.
// Default is 60 seconds.
IdleTimeout time.Duration
// DefaultAgent is the agent to use when no agent is specified in the request.
// If empty, the "agent" field is required in invocation requests.
DefaultAgent string
// EnableRequestLogging enables logging of incoming requests.
// Default is true.
EnableRequestLogging bool
// EnableSessionTracking enables session ID tracking in logs.
// Default is true.
EnableSessionTracking bool
}
Config holds configuration for an AgentCore runtime server.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults for AgentCore.
func LoadConfigFromEnv ¶
func LoadConfigFromEnv() Config
LoadConfigFromEnv loads configuration from environment variables. Environment variables:
- AGENTCORE_PORT: Port to listen on (default: 8080)
- AGENTCORE_DEFAULT_AGENT: Default agent name
- AGENTCORE_READ_TIMEOUT_SECS: Read timeout in seconds
- AGENTCORE_WRITE_TIMEOUT_SECS: Write timeout in seconds
- AGENTCORE_ENABLE_REQUEST_LOGGING: Enable request logging (true/false)
type ExecutorAdapter ¶
type ExecutorAdapter[I, O any] struct { // contains filtered or unexported fields }
ExecutorAdapter wraps an AgentKit Executor to implement the Agent interface. This allows Eino-based workflows to run on AgentCore without modification.
func NewExecutorAdapter ¶
func NewExecutorAdapter[I, O any](cfg ExecutorAdapterConfig[I, O]) *ExecutorAdapter[I, O]
NewExecutorAdapter creates an Agent that wraps an AgentKit Executor.
func WrapExecutor ¶
func WrapExecutor[I, O any](name string, executor *orchestration.Executor[I, O]) *ExecutorAdapter[I, O]
WrapExecutor is a convenience function to create an ExecutorAdapter with defaults. Uses JSON for input parsing and output formatting.
func WrapExecutorWithPrompt ¶
func WrapExecutorWithPrompt[I, O any]( name string, executor *orchestration.Executor[I, O], setPrompt func(prompt string) I, getOutput func(output O) string, ) *ExecutorAdapter[I, O]
WrapExecutorWithPrompt creates an adapter where the prompt is passed directly to a field in the input struct. Useful for simple prompt-in/response-out agents.
func (*ExecutorAdapter[I, O]) Name ¶
func (a *ExecutorAdapter[I, O]) Name() string
Name returns the agent name.
type ExecutorAdapterConfig ¶
type ExecutorAdapterConfig[I, O any] struct { // Name is the agent name for routing. Name string // Executor is the AgentKit Executor to wrap. Executor *orchestration.Executor[I, O] // ParseInput converts the prompt string to the executor's input type. // If nil, JSON unmarshaling is used. ParseInput func(prompt string) (I, error) // FormatOutput converts the executor's output to a response string. // If nil, JSON marshaling is used. FormatOutput func(output O) string }
ExecutorAdapterConfig configures an ExecutorAdapter.
type HandlerAdapter ¶
type HandlerAdapter struct {
// contains filtered or unexported fields
}
HandlerAdapter wraps an http.HandlerFunc-style function as an Agent. Useful for migrating existing HTTP handlers to AgentCore.
func NewHandlerAdapter ¶
func NewHandlerAdapter(name string, handler func(ctx context.Context, req Request) (Response, error)) *HandlerAdapter
NewHandlerAdapter creates an Agent from a handler function.
type HealthChecker ¶
type HealthChecker interface {
// HealthCheck returns nil if the agent is healthy, error otherwise.
HealthCheck(ctx context.Context) error
}
HealthChecker is an optional interface for agents that support health checks. If an agent implements this, the server will call it for /ping requests.
type Initializer ¶
type Initializer interface {
// Initialize is called when the agent is registered.
Initialize(ctx context.Context) error
}
Initializer is an optional interface for agents that need initialization. Called once when the agent is registered with the server.
type MultiAgentRouter ¶
type MultiAgentRouter struct {
// contains filtered or unexported fields
}
MultiAgentRouter routes requests to multiple agents based on the agent field. This is useful when you want a single AgentCore endpoint to handle multiple agents.
func NewMultiAgentRouter ¶
func NewMultiAgentRouter(name string, agents ...Agent) (*MultiAgentRouter, error)
NewMultiAgentRouter creates a router that delegates to other agents.
func (*MultiAgentRouter) Name ¶
func (r *MultiAgentRouter) Name() string
Name returns the router name.
func (*MultiAgentRouter) RegisterAgent ¶
func (r *MultiAgentRouter) RegisterAgent(ctx context.Context, agent Agent) error
RegisterAgent adds an agent to the router.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages a collection of agents and routes requests to them.
func (*Registry) Close ¶
Close closes all agents that implement Closer. Collects all errors and returns them as a combined error.
func (*Registry) Get ¶
Get retrieves an agent by name. If name is empty, returns the default agent (if set).
func (*Registry) HealthCheck ¶
HealthCheck checks the health of all agents that implement HealthChecker. Returns a map of agent names to their health status (nil = healthy).
func (*Registry) Invoke ¶
Invoke routes a request to the appropriate agent and invokes it. This is a convenience method that combines Get and Invoke.
func (*Registry) MustRegister ¶
MustRegister is like Register but panics on error. Useful for initialization code where registration should never fail.
func (*Registry) Register ¶
Register adds an agent to the registry. If the agent implements Initializer, Initialize() is called. Returns an error if an agent with the same name already exists.
func (*Registry) RegisterAll ¶
RegisterAll registers multiple agents. Stops on the first error.
func (*Registry) SetDefault ¶
SetDefault sets the default agent to use when no agent is specified.
type Request ¶
type Request struct {
// Prompt is the user's input/query to the agent.
Prompt string `json:"prompt"`
// SessionID is the AgentCore session identifier.
// AgentCore provides session isolation via Firecracker microVMs.
SessionID string `json:"session_id,omitempty"`
// Agent specifies which agent to invoke (for multi-agent setups).
// If empty, the server's DefaultAgent is used.
Agent string `json:"agent,omitempty"`
// Metadata contains additional context passed to the agent.
Metadata map[string]string `json:"metadata,omitempty"`
// RawInput contains the full raw JSON input for custom parsing.
// Use this when your agent needs access to fields beyond the standard ones.
RawInput json.RawMessage `json:"-"`
}
Request represents an AgentCore invocation request. This is passed to agents when /invocations is called.
func RequestFromContext ¶
RequestFromContext retrieves the original request from the context. Returns nil if no request is present.
type Response ¶
type Response struct {
// Output is the agent's response text.
Output string `json:"output"`
// Metadata contains additional response metadata.
Metadata map[string]string `json:"metadata,omitempty"`
// Error contains error information if the invocation failed.
// This is separate from HTTP errors for partial failure scenarios.
Error string `json:"error,omitempty"`
}
Response represents an AgentCore invocation response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements the AWS AgentCore HTTP contract. It handles /ping and /invocations endpoints as required by AgentCore Runtime.
func NewServerWithRegistry ¶
NewServerWithRegistry creates a new AgentCore server with a pre-configured registry.
func (*Server) MustRegister ¶
MustRegister is like Register but panics on error.
func (*Server) RegisterAll ¶
RegisterAll registers multiple agents.
func (*Server) SetDefaultAgent ¶
SetDefaultAgent sets the default agent to use when none is specified.
func (*Server) Start ¶
Start starts the AgentCore server. This method blocks until the server stops.
func (*Server) StartAsync ¶
func (s *Server) StartAsync()
StartAsync starts the server in the background. Returns immediately. Use Stop() to shut down the server.
type Session ¶
type Session struct {
// ID is the unique session identifier provided by AgentCore.
ID string
// Metadata contains session-level metadata.
Metadata map[string]string
}
Session represents an AgentCore session context. AgentCore provides session isolation via Firecracker microVMs, with each session getting dedicated CPU, memory, and filesystem resources.
func SessionFromContext ¶
SessionFromContext retrieves session information from the context. Returns nil if no session is present.