mirror of
https://github.com/mudler/LocalAGI.git
synced 2026-07-23 18:55:52 -04:00
73a6be8264
* WIP
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Drop old webui
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Almost there
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* It builds
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Make it build
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* fixups, still doesn't work
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* unused now
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Send result before closing
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Fix observability
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Drop MCP code and wire-up in cogito
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Drop some templates
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Keep reporting into conv
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* tests fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* tests fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Do not complete observable during thought process
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Update cogito
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Drop unneded option now
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Fixups
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Better handling of user tools
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* TEST
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Add flake attempts
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Revert "TEST"
This reverts commit 8b12a9fd03.
* tKeep indexing MCP actions
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Split CI jobs to improve speed
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* CI optimizations
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Bump timeout
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* Bump cogito
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* fix: always commit last progress
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* chore: better management of observables
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
173 lines
4.8 KiB
Go
173 lines
4.8 KiB
Go
package localagi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// AgentConfig represents the configuration for an agent
|
|
type AgentConfig struct {
|
|
Name string `json:"name"`
|
|
Actions []string `json:"actions,omitempty"`
|
|
Connectors []string `json:"connectors,omitempty"`
|
|
PromptBlocks []string `json:"prompt_blocks,omitempty"`
|
|
InitialPrompt string `json:"initial_prompt,omitempty"`
|
|
Parallel bool `json:"parallel,omitempty"`
|
|
EnableReasoning bool `json:"enable_reasoning,omitempty"`
|
|
}
|
|
|
|
// AgentStatus represents the status of an agent
|
|
type AgentStatus struct {
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// ListAgents returns a list of all agents
|
|
func (c *Client) ListAgents() ([]string, error) {
|
|
resp, err := c.doRequest(http.MethodGet, "/agents", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// The response is HTML, so we'll need to parse it properly
|
|
// For now, we'll just return a placeholder implementation
|
|
return []string{}, fmt.Errorf("ListAgents not implemented")
|
|
}
|
|
|
|
// GetAgentConfig retrieves the configuration for a specific agent
|
|
func (c *Client) GetAgentConfig(name string) (*AgentConfig, error) {
|
|
path := fmt.Sprintf("/api/agent/%s/config", name)
|
|
resp, err := c.doRequest(http.MethodGet, path, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var config AgentConfig
|
|
if err := json.NewDecoder(resp.Body).Decode(&config); err != nil {
|
|
return nil, fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|
|
|
|
// CreateAgent creates a new agent with the given configuration
|
|
func (c *Client) CreateAgent(config *AgentConfig) error {
|
|
resp, err := c.doRequest(http.MethodPost, "/api/agent/create", config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response map[string]string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
if status, ok := response["status"]; ok && status == "ok" {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to create agent: %v", response)
|
|
}
|
|
|
|
// UpdateAgentConfig updates the configuration for an existing agent
|
|
func (c *Client) UpdateAgentConfig(name string, config *AgentConfig) error {
|
|
// Ensure the name in the URL matches the name in the config
|
|
config.Name = name
|
|
path := fmt.Sprintf("/api/agent/%s/config", name)
|
|
|
|
resp, err := c.doRequest(http.MethodPut, path, config)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response map[string]string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
if status, ok := response["status"]; ok && status == "ok" {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to update agent: %v", response)
|
|
}
|
|
|
|
// DeleteAgent removes an agent
|
|
func (c *Client) DeleteAgent(name string) error {
|
|
path := fmt.Sprintf("/api/agent/%s", name)
|
|
resp, err := c.doRequest(http.MethodDelete, path, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response map[string]string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
if status, ok := response["status"]; ok && status == "ok" {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to delete agent: %v", response)
|
|
}
|
|
|
|
// PauseAgent pauses an agent
|
|
func (c *Client) PauseAgent(name string) error {
|
|
path := fmt.Sprintf("/api/agent/pause/%s", name)
|
|
resp, err := c.doRequest(http.MethodPut, path, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response map[string]string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
if status, ok := response["status"]; ok && status == "ok" {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to pause agent: %v", response)
|
|
}
|
|
|
|
// StartAgent starts a paused agent
|
|
func (c *Client) StartAgent(name string) error {
|
|
path := fmt.Sprintf("/api/agent/start/%s", name)
|
|
resp, err := c.doRequest(http.MethodPut, path, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var response map[string]string
|
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
|
return fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
if status, ok := response["status"]; ok && status == "ok" {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("failed to start agent: %v", response)
|
|
}
|
|
|
|
// ExportAgent exports an agent configuration
|
|
func (c *Client) ExportAgent(name string) (*AgentConfig, error) {
|
|
path := fmt.Sprintf("/settings/export/%s", name)
|
|
resp, err := c.doRequest(http.MethodGet, path, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
var config AgentConfig
|
|
if err := json.NewDecoder(resp.Body).Decode(&config); err != nil {
|
|
return nil, fmt.Errorf("error decoding response: %w", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|