state

package
v0.0.0-...-a59c08c Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PromptBuilder

type PromptBuilder struct {
	// contains filtered or unexported fields
}

PromptBuilder facilitates the construction of structured prompts It manages template sections and associated state data

func NewPromptBuilder

func NewPromptBuilder(s *State) *PromptBuilder

NewPromptBuilder creates a new template builder instance It initializes empty sections and state data stores

func (*PromptBuilder) AddAssistantSection

func (tb *PromptBuilder) AddAssistantSection(templateText string) *PromptBuilder

func (*PromptBuilder) AddSection

func (tb *PromptBuilder) AddSection(role llm.Role, templateText string) *PromptBuilder

AddSection adds a new template section with the specified role Returns the builder for method chaining

func (*PromptBuilder) AddSectionWithName

func (tb *PromptBuilder) AddSectionWithName(role llm.Role, templateText, name string) *PromptBuilder

AddSectionWithName adds a new template section with the specified role and name The name parameter allows identifying specific participants in the conversation

func (*PromptBuilder) AddSystemSection

func (tb *PromptBuilder) AddSystemSection(templateText string) *PromptBuilder

Helper methods for common message types Each returns the builder for method chaining

func (*PromptBuilder) AddUserSection

func (tb *PromptBuilder) AddUserSection(templateText string, name string) *PromptBuilder

func (*PromptBuilder) Compose

func (tb *PromptBuilder) Compose() ([]llm.Message, error)

Compose processes all template sections and returns an array of formatted messages It combines state fields, manager data, and custom data for template rendering

func (*PromptBuilder) GetTools

func (tb *PromptBuilder) GetTools() []toolkit.Tool

func (*PromptBuilder) WithHelper

func (tb *PromptBuilder) WithHelper(name string, fn interface{}) *PromptBuilder

Method to register template functions

func (*PromptBuilder) WithManagerData

func (tb *PromptBuilder) WithManagerData(key StateDataKey) *PromptBuilder

WithManagerData adds a single piece of manager-provided data to the template context Returns an error if the specified key doesn't exist in the state's manager data

func (*PromptBuilder) WithManagerDataBatch

func (tb *PromptBuilder) WithManagerDataBatch(keys ...StateDataKey) *PromptBuilder

WithManagerDataBatch adds multiple manager data keys at once Stops processing and returns error if any key is not found

func (*PromptBuilder) WithToolkit

func (tb *PromptBuilder) WithToolkit(toolkit *toolkit.Toolkit) *PromptBuilder

WithToolkit adds a toolkit to the state

func (*PromptBuilder) WithTools

func (tb *PromptBuilder) WithTools(tools ...toolkit.Tool) *PromptBuilder

WithTools adds a list of tools to the state

type PromptSection

type PromptSection struct {
	Role     llm.Role // The role of this section (system, user, assistant, etc)
	Template string   // The template text for this section
	Name     string   // Optional name for the role (e.g., specific user identifiers)
}

PromptSection represents a single section of a prompt template with its role and content

type State

type State struct {
	// Core conversation data
	Input  *db.Fragment // The current input
	Output *db.Fragment // The LLM response

	// Actor information
	Actor *db.Actor // Information about where it came from

	// Recent data
	RecentInteractions   []db.Fragment
	RelevantInteractions []db.Fragment
	Tools                []toolkit.Tool
	// contains filtered or unexported fields
}

State represents the current context and state of a conversation It maintains core conversation data, user information, and both manager and custom data

func NewState

func NewState() *State

NewState creates and initializes a new State instance with empty data stores

func (*State) AddCustomData

func (s *State) AddCustomData(key string, value interface{}) *State

AddCustomData adds a custom key-value pair to the state's custom data store. This is useful for platform-specific or temporary data that doesn't fit into manager data.

func (*State) AddManagerData

func (s *State) AddManagerData(data []StateData) *State

AddManagerData adds a slice of StateData entries to the state's manager data store. If the manager data map hasn't been initialized, it creates a new one.

func (*State) GetCustomData

func (s *State) GetCustomData(key string) (interface{}, bool)

GetCustomData retrieves a custom data value by its key. Returns the value and a boolean indicating if the key exists.

func (*State) GetManagerData

func (s *State) GetManagerData(key StateDataKey) (interface{}, bool)

GetManagerData retrieves manager-specific data by its key. Returns the value and a boolean indicating if the key exists.

func (*State) Reset

func (s *State) Reset()

Reset clears all manager and custom data from the state. This is typically called before updating the state with fresh data.

type StateData

type StateData struct {
	Key   StateDataKey
	Value interface{}
}

StateData represents a key-value pair of data provided by managers

type StateDataKey

type StateDataKey string

StateDataKey represents a unique identifier for state data entries

Jump to

Keyboard shortcuts

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