agents

package
v0.0.0-...-d9fdc95 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIAgent

type AIAgent interface {
	//GetName() string
	Initialize(ctx context.Context, config Config, name string)
	QuickInitialization()
	SetSystemInstructionsFromFile(systemInstructionsPath string) error
	SetSystemInstructions(systemInstructions string)
	InitializeVectorStoreFromFile(ctx context.Context, config Config, backgroundContextPath string) error
	Completion(ctx context.Context, config Config, userMessage string) (string, error)
	JsonCompletion(ctx context.Context, config Config, outputType any, userMessage string) (string, error)
	SimilaritySearch(ctx context.Context, config Config, userMessage string) (string, error)
	CompletionWithSimilaritySearch(ctx context.Context, config Config, userMessage string) (string, error)
	StreamCompletion(ctx context.Context, config Config, userMessage string, callback ai.ModelStreamCallback) (string, error)
	StreamCompletionWithSimilaritySearch(ctx context.Context, config Config, userMessage string, callback ai.ModelStreamCallback) (string, error)
	DetectAndExecuteToolCalls(ctx context.Context, config Config, userMessage string) (*ToolCallsResult, error)
	DetectAndExecuteToolCallsWithConfirmation(ctx context.Context, config Config, userMessage string) (*ToolCallsResult, error)
	ResetMessages()
	GetHistory() []*ai.Message
	DisplayHistory()
	LoopCompletion(ctx context.Context, config Config)
	DirectExecuteTool(ctx context.Context, config Config, req *ai.ToolRequest) (string, error)
}

type Config

type Config struct {
	EngineURL                  string
	SimilaritySearchLimit      float64
	SimilaritySearchMaxResults int

	Temperature float64
	TopP        float64

	ChatModelId       string
	EmbeddingsModelId string
	ToolsModelId      string

	Tools []ai.ToolRef
}

type NPCAgent

type NPCAgent struct {
	Name string
	// contains filtered or unexported fields
}

IMPORTANT: the conversation history is automatically managed TODO: add methods to clear history, export history, import history, etc.

func (*NPCAgent) Completion

func (agent *NPCAgent) Completion(ctx context.Context, config Config, userMessage string) (string, error)

func (*NPCAgent) CompletionWithSimilaritySearch

func (agent *NPCAgent) CompletionWithSimilaritySearch(ctx context.Context, config Config, userMessage string) (string, error)

func (*NPCAgent) DetectAndExecuteToolCalls

func (agent *NPCAgent) DetectAndExecuteToolCalls(ctx context.Context, config Config, userMessage string) (*ToolCallsResult, error)

DetectAndExecuteToolCalls detects and executes tool calls automatically (no confirmation)

Flow:

┌──────────────────────────────┐
│ DetectAndExecuteToolCalls    │
└──────────────┬───────────────┘
               │
               │ Creates executor lambda
               │ that calls executeTool
               │
               ▼
┌──────────────────────────────┐
│detectAndExecuteToolCallsLoop │
└──────────────┬───────────────┘
               │
               │ For each tool request,
               │ calls executor
               │
               ▼
┌──────────────────────────────┐
│ executeTool                  │
│ (automatic execution)        │
└──────────────┬───────────────┘
               │
               ▼
┌──────────────────────────────┐
│ tool.RunRaw()                │
│ Append result to history     │
└──────────────────────────────┘

func (*NPCAgent) DetectAndExecuteToolCallsWithConfirmation

func (agent *NPCAgent) DetectAndExecuteToolCallsWithConfirmation(ctx context.Context, config Config, userMessage string) (*ToolCallsResult, error)

DetectAndExecuteToolCallsWithConfirmation detects and executes tool calls with user confirmation

Flow:

┌──────────────────────────────┐
│DetectAndExecuteToolCalls     │
│WithConfirmation              │
└──────────────┬───────────────┘
               │
               │ Passes executeToolWithConfirmation
               │ as executor
               │
               ▼
┌──────────────────────────────┐
│detectAndExecuteToolCallsLoop │
└──────────────┬───────────────┘
               │
               │ For each tool request,
               │ calls executor
               │
               ▼
���──────────────────────────────┐
│executeToolWithConfirmation   │
└──────────────┬───────────────┘
               │
               │ Ask user: y/n/q?
               │
    ┌──────────┼──────────┐
    │          │          │
    ▼          ▼          ▼
 ┌───┐      ┌───┐      ┌───┐
 │ y │      │ n │      │ q │
 └─┬─┘      └─┬─┘      └─┬─┘
   │          │          │
   │          │          └──► Set stopped=true
   │          │
   │          └──► Append "cancelled" to history
   │
   └──► Call executeTool()

func (*NPCAgent) DirectExecuteTool

func (agent *NPCAgent) DirectExecuteTool(ctx context.Context, config Config, req *ai.ToolRequest) (string, error)

IMPORTANT: [TODO]

func (*NPCAgent) DisplayHistory

func (agent *NPCAgent) DisplayHistory()

func (*NPCAgent) GetHistory

func (agent *NPCAgent) GetHistory() []*ai.Message

func (*NPCAgent) Initialize

func (agent *NPCAgent) Initialize(ctx context.Context, config Config, name string)

func (*NPCAgent) InitializeVectorStoreFromFile

func (agent *NPCAgent) InitializeVectorStoreFromFile(ctx context.Context, config Config, backgroundContextPath string) error

func (*NPCAgent) JsonCompletion

func (agent *NPCAgent) JsonCompletion(ctx context.Context, config Config, outputType any, userMessage string) (string, error)

func (*NPCAgent) JsonStreamCompletion

func (agent *NPCAgent) JsonStreamCompletion(ctx context.Context, config Config, outputType any, userMessage string, callback ai.ModelStreamCallback) (string, error)

func (*NPCAgent) LoopCompletion

func (agent *NPCAgent) LoopCompletion(ctx context.Context, config Config)

func (*NPCAgent) QuickInitialization

func (agent *NPCAgent) QuickInitialization()

func (*NPCAgent) ResetMessages

func (agent *NPCAgent) ResetMessages()

func (*NPCAgent) SetSystemInstructions

func (agent *NPCAgent) SetSystemInstructions(systemInstructions string)

func (*NPCAgent) SetSystemInstructionsFromFile

func (agent *NPCAgent) SetSystemInstructionsFromFile(systemInstructionsPath string) error

func (*NPCAgent) SimilaritySearch

func (agent *NPCAgent) SimilaritySearch(ctx context.Context, config Config, userMessage string) (string, error)

func (*NPCAgent) StreamCompletion

func (agent *NPCAgent) StreamCompletion(ctx context.Context, config Config, userMessage string, callback ai.ModelStreamCallback) (string, error)

func (*NPCAgent) StreamCompletionWithSimilaritySearch

func (agent *NPCAgent) StreamCompletionWithSimilaritySearch(ctx context.Context, config Config, userMessage string, callback ai.ModelStreamCallback) (string, error)

type ToolCallsResult

type ToolCallsResult struct {
	TotalCalls int
	//Results     []any
	Results     []map[string]any
	LastMessage string
}

ToolCallsResult holds the result of tool calls detection and execution