Documentation
¶
Index ¶
- type PromptBuilder
- func (tb *PromptBuilder) AddAssistantSection(templateText string) *PromptBuilder
- func (tb *PromptBuilder) AddSection(role llm.Role, templateText string) *PromptBuilder
- func (tb *PromptBuilder) AddSectionWithName(role llm.Role, templateText, name string) *PromptBuilder
- func (tb *PromptBuilder) AddSystemSection(templateText string) *PromptBuilder
- func (tb *PromptBuilder) AddUserSection(templateText string, name string) *PromptBuilder
- func (tb *PromptBuilder) Compose() ([]llm.Message, error)
- func (tb *PromptBuilder) GetTools() []toolkit.Tool
- func (tb *PromptBuilder) WithHelper(name string, fn interface{}) *PromptBuilder
- func (tb *PromptBuilder) WithManagerData(key StateDataKey) *PromptBuilder
- func (tb *PromptBuilder) WithManagerDataBatch(keys ...StateDataKey) *PromptBuilder
- func (tb *PromptBuilder) WithToolkit(toolkit *toolkit.Toolkit) *PromptBuilder
- func (tb *PromptBuilder) WithTools(tools ...toolkit.Tool) *PromptBuilder
- type PromptSection
- type State
- type StateData
- type StateDataKey
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 ¶
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 ¶
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 ¶
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.
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