Documentation
¶
Index ¶
- Constants
- func EncodeMessages(w io.Writer, messages []Message) error
- func WithCraigFragments(frags ...PromptFragment) func(kw *craigKwargs)
- func WithCraigPersonality(personality string) func(kw *craigKwargs)
- func WithCraigTools(tools ...Tool) func(kw *craigKwargs)
- type Agent
- type AgentMessage
- type AgentMode
- type AgentModelBuilder
- type AvailableToolDefinition
- type AvailableToolDefinitionsMessage
- type CraigOpt
- type FragmentSelector
- type FragmentSelectorModelBuilder
- type Message
- type MessageStreamer
- type ModeSwitchMessage
- type ModelBuilder
- type NotificationMessage
- type PromptFragment
- type PromptFragmentMessage
- type SendMessageOpt
- type SystemMessage
- type TextStreamer
- type Tool
- type ToolCall
- type ToolCallArg
- type ToolCallsMessage
- type ToolResponse
- type ToolResponseMessage
- type UserMessage
Constants ¶
const ( ModeCollectContext = iota ModeReasonAct ModeAnswerUser )
Variables ¶
This section is empty.
Functions ¶
func EncodeMessages ¶
EncodeMessages into a json format on the writer.
func WithCraigFragments ¶
func WithCraigFragments(frags ...PromptFragment) func(kw *craigKwargs)
func WithCraigPersonality ¶
func WithCraigPersonality(personality string) func(kw *craigKwargs)
func WithCraigTools ¶
func WithCraigTools(tools ...Tool) func(kw *craigKwargs)
Types ¶
type Agent ¶
type Agent interface {
// Send a message to the agent, getting its response.
// May pass parameters to stream back messages or the response.
Send(msg string, opts ...SendMessageOpt) (string, error)
// Fetch the entire history state of the agent.
Messages() iter.Seq[Message]
}
Agent defines a Re-Act Agent.
func NewCraig ¶
func NewCraig(mb ModelBuilder, opts ...CraigOpt) Agent
Create a new CRAIG agent with the given tools.
func NewCraigFromSaved ¶
func NewCraigFromSaved(mb ModelBuilder, messages []Message, opts ...CraigOpt) Agent
Create a new CRAIG agent from the given state (from a previous CRAIG agent). The tools provided should match the tools originally provided to NewCraig (in schema).
type AgentMessage ¶
type AgentMessage struct {
Content string
}
type AgentModelBuilder ¶
type AvailableToolDefinition ¶
type AvailableToolDefinitionsMessage ¶
type AvailableToolDefinitionsMessage struct {
Tools []AvailableToolDefinition
}
type FragmentSelector ¶
type FragmentSelector interface {
// Select any relevant fragments that should be added tp the conversation.
SelectFragments([]PromptFragment, []Message) ([]PromptFragment, error)
}
FragmentSelector defines an object that can choose relevant fragments to a conversation.
func NewFragmentSelector ¶
func NewFragmentSelector(modelBuilder FragmentSelectorModelBuilder, dontRepeatN int) FragmentSelector
type Message ¶
type Message interface {
// contains filtered or unexported methods
}
Message is a sum type defining the structured data that can live in agent history.
type MessageStreamer ¶
type MessageStreamer interface {
// Try to send a message, ignoring errors.
TrySendMessage(msg Message)
}
MessageStreamer defines a callback interface that can be used to listen to new messages that the agent creates.
type ModeSwitchMessage ¶
type ModeSwitchMessage struct {
Mode AgentMode
}
type ModelBuilder ¶
type ModelBuilder interface {
AgentModelBuilder
FragmentSelectorModelBuilder
}
type NotificationMessage ¶
type PromptFragment ¶
type PromptFragmentMessage ¶
type PromptFragmentMessage struct {
Fragments []PromptFragment
}
type SendMessageOpt ¶
type SendMessageOpt func(*streamers)
func WithMessageStreamer ¶
func WithMessageStreamer(streamer MessageStreamer) SendMessageOpt
In addition to other message streamers, use the provided streamer.
func WithNotifications ¶
func WithNotifications(notifications ...NotificationMessage) SendMessageOpt
func WithResponseStreamer ¶
func WithResponseStreamer(streamer TextStreamer) SendMessageOpt
In addition to other response streamers, use the provided streamer.
type SystemMessage ¶
type SystemMessage struct {
Content string
}
type TextStreamer ¶
type TextStreamer interface {
// Try to send a response text chunk back, ignoring errors.
TrySendTextChunk(chunk string)
}
TextStreamer defines a callback interface that can be used to listen to text being streamed back from the final agent response.
type Tool ¶
type Tool interface {
// The name of the tool to be used by the agent. Should probably be snake_case.
Name() string
// Describe the tool in short bullet points to the agent.
// Includes which parameters to provide.
// Parameters can be described as any json type.
Description() []string
// Call the tool, providing a formatted response or an error if the tool call failed.
// The values of the args will be the direct result of json decoding the tool call args.
Call(map[string]any) (string, error)
}
Tool is a runnable object that can be both described to and called by an agent.
type ToolCall ¶
type ToolCall struct {
ToolName string
ToolArgs []ToolCallArg
}
type ToolCallArg ¶
type ToolCallsMessage ¶
type ToolResponse ¶
type ToolResponse struct {
Response string
}
type ToolResponseMessage ¶
type ToolResponseMessage struct {
Responses []ToolResponse
}
type UserMessage ¶
type UserMessage struct {
Content string
}