swarm

package
v0.95.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 58 Imported by: 0

README

Swarm

A lightweight multi-agent orchestration.

Swarm Magentic-One

[golang-lru]github.com/hashicorp/golang-lru/v2/expirable

Documentation

Index

Constants

View Source
const (
	// read from clipboard
	ClipinRedirect = "{"

	// read from clipboard and wait, allowing multiple copy
	// until Ctrl-D is entered
	ClipinRedirect2 = "{{"

	// write to clipboard, overwriting its content
	ClipoutRedirect = "}"

	// append to clipboard
	ClipoutRedirect2 = "}}"
)

clipboard redirection

View Source
const StdinRedirect = "-"

stdin

Variables

View Source
var BuiltinCommands = []string{
	"true", "false", "exit", "set", "shift", "unset",
	"echo", "printf", "break", "continue", "pwd", "cd",
	"wait", "builtin", "trap", "type", "source", ".", "command",
	"dirs", "pushd", "popd", "umask", "alias", "unalias",
	"fg", "bg", "getopts", "eval", "test", "[", "exec",
	"return", "read", "mapfile", "readarray", "shopt",
}

bash commands

View Source
var CoreUtilsCommands = []string{
	"base64", "basename", "cat", "chmod", "cp", "date", "dirname", "find", "gzip", "head", "ls", "mkdir",
	"mktemp", "mv", "rm", "shasum", "sleep", "tac", "tail", "tar", "time", "touch", "wget", "xargs",
}

internal commands

Functions

func ActionNameFromFile added in v0.1.1

func ActionNameFromFile(file string) string

Return agent/kit name:

  • agent: pack[/sub]
  • tool: kit:name

if the path matches the following pattern: agents/pack/agent.yaml agents/pack/pack.yaml agents/pack/sub.yaml

tools/kit/name.yaml

func Cat added in v0.1.1

func Cat(a, b, sep string) string

func ClearAllEnv added in v0.1.1

func ClearAllEnv(keeps []string)

ClearAllEnv clears all environment variables execep for the keeps

func CreateAgent

func CreateAgent(ctx context.Context, vars *api.Vars, parent *api.Agent, packname api.Packname, config []byte) (*api.Agent, error)

func GetInput added in v0.1.1

func GetInput(ctx context.Context, argv []string) (*api.InputConfig, error)

func GetUserInput added in v0.1.1

func GetUserInput(ctx context.Context, cfg *api.InputConfig) (*api.UserInput, error)

GetUserInput collects user input for the agent. It prefers a direct message from the command line flag (--message), otherwise, it determines the input source (stdin, clipboard, editor) and collects input accordingly. It also attaches any provided files or template file if provided.

func HandleAction added in v0.1.1

func HandleAction(ctx context.Context, vs *VirtualSystem, args []string) error
func Head(s string, maxLen int) string

Head trims the string to the maxLen and replaces newlines with /.

func IsBuiltin added in v0.1.1

func IsBuiltin(s string) bool

func IsCoreUtils added in v0.1.1

func IsCoreUtils(s string) bool

func IsRestricted added in v0.1.1

func IsRestricted(s string) bool

deny list

func IsShellScript added in v0.1.1

func IsShellScript(s string) bool

return true if the last elemment is or ends in sh/bash

func NewAgentScriptRunner added in v0.1.1

func NewAgentScriptRunner(vars *api.Vars, agent *api.Agent) api.ActionRunner

func NewAgentToolRunner added in v0.1.1

func NewAgentToolRunner(vars *api.Vars, agent *api.Agent) api.ActionRunner

func NewToolSystem added in v0.1.1

func NewToolSystem(base string) (api.ToolSystem, error)

func ParseSpecialChars added in v0.1.1

func ParseSpecialChars(args []string) *api.InputConfig

parse special char sequence for stdin/clipboard they can: + be at the end of the args + be in any order + be multiple instances

func RunCoreUtil added in v0.1.1

func RunCoreUtil(ctx context.Context, vs *VirtualSystem, args []string) error

func Tail added in v0.1.1

func Tail(data string, n int) string

func VirtualCallHandlerFunc added in v0.1.1

func VirtualCallHandlerFunc(vs *VirtualSystem) interp.CallHandlerFunc

TODO set: -e Exit immediately if a command exits with a non-zero status. -o option-name

			pipefail   the return value of a pipeline is the status of
                       the last command to exit with a non-zero status,
                       or zero if no command exited with a non-zero status

-u Treat unset variables as an error when substituting. -x Print commands and their arguments as they are executed.

func VirtualExecHandler added in v0.1.1

func VirtualExecHandler(vs *VirtualSystem, runner *interp.Runner) func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc

func VirtualOpenHandler added in v0.1.1

func VirtualOpenHandler(vs *VirtualSystem) interp.OpenHandlerFunc

func VirtualReadDirHandler2 added in v0.1.1

func VirtualReadDirHandler2(vs *VirtualSystem) interp.ReadDirHandlerFunc2

func VirtualStatHandler added in v0.1.1

func VirtualStatHandler(vs *VirtualSystem) interp.StatHandlerFunc

Types

type AIKit added in v0.1.1

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

func NewAIKit added in v0.1.1

func NewAIKit(vars *api.Vars) *AIKit

func (*AIKit) BuildContext added in v0.1.1

func (r *AIKit) BuildContext(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (any, error)

func (*AIKit) BuildPrompt added in v0.1.1

func (r *AIKit) BuildPrompt(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (any, error)

func (*AIKit) BuildQuery added in v0.1.1

func (r *AIKit) BuildQuery(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (any, error)

func (*AIKit) Call added in v0.1.1

func (r *AIKit) Call(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args map[string]any) (any, error)

func (*AIKit) CallLlm added in v0.1.1

func (r *AIKit) CallLlm(ctx context.Context, vars *api.Vars, agent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (any, error)

func (*AIKit) GetAgentInfo added in v0.1.1

func (r *AIKit) GetAgentInfo(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) GetSkillInfo added in v0.1.1

func (r *AIKit) GetSkillInfo(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) GetToolInfo added in v0.1.1

func (r *AIKit) GetToolInfo(ctx context.Context, vars *api.Vars, _ *api.Agent, _ *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) ListAgents added in v0.1.1

func (r *AIKit) ListAgents(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) ListMessages added in v0.1.1

func (r *AIKit) ListMessages(ctx context.Context, vars *api.Vars, _ *api.Agent, _ *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) ListModels added in v0.1.1

func (r *AIKit) ListModels(ctx context.Context, vars *api.Vars, _ *api.Agent, tf *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) ListSkills added in v0.1.1

func (r *AIKit) ListSkills(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) ListTools added in v0.1.1

func (r *AIKit) ListTools(ctx context.Context, vars *api.Vars, _ *api.Agent, _ *api.ToolFunc, args map[string]any) (string, error)

func (*AIKit) LlmAdapter added in v0.1.1

func (r *AIKit) LlmAdapter(ctx context.Context, vars *api.Vars, agent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (*api.Result, error)

func (*AIKit) NewAgent added in v0.1.1

func (r *AIKit) NewAgent(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (any, error)

func (*AIKit) ReadAgentConfig added in v0.1.1

func (r *AIKit) ReadAgentConfig(ctx context.Context, vars *api.Vars, parent *api.Agent, _ *api.ToolFunc, args api.ArgMap) (*api.AppConfig, error)

func (*AIKit) ReadToolConfig added in v0.1.1

func (r *AIKit) ReadToolConfig(ctx context.Context, vars *api.Vars, _ *api.Agent, _ *api.ToolFunc, args api.ArgMap) (*api.AppConfig, error)

func (*AIKit) SaveMessages added in v0.1.1

func (r *AIKit) SaveMessages(_ context.Context, _ *api.Vars, _ *api.Agent, _ *api.ToolFunc, args api.ArgMap) (*api.Result, error)

func (*AIKit) Sleep added in v0.1.1

func (r *AIKit) Sleep(_ context.Context, _ *api.Vars, _ *api.Agent, _ *api.ToolFunc, args api.ArgMap) (*api.Result, error)

func (*AIKit) SpawnAgent added in v0.1.1

func (r *AIKit) SpawnAgent(ctx context.Context, vars *api.Vars, parent *api.Agent, tf *api.ToolFunc, args api.ArgMap) (*api.Result, error)

agent can be invoked directly by name with kit name "agent:" /agent:pack/sub and agent__pack__sub as tool id by LLM this tool serves as a simple interface for LLM tool calls. agent is required. actions defatult to the following if not set: entrypoint: "ai:new_agent", "ai:build_query", "ai:build_prompt", "ai:build_context", "ai:call_llm"

func (*AIKit) TransferAgent added in v0.1.1

func (r *AIKit) TransferAgent(_ context.Context, _ *api.Vars, _ *api.Agent, _ *api.ToolFunc, args map[string]any) (*api.Result, error)

type AgentCacheKey added in v0.1.1

type AgentCacheKey struct {
	// user email
	User string
	// agent
	Pack string
	Sub  string
}

type AgentScriptRunner added in v0.1.1

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

func (*AgentScriptRunner) Run added in v0.1.1

func (r *AgentScriptRunner) Run(ctx context.Context, script string, args map[string]any) (any, error)

Run command or script. If script is empty, read command or script from args.

type AgentToolRunner added in v0.1.1

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

func (*AgentToolRunner) Run added in v0.1.1

func (r *AgentToolRunner) Run(ctx context.Context, tid string, args map[string]any) (any, error)

Lookup aciton for tid or kit:name in the args if tid is not provided

type ConfigLoader added in v0.1.1

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

func NewConfigLoader added in v0.1.1

func NewConfigLoader(vars *api.Vars) *ConfigLoader

func (*ConfigLoader) Create added in v0.1.1

func (r *ConfigLoader) Create(ctx context.Context, packname api.Packname) (*api.Agent, error)

create agent (class) from config

func (*ConfigLoader) CreateTool added in v0.1.1

func (r *ConfigLoader) CreateTool(tid string) (*api.ToolFunc, error)

func (*ConfigLoader) LoadAgentConfig added in v0.1.1

func (r *ConfigLoader) LoadAgentConfig(packname api.Packname) (*api.AppConfig, error)

func (*ConfigLoader) LoadConfig added in v0.1.1

func (r *ConfigLoader) LoadConfig(s string) (*api.AppConfig, error)

load config for agent/tool

func (*ConfigLoader) LoadContent added in v0.1.1

func (r *ConfigLoader) LoadContent(src string) error

func (*ConfigLoader) LoadToolConfig added in v0.1.1

func (r *ConfigLoader) LoadToolConfig(kn api.Kitname) (*api.AppConfig, error)

func (*ConfigLoader) NewAgent added in v0.1.1

func (r *ConfigLoader) NewAgent(c *api.AgentConfig, pn api.Packname) (*api.Agent, error)

func (*ConfigLoader) ResolveAssets added in v0.1.1

func (r *ConfigLoader) ResolveAssets(ac *api.AppConfig) (*api.AppConfig, error)

Load assets for context, instrution, message, and script

type ExecHandler added in v0.1.1

type ExecHandler func(context.Context, []string) (bool, error)

type IOE added in v0.1.1

type IOE = sh.IOE

type KitKey added in v0.1.1

type KitKey struct {
	Type api.ToolType
	Kit  string
}

func NewKitKey added in v0.1.1

func NewKitKey(fnType api.ToolType, kit string) KitKey

type ListCacheKey added in v0.1.1

type ListCacheKey struct {
	Type string
	User string
}

type SkillEntry added in v0.1.1

type SkillEntry struct {
	Name        string
	Description string
	Path        string
}

type SkillInfo added in v0.1.1

type SkillInfo struct {
	Name        string
	Description string
	Instruction string
	Tools       []string
	References  []string
	Scripts     []string
	Assets      []string
	Path        string
}

type Swarm

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

func New

func New(vars *api.Vars) (*Swarm, error)

func (*Swarm) Exec added in v0.1.1

func (sw *Swarm) Exec(ctx context.Context, input any) (*api.Result, error)

func (*Swarm) Format added in v0.1.1

func (sw *Swarm) Format(ctx context.Context, argm map[string]any) (*api.Result, error)

func (*Swarm) Parse added in v0.1.1

func (sw *Swarm) Parse(ctx context.Context, input any) (api.ArgMap, error)

type VirtualSystem added in v0.1.1

type VirtualSystem struct {
	MaxTimeout int
	// contains filtered or unexported fields
}

func NewVirtualSystem added in v0.1.1

func NewVirtualSystem(vars *api.Vars, agent *api.Agent, ioe *IOE) *VirtualSystem

func (*VirtualSystem) NewRunner added in v0.1.1

func (vs *VirtualSystem) NewRunner(opts ...interp.RunnerOption) (*interp.Runner, error)

func (*VirtualSystem) RunInteractive added in v0.1.1

func (vs *VirtualSystem) RunInteractive(ctx context.Context) error

func (*VirtualSystem) RunPath added in v0.1.1

func (vs *VirtualSystem) RunPath(ctx context.Context, path string) error

func (*VirtualSystem) RunReader added in v0.1.1

func (vs *VirtualSystem) RunReader(ctx context.Context) error

func (*VirtualSystem) RunScript added in v0.1.1

func (vs *VirtualSystem) RunScript(ctx context.Context, script string) error

Directories

Path Synopsis
atm
cmd/sh-git command
tools/git-tool command
https://pkg.go.dev/modernc.org/sqlite https://sqlite.org/docs.html
https://pkg.go.dev/modernc.org/sqlite https://sqlite.org/docs.html
Package flag implements command-line flag parsing.
Package flag implements command-line flag parsing.
llm
xai
tool
web
web/ddg
https://github.com/tmc/langchaingo/blob/main/tools/duckduckgo/internal/client.go https://github.com/tmc/langchaingo?tab=MIT-1-ov-file#readme
https://github.com/tmc/langchaingo/blob/main/tools/duckduckgo/internal/client.go https://github.com/tmc/langchaingo?tab=MIT-1-ov-file#readme
web/scrape
https://github.com/tmc/langchaingo/blob/main/tools/scraper/scraper.go https://github.com/tmc/langchaingo?tab=MIT-1-ov-file#readme
https://github.com/tmc/langchaingo/blob/main/tools/scraper/scraper.go https://github.com/tmc/langchaingo?tab=MIT-1-ov-file#readme

Jump to

Keyboard shortcuts

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