bedrock

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 13 Imported by: 0

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

Examples

Constants

View Source
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 Error

type Error struct {
	Message string
	Cause   error
}

Error preserves the ordinary JavaScript Error name in Lambda Runtime API errors.

func (*Error) Error

func (e *Error) Error() string

func (*Error) ErrorName

func (e *Error) ErrorName() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Event

type Event = map[string]any

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

func (*FunctionResponse) Build

func (r *FunctionResponse) Build(actionGroup, function string) map[string]any

Build creates the wire envelope without modifying or cloning supplied fields.

type NamedError

type NamedError struct {
	Name, Message string
	Cause         error
}

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 Options

type Options struct {
	// Diagnostic runs outside locks and may be called concurrently. Registration
	// uses context.Background; execution diagnostics retain the invocation context.
	Diagnostic func(context.Context, string, string, 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 New

func New(options Options) *Resolver

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, input any) (any, error)

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.

type ToolHandler

type ToolHandler func(context.Context, *Parameters, Event) (any, error)

type Undefined

type Undefined struct{}

Undefined represents an absent JavaScript value. Nil represents JSON null.

Jump to

Keyboard shortcuts

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