agent

package
v0.0.0-...-489b4c4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Task and agent identifiers
	KeyTaskID    = "task_id"
	KeyAgentID   = "agent_id"
	KeyMessageID = "message_id"

	// Model and provider information
	KeyModel         = "model"
	KeyProvider      = "provider"
	KeyModelProvider = "model_provider"

	// Timing and performance
	KeyDuration   = "duration_ms"
	KeyStartTime  = "start_time"
	KeyEndTime    = "end_time"
	KeyLatency    = "latency_ms"
	KeyThroughput = "throughput"

	// Token and cost tracking
	KeyInputTokens      = "input_tokens"
	KeyOutputTokens     = "output_tokens"
	KeyTotalTokens      = "total_tokens"
	KeyCacheWriteTokens = "cache_write_tokens"
	KeyCacheReadTokens  = "cache_read_tokens"
	KeyCost             = "cost"
	KeyTokensPerSecond  = "tokens_per_second"
	KeyCacheHitRatio    = "cache_hit_ratio"

	// Tool and execution information
	KeyTool         = "tool"
	KeyToolCount    = "tool_count"
	KeyToolName     = "tool_name"
	KeyToolDuration = "tool_duration_ms"
	KeyToolResult   = "tool_result"
	KeyToolStats    = "tool_stats"

	// Message and queue information
	KeyMessageCount     = "message_count"
	KeyProcessedCount   = "processed_count"
	KeyUnprocessedCount = "unprocessed_count"
	KeyQueueDepth       = "queue_depth"
	KeyActiveTaskCount  = "active_task_count"
	KeyPhase            = "phase"
	KeyNextPhase        = "next_phase"

	// Configuration and environment
	KeyConcurrency     = "concurrency"
	KeyToolsRegistered = "tools_registered"
	KeyListenerAddress = "listener_address"
	KeyListenerType    = "listener_type"

	// Error and retry information
	KeyRetryable  = "retryable"
	KeyRetryAfter = "retry_after_ms"
	KeyRetryCount = "retry_count"
	KeyErrorType  = "error_type"
	KeyError      = "error"

	// Operations and components
	KeyOperation = "operation"
	KeyComponent = "component"
)

Log key constants for consistency across the codebase

View Source
const (
	MaxTitleLength = 80 // characters
	MaxRetries     = 2  // attempts to get shorter title
)
View Source
const DefaultServerPort = 29333
View Source
const ToolExecutionInProgressMarker = "__TOOL_EXECUTION_IN_PROGRESS__"

Variables

This section is empty.

Functions

func ConvertMemoryBlocksToAgent

func ConvertMemoryBlocksToAgent(blocks []types.MessageBlock) ([]*tooltypes.ToolCall, []*tooltypes.ToolResult, error)

ConvertMemoryBlocksToAgent converts memory blocks to agent-typed blocks with parsed Input/Output.

func ConvertMemoryMessageBlocksToModel

func ConvertMemoryMessageBlocksToModel(blocks []types.MessageBlock) ([]model.ContentBlock, error)

func ConvertMemoryMessageSourceToModel

func ConvertMemoryMessageSourceToModel(source types.MessageSource) (model.MessageSource, error)

func ConvertMemoryMessageToModel

func ConvertMemoryMessageToModel(m *memory.Message) (*model.Message, error)

func ConvertModelContentBlocksToMemory

func ConvertModelContentBlocksToMemory(blocks []model.ContentBlock) (*types.MessageContent, error)

func ConvertModelContentBlocksToMemoryWithProvider

func ConvertModelContentBlocksToMemoryWithProvider(blocks []model.ContentBlock, providerKind string) (*types.MessageContent, error)

func ConvertModelMessageSourceToMemory

func ConvertModelMessageSourceToMemory(source model.MessageSource) types.MessageSource

func ConvertModelMessageToMemory

func ConvertModelMessageToMemory(m *model.Message) (*memory.Message, error)

func ConvertModelUsageToMemory

func ConvertModelUsageToMemory(usage *model.Usage) *types.MessageUsage

func LogComponentShutdown

func LogComponentShutdown(logger *slog.Logger, component string, shutdownStart time.Time, keyValues ...any)

LogComponentShutdown logs component shutdown

func LogComponentStartup

func LogComponentStartup(logger *slog.Logger, component string, keyValues ...any)

LogComponentStartup logs component initialization

func LogError

func LogError(logger *slog.Logger, operation string, err error, keyValues ...any)

LogError logs an error with structured context

func LogOperationEnd

func LogOperationEnd(logger *slog.Logger, operation string, start time.Time, keyValues ...any)

LogOperationEnd logs the end of a significant operation

func LogOperationStart

func LogOperationStart(logger *slog.Logger, operation string, keyValues ...any)

LogOperationStart logs the start of a significant operation

func LogPhaseTransition

func LogPhaseTransition(logger *slog.Logger, taskID string, from, to string, keyValues ...any)

LogPhaseTransition logs task phase transitions

func LogTokenUsage

func LogTokenUsage(logger *slog.Logger, level slog.Level, inputTokens, outputTokens, cacheWrite, cacheRead int64, cost float64, duration time.Duration, keyValues ...any)

LogTokenUsage logs token usage from an API call

func NewAssistantMessage

func NewAssistantMessage(taskID uuid.UUID, options ...func(*v1.Message)) *v1.Message

func NewMessage

func NewMessage(taskID uuid.UUID, options ...func(*v1.Message)) *v1.Message

func NewSystemMessage

func NewSystemMessage(taskID uuid.UUID, options ...func(*v1.Message)) *v1.Message

func NewUserMessage

func NewUserMessage(taskID uuid.UUID, options ...func(*v1.Message)) *v1.Message

func ProjectStructure

func ProjectStructure(root string) (string, error)

func WithContent

func WithContent(content *v1.MessagePart) func(*v1.Message)

func WithRole

func WithRole(role v1.MessageRole) func(*v1.Message)

Types

type DevTools

type DevTools struct {
	VersionControl         []string
	PackageManagers        []string
	LanguageRuntimes       []string
	BuildTools             []string
	Testing                []string
	Database               []string
	ContainerOrchestration []string
	CloudInfrastructure    []string
	TextProcessing         []string
	FileOperations         []string
	NetworkHTTP            []string
	SystemMonitoring       []string
}

func AvailableDevTools

func AvailableDevTools() *DevTools

type LoggerConfig

type LoggerConfig struct {
	Level         slog.Level
	VerboseTools  bool
	VerboseModels bool
}

LoggerConfig holds logging configuration

func DefaultLoggerConfig

func DefaultLoggerConfig() *LoggerConfig

DefaultLoggerConfig returns default logging configuration

type ModelProviderFactory

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

func NewModelProviderFactory

func NewModelProviderFactory(encryption *secret.Encryption, memory *memory.Client) *ModelProviderFactory

func (*ModelProviderFactory) CreateClient

func (f *ModelProviderFactory) CreateClient(
	ctx context.Context,
	modelProviderID uuid.UUID,
) (providerClient model.ModelProvider, err error)

type Result

type Result struct {
	RetryAfter time.Duration
	Retry      bool
}

type Runtime

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

func NewRuntime

func NewRuntime(memory *memory.Client, encryption *secret.Encryption, listener net.Listener, opts ...RuntimeOption) (*Runtime, error)

func (*Runtime) Encryption

func (rt *Runtime) Encryption() *secret.Encryption

func (*Runtime) Memory

func (rt *Runtime) Memory() *memory.Client

func (*Runtime) Run

func (rt *Runtime) Run(ctx context.Context) error

type RuntimeOption

type RuntimeOption func(*RuntimeOptions)

func WithAnalytics

func WithAnalytics(analytics analytics.Client) RuntimeOption

func WithCodeActTools

func WithCodeActTools(tools ...codeact.Tool) RuntimeOption

func WithConcurrency

func WithConcurrency(concurrency int) RuntimeOption

func WithLoggerConfig

func WithLoggerConfig(config *LoggerConfig) RuntimeOption

type RuntimeOptions

type RuntimeOptions struct {
	Tools        []codeact.Tool
	Concurrency  int
	Analytics    analytics.Client
	LoggerConfig *LoggerConfig
}

func DefaultRuntimeOptions

func DefaultRuntimeOptions() *RuntimeOptions

type Shell

type Shell struct {
	Path string
	Name string
}

func DefaultShell

func DefaultShell() (*Shell, error)

type SyncMap

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewSyncMap

func NewSyncMap[K comparable, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) Delete

func (sm *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) Get

func (sm *SyncMap[K, V]) Get(key K) (V, bool)

func (*SyncMap[K, V]) Len

func (sm *SyncMap[K, V]) Len() int

func (*SyncMap[K, V]) Set

func (sm *SyncMap[K, V]) Set(key K, value V)

type TaskPhase

type TaskPhase string
const (
	TaskPhaseAwaitInput   TaskPhase = "await_input"
	TaskPhaseExecuteTools TaskPhase = "execute_tools"
	TaskPhaseInvokeModel  TaskPhase = "invoke_model"
	TaskPhaseSuspended    TaskPhase = "suspended"
)

type TaskReconciler

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

func NewTaskReconciler

func NewTaskReconciler(
	memory *memory.Client,
	interpreter *codeact.Interpreter,
	concurrency int,
	eventRouter *event.EventRouter,
	providerFactory *ModelProviderFactory,
	metricsRegistry prometheus.Registerer,
) *TaskReconciler

func (*TaskReconciler) Run

func (r *TaskReconciler) Run(ctx context.Context) error

type TaskStatus

type TaskStatus struct {
	Phase             TaskPhase
	NextMessage       *memory.Message
	ProcessedMessages []*memory.Message
}

type TitleGenerator

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

func NewTitleGenerator

func NewTitleGenerator(memory *memory.Client, providerFactory *ModelProviderFactory) *TitleGenerator

func (*TitleGenerator) GenerateTitle

func (g *TitleGenerator) GenerateTitle(ctx context.Context, taskID uuid.UUID) error

Jump to

Keyboard shortcuts

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