Documentation
¶
Overview ¶
Package bedrock handles AWS Bedrock Agent function-based action-group invocations.
New constructs a Resolver. Resolver.Tool registers a named ToolHandler using Configuration. Resolver.Resolve selects the tool and builds the action-group response envelope. Tool handlers receive invocation context, ordered Parameters and the complete Event.
Integration boundary ¶
This package implements function-based action groups. The application configures the Bedrock Agent, action group, function definitions and Lambda permissions. It does not invoke a model or implement an OpenAPI-based action-group router.
Register tools during initialization and make callbacks safe for concurrent invocations. Review documented response, parameter and named-error behavior before returning application values or translating failures.
For usage and compatibility details, see the user guide.
Index ¶
- Constants
- type Configuration
- type Error
- type Event
- type FunctionResponse
- type NamedError
- type Options
- type Parameters
- func (p *Parameters) Delete(name string)
- func (p *Parameters) Get(name string) any
- func (p *Parameters) Has(name string) bool
- func (p *Parameters) Keys() []string
- func (p *Parameters) MarshalJSON() ([]byte, error)
- func (p *Parameters) Set(name string, value any)
- func (p *Parameters) Values() map[string]any
- type Resolver
- type ToolHandler
- type Undefined
Examples ¶
Constants ¶
const ( Failure = "FAILURE" Reprompt = "REPROMPT" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration struct{ Name, Description string }
type FunctionResponse ¶
type FunctionResponse struct {
Body any
ResponseState any
SessionAttributes any
PromptSessionAttributes any
KnowledgeBasesConfiguration any
}
FunctionResponse bypasses ordinary JSON body conversion. Construct it with NewFunctionResponse to obtain the reference's empty session-attribute defaults. Set optional fields to nil to omit them. Fields remain invocation-owned.
func NewFunctionResponse ¶
func NewFunctionResponse(body any) *FunctionResponse
type NamedError ¶
func (*NamedError) Error ¶
func (e *NamedError) Error() string
func (*NamedError) ErrorName ¶
func (e *NamedError) ErrorName() string
func (*NamedError) Unwrap ¶
func (e *NamedError) Unwrap() error
type Parameters ¶
type Parameters struct {
// contains filtered or unexported fields
}
Parameters retains insertion order so returning the received parameters preserves the reference JSON body. Each invocation receives an independent instance.
func (*Parameters) Delete ¶
func (p *Parameters) Delete(name string)
func (*Parameters) Get ¶
func (p *Parameters) Get(name string) any
func (*Parameters) Has ¶
func (p *Parameters) Has(name string) bool
func (*Parameters) Keys ¶
func (p *Parameters) Keys() []string
Keys follows Object.keys ordering: numeric indices first, then insertion order.
func (*Parameters) MarshalJSON ¶
func (p *Parameters) MarshalJSON() ([]byte, error)
func (*Parameters) Set ¶
func (p *Parameters) Set(name string, value any)
Set replaces a value without moving its original key position.
func (*Parameters) Values ¶
func (p *Parameters) Values() map[string]any
Values returns a shallow map copy. Go maps do not preserve insertion order.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
func (*Resolver) Resolve ¶
Resolve validates the event before calling a tool. Business and serialization failures become Bedrock response bodies; malformed input returns an error.
Example ¶
package main
import (
"context"
"fmt"
"github.com/rambow-cloud/powertools-lambda-go/eventhandler/bedrock"
)
func main() {
app := bedrock.New(bedrock.Options{})
app.Tool(func(_ context.Context, parameters *bedrock.Parameters, _ bedrock.Event) (any, error) {
return parameters.Get("orderId"), nil
}, bedrock.Configuration{Name: "lookupOrder", Description: "Look up an order"})
event := map[string]any{
"actionGroup": "orders", "function": "lookupOrder", "messageVersion": "1.0",
"inputText": "Find my order", "sessionId": "example-session",
"agent": map[string]any{"name": "example", "id": "example-agent", "alias": "example", "version": "1"},
"sessionAttributes": map[string]any{}, "promptSessionAttributes": map[string]any{},
"parameters": []any{map[string]any{"name": "orderId", "type": "string", "value": "order-123"}},
}
value, err := app.Resolve(context.Background(), event)
if err != nil {
panic(err)
}
response := value.(map[string]any)["response"].(map[string]any)
fmt.Println(response["actionGroup"], response["function"])
}
Output: orders lookupOrder
func (*Resolver) Tool ¶
func (r *Resolver) Tool(handler ToolHandler, configuration Configuration)
Tool registers a handler by function name. Description is accepted for source compatibility; the reference stores it without validating or publishing it.