agent

package
v0.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultModel = "claude-3-7-sonnet-latest"

Variables

View Source
var QueryTimeout = 60 * time.Second

QueryTimeout is the default timeout for SQL query execution

Functions

func MarshalToolsToJSON

func MarshalToolsToJSON(tools []*Tool) (string, error)

MarshalToolsToJSON converts tools to JSON for debugging/logging

Types

type Agent

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

func NewAgent

func NewAgent(apiKey string, mode string, model string) (*Agent, error)

func (*Agent) AddTool

func (a *Agent) AddTool(tool ToolDefinition)

AddTool adds a tool to the agent

func (*Agent) ClearConversation

func (a *Agent) ClearConversation()

ClearConversation clears the conversation history

func (*Agent) SendMessage

func (a *Agent) SendMessage(ctx context.Context, userMessage string) (string, error)

type ContentBlock

type ContentBlock struct {
	Type string `json:"type"` // "text", "tool_use", "tool_result"
	Text string `json:"text,omitempty"`

	// For tool_use
	ID    string                 `json:"id,omitempty"`
	Name  string                 `json:"name,omitempty"`
	Input map[string]interface{} `json:"input,omitempty"`

	// For tool_result
	ToolUseID string `json:"tool_use_id,omitempty"`
	Content   string `json:"content,omitempty"`
	IsError   bool   `json:"is_error,omitempty"`
}

ContentBlock represents a piece of message content

type ConversationHistory

type ConversationHistory struct {
	Messages []Message `json:"messages"`
}

ConversationHistory manages the conversation state

func (*ConversationHistory) AddAssistantMessage

func (ch *ConversationHistory) AddAssistantMessage(content interface{})

AddAssistantMessage adds an assistant message to the conversation

func (*ConversationHistory) AddToolResult

func (ch *ConversationHistory) AddToolResult(toolUseID string, result *ToolResult)

AddToolResult adds a tool result to the conversation

func (*ConversationHistory) AddUserMessage

func (ch *ConversationHistory) AddUserMessage(content string)

AddUserMessage adds a user message to the conversation

func (*ConversationHistory) Clear

func (ch *ConversationHistory) Clear()

Clear resets the conversation history

func (*ConversationHistory) GetLastUserMessage

func (ch *ConversationHistory) GetLastUserMessage() string

GetLastUserMessage returns the last user message content

type Message

type Message struct {
	Role    string      `json:"role"`    // "user", "assistant"
	Content interface{} `json:"content"` // string or []ContentBlock
}

Message represents a conversation message

type QueryResultData

type QueryResultData struct {
	ColumnNames []string
	Rows        [][]interface{}
	TotalRows   int
	Truncated   bool
}

QueryResultData represents the actual data from a query for LLM sharing

type QueryResultWithData

type QueryResultWithData struct {
	QueryResultData
	AllRows   [][]interface{}
	QueryText string
}

QueryResultWithData extends QueryResultData with additional metadata

var LastQueryResult *QueryResultWithData

LastQueryResult stores the most recent query result for browsing

type Tool

type Tool struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	InputSchema ToolSchema  `json:"input_schema"`
	Handler     ToolHandler `json:"-"`
}

Tool represents a function that the LLM can call

func CreateExecutionTools

func CreateExecutionTools(conn db.Connection, getUserApproval func(string) bool, mode string) []*Tool

CreateExecutionTools creates SQL execution tools for the LLM

func CreateSchemaTools

func CreateSchemaTools(conn db.Connection, mode string) []*Tool

CreateSchemaTools creates all schema inspection tools for the LLM

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	InputSchema anthropic.ToolInputSchemaParam
	Function    func(ctx context.Context, input json.RawMessage) (string, error)
}

func ConvertToolToDefinition

func ConvertToolToDefinition(tool *Tool) ToolDefinition

ConvertToolToDefinition converts our Tool to ToolDefinition format

type ToolHandler

type ToolHandler func(ctx context.Context, input map[string]interface{}) (*ToolResult, error)

ToolHandler is a function that executes a tool

type ToolRegistry

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

ToolRegistry manages available tools for the LLM

func NewToolRegistry

func NewToolRegistry() *ToolRegistry

NewToolRegistry creates a new tool registry

func (*ToolRegistry) Clear

func (tr *ToolRegistry) Clear()

Clear removes all tools from the registry

func (*ToolRegistry) ExecuteTool

func (tr *ToolRegistry) ExecuteTool(ctx context.Context, name string, input map[string]interface{}) (*ToolResult, error)

ExecuteTool executes a tool by name with given input

func (*ToolRegistry) GetAllTools

func (tr *ToolRegistry) GetAllTools() []*Tool

GetAllTools returns all registered tools

func (*ToolRegistry) GetTool

func (tr *ToolRegistry) GetTool(name string) (*Tool, bool)

GetTool retrieves a tool by name

func (*ToolRegistry) GetToolsForAnthropic

func (tr *ToolRegistry) GetToolsForAnthropic() []map[string]interface{}

GetToolsForAnthropic returns tools in Anthropic API format

func (*ToolRegistry) ListToolNames

func (tr *ToolRegistry) ListToolNames() []string

ListToolNames returns a list of all tool names

func (*ToolRegistry) RegisterTool

func (tr *ToolRegistry) RegisterTool(tool *Tool) error

RegisterTool adds a tool to the registry

func (*ToolRegistry) RemoveTool

func (tr *ToolRegistry) RemoveTool(name string) bool

RemoveTool removes a tool from the registry

type ToolResult

type ToolResult struct {
	Content string `json:"content"`
	IsError bool   `json:"is_error,omitempty"`
}

ToolResult represents the result of tool execution

type ToolSchema

type ToolSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties"`
	Required   []string               `json:"required,omitempty"`
}

ToolSchema defines the JSON schema for tool input

Jump to

Keyboard shortcuts

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