agent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package agent implements the core AI agent loop that powers autopilot. This file defines the Tool type and conversion to the Claude API format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent is the core orchestrator. It holds configuration, persistent memory, registered tools, and an HTTP client for calling Claude's API. The Run method implements the full agentic loop: prompt -> tool calls -> loop until Claude returns a final text response.

func New

func New(cfg *config.Config, mem *memory.Store) *Agent

New creates an Agent wired to the given config and memory store.

func (*Agent) Notify

func (a *Agent) Notify(msg string)

Notify logs a message. The router layer can override delivery to Discord/Telegram.

func (*Agent) RegisterTool

func (a *Agent) RegisterTool(t Tool)

RegisterTool adds a single tool the agent can invoke.

func (*Agent) RegisterTools

func (a *Agent) RegisterTools(tools []Tool)

RegisterTools adds multiple tools at once.

func (*Agent) Run

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

Run executes the agent loop with a user message. It loads conversation history from memory, calls Claude with all registered tools, executes any tool calls in a loop, and returns the final text response.

func (*Agent) RunAutonomous

func (a *Agent) RunAutonomous(ctx context.Context, task string) (string, error)

RunAutonomous executes a task without a preceding user message. Used by the scheduler for proactive tasks like morning briefings and monitoring.

type ParameterDef

type ParameterDef struct {
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Required    bool     `json:"-"`
	Enum        []string `json:"enum,omitempty"`
}

ParameterDef describes a single parameter for a tool.

type Tool

type Tool struct {
	Name        string
	Description string
	Parameters  map[string]ParameterDef
	Fn          func(ctx context.Context, args map[string]any) (string, error)
}

Tool is a callable function the agent can invoke during a conversation. Modules register tools to give the agent capabilities like sending email, checking calendars, or searching the web.

func (Tool) ToAPI

func (t Tool) ToAPI() map[string]any

ToAPI converts the tool to the JSON structure Claude's API expects. Returns a map suitable for marshaling into the "tools" array of an API request.

Jump to

Keyboard shortcuts

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