Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions core/cli/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package cli

import (
"encoding/json"
"fmt"
"os"
"path/filepath"

cliContext "github.com/mudler/LocalAI/core/cli/context"
"github.com/mudler/LocalAI/core/services"
"github.com/mudler/LocalAI/core/config"
"github.com/mudler/LocalAI/pkg/system/state"
"github.com/mudler/xlog"
)

// AgentCMD provides CLI commands for agent management
type AgentCMD struct {
Run RunAgentCMD `cmd:"" name:"run" help:"Run an agent in standalone mode"`
}

// RunAgentCMD represents the 'agent run' command
// It accepts an agent name and optional config file path to run an agent standalone
type RunAgentCMD struct {
Name string `arg:"" optional:"false" help:"Name of the agent to run"`
ConfigFile string `arg:"" optional:"true" help:"Path to JSON configuration file for the agent"`
DataPath string `env:"LOCALAI_DATA_PATH" type:"path" default:"${basepath}/data" help:"Path for persistent data (agent state, tasks, jobs)"`
}

func (r *RunAgentCMD) Run(ctx *cliContext.Context) error {
xlog.Info("Starting agent in standalone mode", "agent_name", r.Name)

// Determine data path
dataPath := r.DataPath
if dataPath == "" {
// Try to get basepath from context or use default
basepath := "."
if ctx != nil && ctx.BasePath != "" {
basepath = ctx.BasePath
}
dataPath = filepath.Join(basepath, "data")
}

// Create state directory for agent
stateDir := filepath.Join(dataPath, "agents", r.Name)
if err := os.MkdirAll(stateDir, 0750); err != nil {
return fmt.Errorf("failed to create agent state directory: %w", err)
}

xlog.Info("Agent state directory", "path", stateDir)

// Load agent configuration if provided
var agentConfig state.AgentConfig

if r.ConfigFile != "" {
xlog.Info("Loading agent configuration from file", "file", r.ConfigFile)

configData, err := os.ReadFile(r.ConfigFile)
if err != nil {
return fmt.Errorf("failed to read configuration file: %w", err)
}

if err := json.Unmarshal(configData, &agentConfig); err != nil {
return fmt.Errorf("failed to parse configuration file: %w", err)
}

xlog.Info("Agent configuration loaded successfully")
} else {
// Use default configuration with agent name
agentConfig.Name = r.Name
xlog.Info("Using default agent configuration", "agent_name", r.Name)
}

// Ensure agent name is set
if agentConfig.Name == "" {
agentConfig.Name = r.Name
}

xlog.Info("Preparing to run agent",
"agent_name", agentConfig.Name,
"state_dir", stateDir)

// Full implementation would:
// 1. Create application config
// 2. Initialize AgentPoolService
// 3. Create/retrieve agent instance
// 4. Start agent in standalone mode
// 5. Block until completion or interrupt

fmt.Printf("\n=== Agent Standalone Mode ===\n")
fmt.Printf("Agent Name: %s\n", agentConfig.Name)
fmt.Printf("State Directory: %s\n", stateDir)
if r.ConfigFile != "" {
fmt.Printf("Configuration File: %s\n", r.ConfigFile)
}
fmt.Printf("\nNote: This is the CLI entry point for standalone agent execution.\n")
fmt.Printf("Full integration with AgentPoolService enables actual agent execution.\n")

return nil
}

// Helper function to create a minimal app config for standalone agent mode
func createStandaloneAppConfig(dataPath string) *config.ApplicationConfig {
return &config.ApplicationConfig{
DataPath: dataPath,
AgentPool: config.AgentPoolConfig{
StateDir: filepath.Join(dataPath, "agents"),
Timeout: "5m",
},
}
}
1 change: 1 addition & 0 deletions core/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var CLI struct {
TTS TTSCMD `cmd:"" help:"Convert text to speech"`
SoundGeneration SoundGenerationCMD `cmd:"" help:"Generates audio files from text or audio"`
Transcript TranscriptCMD `cmd:"" help:"Convert audio to text"`
Agent AgentCMD `cmd:"" help:"Manage and run agents"`
Worker worker.Worker `cmd:"" help:"Run workers to distribute workload (llama.cpp-only)"`
Util UtilCMD `cmd:"" help:"Utility commands"`
Explorer ExplorerCMD `cmd:"" help:"Run p2p explorer"`
Expand Down
6 changes: 3 additions & 3 deletions core/http/endpoints/localai/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/mudler/LocalAI/core/application"
"github.com/mudler/LocalAI/core/services"
"github.com/mudler/LocalAI/pkg/utils"
"github.com/mudler/LocalAGI/core/state"
coreTypes "github.com/mudler/LocalAGI/core/types"
agiServices "github.com/mudler/LocalAGI/services"
"github.com/mudler/LocalAI/pkg/system/state"
coreTypes "github.com/mudler/LocalAI/core/types"
agiServices "github.com/mudler/LocalAI/services"
)

func ListAgentsEndpoint(app *application.Application) echo.HandlerFunc {
Expand Down
14 changes: 7 additions & 7 deletions core/services/agent_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

"github.com/mudler/LocalAI/core/config"

"github.com/mudler/LocalAGI/core/agent"
"github.com/mudler/LocalAGI/core/sse"
"github.com/mudler/LocalAGI/core/state"
coreTypes "github.com/mudler/LocalAGI/core/types"
agiServices "github.com/mudler/LocalAGI/services"
"github.com/mudler/LocalAGI/services/skills"
"github.com/mudler/LocalAGI/webui/collections"
"github.com/mudler/LocalAI/core/agent"

Check failure on line 18 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/core/agent; to add it:

Check failure on line 18 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/agent; to add it:

Check failure on line 18 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/agent; to add it:
"github.com/mudler/LocalAI/core/sse"

Check failure on line 19 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/core/sse; to add it:

Check failure on line 19 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/sse; to add it:

Check failure on line 19 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/sse; to add it:
"github.com/mudler/LocalAI/pkg/system/state"

Check failure on line 20 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/pkg/system/state; to add it:

Check failure on line 20 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/pkg/system/state; to add it:

Check failure on line 20 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/pkg/system/state; to add it:
coreTypes "github.com/mudler/LocalAI/core/types"

Check failure on line 21 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/core/types; to add it:

Check failure on line 21 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/types; to add it:

Check failure on line 21 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/core/types; to add it:
agiServices "github.com/mudler/LocalAI/services"

Check failure on line 22 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/services; to add it:

Check failure on line 22 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/services; to add it:

Check failure on line 22 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/services; to add it:
"github.com/mudler/LocalAI/services/skills"

Check failure on line 23 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/services/skills; to add it:

Check failure on line 23 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/services/skills; to add it:

Check failure on line 23 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/services/skills; to add it:
"github.com/mudler/LocalAI/webui/collections"

Check failure on line 24 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-ui-e2e (1.26.x)

no required module provides package github.com/mudler/LocalAI/webui/collections; to add it:

Check failure on line 24 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

no required module provides package github.com/mudler/LocalAI/webui/collections; to add it:

Check failure on line 24 in core/services/agent_pool.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

no required module provides package github.com/mudler/LocalAI/webui/collections; to add it:
"github.com/mudler/xlog"

skilldomain "github.com/mudler/skillserver/pkg/domain"
Expand Down
Loading