Refactor console agents for improved modularity and configuration

Consolidated and refactored console agent logic into a streamlined structure with better configuration capabilities via `ConsoleConfig`. Improved code reusability and readability by converting nested structures and functions, and introduced more modular execution types for handling commands and history tracking.
This commit is contained in:
2025-05-03 22:06:32 -04:00
parent 4c5922d571
commit d2b9eb350e
3 changed files with 283 additions and 328 deletions

View File

@@ -6,7 +6,7 @@ import (
gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
)
type execution struct {
type Execution struct {
Command string
Output string
WhatILearned []string
@@ -16,7 +16,7 @@ type execution struct {
const kMaxLenCommandSummary = 200
const kMaxLenCommandOutputSummary = 200
func (e execution) ToGeneralMessageHistory() gollm.Message {
func (e Execution) ToGeneralMessageHistory() gollm.Message {
if len(e.Command) > kMaxLenCommandSummary {
e.Command = e.Command[:kMaxLenCommandSummary] + "... (truncated)"
}
@@ -33,7 +33,7 @@ func (e execution) ToGeneralMessageHistory() gollm.Message {
}
}
func (e execution) ToDetailedMessageHistory() gollm.Message {
func (e Execution) ToDetailedMessageHistory() gollm.Message {
prompt := "$ "
if strings.HasPrefix(e.Command, "sudo ") {
prompt = "# "
@@ -60,9 +60,9 @@ func (e execution) ToDetailedMessageHistory() gollm.Message {
}
}
type executions []execution
type Executions []Execution
func (e executions) ToGeneralMessageHistory() []gollm.Message {
func (e Executions) ToGeneralMessageHistory() []gollm.Message {
var messages []gollm.Message
for _, v := range e {
@@ -72,7 +72,7 @@ func (e executions) ToGeneralMessageHistory() []gollm.Message {
return messages
}
func (e executions) ToGeneralButLastMessageHistory() []gollm.Message {
func (e Executions) ToGeneralButLastMessageHistory() []gollm.Message {
var messages []gollm.Message
for i, v := range e {
@@ -86,7 +86,7 @@ func (e executions) ToGeneralButLastMessageHistory() []gollm.Message {
return messages
}
func (e executions) ToDetailedMessageHistory() []gollm.Message {
func (e Executions) ToDetailedMessageHistory() []gollm.Message {
var messages []gollm.Message
for _, v := range e {