engine

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPromptFn

func GetPromptFn(promptValues *ChatPromptValues) ai.PromptFn

Types

type Action

type Action struct {
	Name      string `json:"name"`
	Arguments any    `json:"arguments"`
	Result    any    `json:"result"`
}

type AvailableAction

type AvailableAction struct {
	Action      string `json:"action"`
	Description string `json:"description"`
}

type ChatPromptValues

type ChatPromptValues struct {
	Agent               entity.Agent
	RecentConversations []Conversation
	AvailableActions    []AvailableAction
	MessageExamples     [][]entity.MessageExample
	Thread              Thread
	Tools               []ai.ToolRef
	Knowledge           []string
}

type Conversation

type Conversation struct {
	User    string   `json:"user,omitempty"`
	Text    string   `json:"text,omitempty"`
	Actions []Action `json:"actions,omitempty"`
}

type Engine

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

func NewEngine

func NewEngine(
	logger *mylog.Logger,
	toolManager tool.Manager,
	genkit *genkit.Genkit,
	memoryService memory.Service,
) *Engine

func (*Engine) BuildPromptValues

func (s *Engine) BuildPromptValues(ctx context.Context, agent entity.Agent, history []Conversation, thread Thread) (*ChatPromptValues, error)

func (*Engine) Embed

func (e *Engine) Embed(
	ctx context.Context,
	texts ...string,
) ([][]float32, error)

func (*Engine) Generate

func (e *Engine) Generate(
	ctx context.Context,
	req *GenerateRequest,
	out any,
	opts ...ai.GenerateOption,
) (*ai.ModelResponse, error)

func (*Engine) Run

func (s *Engine) Run(
	ctx context.Context,
	agent entity.Agent,
	req RunRequest,
	output any,
) (*RunResponse, error)

type EvaluatorResponse

type EvaluatorResponse struct {
	Score      float32  `json:"score" jsonschema_description:"Score of the response. 0.0 is the worst, 1.0 is the best"`
	Reason     string   `json:"reason" jsonschema_description:"Reason of the score. It should be a short sentence."`
	Suggestion []string `json:"suggestion" jsonschema_description:"Suggestion to improve the response. It should be a short sentence."`
}

type GenerateRequest

type GenerateRequest struct {
	Model               string
	EvaluatorPromptTmpl string
	NumRetries          int
}

type Participant

type Participant struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Role        string `json:"role"`
}

type RunRequest

type RunRequest struct {
	ThreadInstruction string         `json:"thread_instruction,omitempty"`
	History           []Conversation `json:"history"`
	Participant       []Participant  `json:"participants,omitempty"`
}

type RunResponse

type RunResponse struct {
	ToolCalls []ToolCall `json:"tool_calls"`
}

type Thread

type Thread struct {
	Instruction  string
	Participants []Participant `json:"participants,omitempty"`
}

type ToolCall

type ToolCall struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
	Result    json.RawMessage `json:"result"`
}