api

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RoleSystem    = "system"
	RoleAssistant = "assistant"
	RoleUser      = "user"
	RoleTool      = "tool"
)
View Source
const (
	VarsEnvContainer = "container"
	VarsEnvHost      = "host"
)
View Source
const (
	ContentTypeImageB64 = "img/base64"
)

Variables

View Source
var Levels = []Level{L1, L2, L3, Image, TTS}

Functions

func GetArrayProp added in v0.1.1

func GetArrayProp(key string, props map[string]any) ([]string, error)

func GetBoolProp added in v0.1.1

func GetBoolProp(key string, props map[string]any) (bool, error)

func GetIntProp added in v0.1.1

func GetIntProp(key string, props map[string]any) (int, error)

func GetStrProp added in v0.1.1

func GetStrProp(key string, props map[string]any) (string, error)

func IsRequired added in v0.1.1

func IsRequired(key string, props map[string]any) bool

if required properties is not missing and is an array of strings check if the required properties are present

func LogLevelToString added in v0.1.1

func LogLevelToString(level LogLevel) string

func NewBadRequestError added in v0.1.1

func NewBadRequestError(msg string) error

func NewInternalServerError added in v0.1.1

func NewInternalServerError(msg string) error

func NewNotFoundError added in v0.1.1

func NewNotFoundError(msg string) error

func NewUnauthorizedError added in v0.1.1

func NewUnauthorizedError(msg string) error

func NewUnsupportedError added in v0.1.1

func NewUnsupportedError(msg string) error

func ToInt added in v0.1.1

func ToInt(data any) int

func ToString added in v0.1.1

func ToString(data any) string

Types

type ATMSupport added in v0.1.1

type ATMSupport interface {
	AssetStore
	RetrieveAgent(owner, pack string) (*Record, error)
	ListAgents(owner string) ([]*Record, error)
	SearchAgent(owner, pack string) (*Record, error)
	RetrieveTool(owner, kit string) (*Record, error)
	ListTools(owner string) ([]*Record, error)
	RetrieveModel(owner, alias string) (*Record, error)
	ListModels(owner string) ([]*Record, error)
}

agent/tool/model methods

type Action added in v0.1.1

type Action struct {
	// unique identifier
	ID string

	// agent/tool name
	Name string

	// arguments including name
	Arguments *Arguments
}

func NewAction added in v0.11.1

func NewAction(id string, name string, args map[string]any) *Action

type ActionConfig added in v0.11.1

type ActionConfig struct {
	// kit specifies a namespace for the action
	// examples:
	// class name
	// MCP server name
	// file system
	// container name
	// virtual machine name
	// tool/function (Gemini)
	Kit string `yaml:"kit"`

	// action type:
	// func, system, agent...
	Type string `yaml:"type"`

	// action name and arguments
	Name      string         `yaml:"name"`
	Arguments map[string]any `yaml:"arguments"`

	// user message
	Message string `yaml:"message"`

	// system prompt
	Instruction string `yaml:"instruction"`

	// set/level key - not the LLM model
	Model string `yaml:"model"`

	//
	MaxTurns int `yaml:"max_turns"`
	MaxTime  int `yaml:"max_time"`

	// output format: json | text
	Format string `yaml:"format"`

	// memory context
	MaxHistory int    `yaml:"max_history"`
	MaxSpan    int    `yaml:"max_span"`
	Context    string `yaml:"context"`

	// logging: quiet | informative | verbose
	LogLevel string `yaml:"log_level"`
}

func (*ActionConfig) ToMap added in v0.11.1

func (ac *ActionConfig) ToMap() map[string]any

type ActionRunner added in v0.1.1

type ActionRunner interface {
	Run(context.Context, string, map[string]any) (any, error)
}

type Agent

type Agent struct {
	Parent *Agent

	Owner string

	// The name of the agent.
	Name        string
	Display     string
	Description string

	//
	Instruction string
	Context     string
	Message     string

	// The model to be used by the agent
	Model *Model
	// Functions that the agent can call
	Tools []*ToolFunc

	// // default values
	Arguments *Arguments

	// LLM adapter
	Adapter string

	//
	Flow *Flow

	Embed []*Agent

	// global values
	// Environment map[string]any
	Environment *Environment

	//
	Runner ActionRunner

	Template *template.Template
}

func (*Agent) Clone added in v0.5.0

func (a *Agent) Clone() *Agent

for reusing cached agent

func (*Agent) History added in v0.1.1

func (a *Agent) History() []*Message

func (*Agent) Prompt added in v0.1.1

func (a *Agent) Prompt() string

func (*Agent) Query added in v0.1.1

func (a *Agent) Query() string

ai operations

func (*Agent) Result added in v0.11.1

func (a *Agent) Result() string

func (*Agent) SetHistory added in v0.11.1

func (a *Agent) SetHistory(messages []*Message) *Agent

func (*Agent) SetPrompt added in v0.11.1

func (a *Agent) SetPrompt(s string) *Agent

func (*Agent) SetQuery added in v0.11.1

func (a *Agent) SetQuery(s string) *Agent

func (*Agent) SetResult added in v0.11.1

func (a *Agent) SetResult(v string) *Agent

type AgentConfig

type AgentConfig struct {
	Display     string `yaml:"display"`
	Description string `yaml:"description"`

	// tools defined in tools config
	// kit:name
	Functions []string `yaml:"functions"`

	Flow *FlowConfig `yaml:"flow"`

	// chat|image|docker/aider oh gptr
	Adapter string `yaml:"adapter"`

	// name of custom creator agent for this agent configuration
	Creator string `yaml:"creator"`

	// middleware chain
	Chain *ChainConfig `yaml:"chain"`

	// default agents config
	Name      string         `yaml:"name"`
	Arguments map[string]any `yaml:"arguments"`

	Instruction string `yaml:"instruction"`
	Context     string `yaml:"context"`
	Message     string `yaml:"message"`

	Model string `yaml:"model"`

	//
	MaxTurns int `yaml:"max_turns"`
	MaxTime  int `yaml:"max_time"`

	// output format: json | text
	Format string `yaml:"format"`

	// memory
	// max history: 0 max span: 0
	// New        *bool  `yaml:"new,omitempty"`
	MaxHistory int `yaml:"max_history"`
	MaxSpan    int `yaml:"max_span"`

	// logging: quiet | info[rmative] | verbose | trace
	LogLevel string `yaml:"log_level"`

	// agent as tool
	Parameters map[string]any `yaml:"parameters"`

	// agent global vars
	Environment map[string]any `yaml:"environment"`

	// security
	Filters []*IOFilter  `yaml:"filters"`
	Guards  []*ToolGuard `yaml:"guards"`

	// inherit from embedded parent:
	// + environment
	// + instruction
	// + functions
	// local scope:
	// - arguments
	// - context
	// - message
	// - model
	// - flow/actions
	Embed []string `yaml:"embed"`

	//
	Store AssetStore `yaml:"-"`
	// relative to root
	BaseDir string `yaml:"-"`
}

func (*AgentConfig) ToMap added in v0.1.1

func (ac *AgentConfig) ToMap() map[string]any

type AgentsConfig

type AgentsConfig AppConfig

pack config

func (*AgentsConfig) ToMap added in v0.11.1

func (ac *AgentsConfig) ToMap() map[string]any

type AppConfig

type AppConfig struct {
	// ActionConfig
	//
	// kit specifies a namespace for the action
	// examples:
	// class name
	// MCP server name
	// file system
	// container name
	// virtual machine name
	// tool/function (Gemini)
	Kit string `yaml:"kit"`

	// action type:
	// func, system, agent...
	Type string `yaml:"type"`

	// action name and arguments
	Name      string         `yaml:"name"`
	Arguments map[string]any `yaml:"arguments"`

	// user message
	Message string `yaml:"message"`

	// system prompt
	Instruction string `yaml:"instruction"`

	// set/level key - not the LLM model
	Model string `yaml:"model"`

	//
	MaxTurns int `yaml:"max_turns"`
	MaxTime  int `yaml:"max_time"`

	// output format: json | text
	Format string `yaml:"format"`

	// memory context
	MaxHistory int    `yaml:"max_history"`
	MaxSpan    int    `yaml:"max_span"`
	Context    string `yaml:"context"`

	// logging: quiet | informative | verbose
	LogLevel string `yaml:"log_level"`

	// app level global vars
	Environment map[string]any `yaml:"environment"`

	//
	// unique identifier
	ID string `yaml:"-"`

	// app root. default: $HOME/.ai/
	Base string `yaml:"-"`

	// auth email
	User string `yaml:"-"`

	// workspace root. default: <base>/workspace
	Workspace string `yaml:"-"`

	Session string `yaml:"-"`

	// name of custom creator agent for this agent configuration
	Creator string `yaml:"creator"`

	// middleware chain
	Chain *ChainConfig `yaml:"chain"`

	//
	Pack string `yaml:"pack"`

	Agents []*AgentConfig `yaml:"agents"`

	// tool / model provider
	Provider string `yaml:"provider"`
	BaseUrl  string `yaml:"base_url"`

	// api token lookup key
	ApiKey string `yaml:"api_key"`

	// action type:
	// func, system, agent...
	// Type  string        `yaml:"type"`
	Tools []*ToolConfig `yaml:"tools"`

	// modelset name
	Set    string                  `yaml:"set"`
	Models map[string]*ModelConfig `yaml:"models"`

	// TODO use arguments
	Clipin     bool
	ClipWait   bool
	Clipout    bool
	ClipAppend bool
	Stdin      bool
}

func (*AppConfig) HasInput

func (cfg *AppConfig) HasInput() bool

func (*AppConfig) Interactive

func (cfg *AppConfig) Interactive() bool

func (*AppConfig) IsClipin

func (cfg *AppConfig) IsClipin() bool

func (*AppConfig) IsInformative added in v0.1.1

func (cfg *AppConfig) IsInformative() bool

func (*AppConfig) IsNew added in v0.5.1

func (cfg *AppConfig) IsNew() bool

func (*AppConfig) IsQuiet added in v0.1.1

func (cfg *AppConfig) IsQuiet() bool

func (*AppConfig) IsSpecial

func (cfg *AppConfig) IsSpecial() bool

func (*AppConfig) IsStdin

func (cfg *AppConfig) IsStdin() bool

func (*AppConfig) IsTracing added in v0.1.1

func (cfg *AppConfig) IsTracing() bool

func (*AppConfig) IsVerbose added in v0.1.1

func (cfg *AppConfig) IsVerbose() bool

func (*AppConfig) ToMap added in v0.1.1

func (ac *AppConfig) ToMap() map[string]any

ToMap converts AppConfig to a map[string]any map only the fileds common in action config and only for non zero values.

type ArgMap added in v0.1.1

type ArgMap map[string]any

func NewArgMap added in v0.1.1

func NewArgMap() ArgMap

func (ArgMap) Get added in v0.1.1

func (v ArgMap) Get(key string) any

taken from viper@1.21.0

func (ArgMap) GetBool added in v0.1.1

func (v ArgMap) GetBool(key string) bool

func (ArgMap) GetDuration added in v0.1.1

func (v ArgMap) GetDuration(key string) time.Duration

func (ArgMap) GetFloat64 added in v0.1.1

func (v ArgMap) GetFloat64(key string) float64

func (ArgMap) GetInt added in v0.1.1

func (v ArgMap) GetInt(key string) int

func (ArgMap) GetInt32 added in v0.1.1

func (v ArgMap) GetInt32(key string) int32

func (ArgMap) GetInt64 added in v0.1.1

func (v ArgMap) GetInt64(key string) int64

func (ArgMap) GetIntSlice added in v0.1.1

func (v ArgMap) GetIntSlice(key string) []int

func (ArgMap) GetString added in v0.1.1

func (v ArgMap) GetString(key string) string

func (ArgMap) GetStringMap added in v0.1.1

func (v ArgMap) GetStringMap(key string) map[string]any

func (ArgMap) GetStringMapString added in v0.1.1

func (v ArgMap) GetStringMapString(key string) map[string]string

func (ArgMap) GetStringMapStringSlice added in v0.1.1

func (v ArgMap) GetStringMapStringSlice(key string) map[string][]string

func (ArgMap) GetStringSlice added in v0.1.1

func (v ArgMap) GetStringSlice(key string) []string

func (ArgMap) GetTime added in v0.1.1

func (v ArgMap) GetTime(key string) time.Time

func (ArgMap) GetUint added in v0.1.1

func (v ArgMap) GetUint(key string) uint

func (ArgMap) GetUint8 added in v0.1.1

func (v ArgMap) GetUint8(key string) uint8

func (ArgMap) GetUint16 added in v0.1.1

func (v ArgMap) GetUint16(key string) uint16

func (ArgMap) GetUint32 added in v0.1.1

func (v ArgMap) GetUint32(key string) uint32

func (ArgMap) GetUint64 added in v0.1.1

func (v ArgMap) GetUint64(key string) uint64

func (ArgMap) Kit added in v0.12.0

func (a ArgMap) Kit() string

func (ArgMap) Kitname added in v0.1.1

func (a ArgMap) Kitname() Kitname

func (ArgMap) Type added in v0.1.1

func (a ArgMap) Type() string

type Arguments added in v0.1.1

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

func NewArguments added in v0.1.1

func NewArguments() *Arguments

func (*Arguments) AddArgs added in v0.1.1

func (r *Arguments) AddArgs(args map[string]any) *Arguments

func (*Arguments) Clone added in v0.11.1

func (r *Arguments) Clone() *Arguments

func (*Arguments) Copy added in v0.1.1

func (r *Arguments) Copy(dst map[string]any) *Arguments

func (*Arguments) Get added in v0.11.1

func (r *Arguments) Get(key string) (any, bool)

func (*Arguments) GetAllArgs added in v0.11.1

func (r *Arguments) GetAllArgs() map[string]any

func (*Arguments) GetArgs added in v0.1.1

func (r *Arguments) GetArgs(keys []string) map[string]any

Return args specified by keys

func (*Arguments) GetInt added in v0.11.1

func (r *Arguments) GetInt(key string) int

func (*Arguments) GetString added in v0.11.1

func (r *Arguments) GetString(key string) string

func (*Arguments) Message added in v0.11.1

func (r *Arguments) Message() string

func (*Arguments) Set added in v0.11.1

func (r *Arguments) Set(key string, val any) *Arguments

func (*Arguments) SetArgs added in v0.1.1

func (r *Arguments) SetArgs(args map[string]any) *Arguments

clear all entries and copy args while maintaining the same old reference

func (*Arguments) SetMessage added in v0.11.1

func (r *Arguments) SetMessage(s any) *Arguments

type AssetFS added in v0.1.1

type AssetFS interface {
	AssetStore
	ReadDir(name string) ([]DirEntry, error)
	ReadFile(name string) ([]byte, error)
	Resolve(parent string, name string) string
}

type AssetManager added in v0.1.1

type AssetManager interface {
	// GetStore(key string) (AssetStore, error)
	AddStore(store AssetStore)

	SearchAgent(owner, pack string) (*Record, error)
	ListAgent(owner string) (map[string]*AgentsConfig, error)
	FindAgent(owner, pack string) (*AgentsConfig, error)
	ListToolkit(owner string) (map[string]*ToolsConfig, error)
	FindToolkit(owner string, kit string) (*ToolsConfig, error)
	ListModels(owner string) (map[string]*ModelsConfig, error)
	FindModels(owner string, alias string) (*ModelsConfig, error)
}

type AssetStore

type AssetStore any

type BadRequestError added in v0.1.1

type BadRequestError struct {
	Message string
}

func (*BadRequestError) Error added in v0.1.1

func (e *BadRequestError) Error() string

type Blob added in v0.1.1

type Blob struct {
	ID       string         `json:"id"`
	MimeType string         `json:"mime_type"`
	Content  []byte         `json:"content"`
	Meta     map[string]any `json:"meta"`
}

https://en.wikipedia.org/wiki/Media_type https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types https://mimesniff.spec.whatwg.org/

type BlobStore added in v0.1.1

type BlobStore interface {
	Put(ID string, blob *Blob) error
	Get(ID string) (*Blob, error)
	Presign(ID string) (string, error)
}

Object store

type ChainConfig added in v0.11.1

type ChainConfig struct {
	// action list
	Middleware []string `yaml:"middelware"`
}

type ClipboardProvider

type ClipboardProvider interface {
	Clear() error
	Read() (string, error)
	Get() (string, error)
	Write(string) error
	Append(string) error
}

type ConnectorConfig added in v0.0.2

type ConnectorConfig struct {

	// optional as of now
	Provider string `yaml:"provider"`

	BaseUrl string `yaml:"base_url"`
	// name of api lookup key
	ApiKey string `yaml:"api_key"`
}

type ContextKey added in v0.1.1

type ContextKey string
const SwarmUserContextKey ContextKey = "swarm_user"

type DHNTConfig added in v0.1.1

type DHNTConfig struct {
	Blob   *ResourceConfig   `json:"blob"`
	Assets []*ResourceConfig `json:"assets"`
}

func LoadDHNTConfig added in v0.1.1

func LoadDHNTConfig(conf string) (*DHNTConfig, error)

type DirEntry

type DirEntry = fs.DirEntry

Resource Store

func NewDirEntry

func NewDirEntry(
	name string,
	isDir bool,
	mode uint32,
	info *FileInfo,
) DirEntry

type DirEntryInfo

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

func FsDirEntryInfo

func FsDirEntryInfo(de fs.DirEntry) *DirEntryInfo

func (*DirEntryInfo) Info

func (r *DirEntryInfo) Info() (fs.FileInfo, error)

func (*DirEntryInfo) IsDir

func (r *DirEntryInfo) IsDir() bool

func (DirEntryInfo) MarshalJSON

func (r DirEntryInfo) MarshalJSON() ([]byte, error)

func (*DirEntryInfo) Name

func (r *DirEntryInfo) Name() string

func (*DirEntryInfo) Type

func (r *DirEntryInfo) Type() fs.FileMode

func (*DirEntryInfo) UnmarshalJSON

func (r *DirEntryInfo) UnmarshalJSON(data []byte) error

type EditorProvider

type EditorProvider interface {
	Launch(string) (string, error)
}

type Environment added in v0.1.1

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

func NewEnvironment added in v0.1.1

func NewEnvironment() *Environment

func (*Environment) AddEnvs added in v0.1.1

func (g *Environment) AddEnvs(src map[string]any)

copy all src values to the environment env

func (*Environment) Apply added in v0.1.1

func (g *Environment) Apply(fn func(map[string]any) error) error

thread safe access to the env

func (*Environment) Clone added in v0.11.1

func (g *Environment) Clone() *Environment

func (*Environment) Copy added in v0.1.1

func (g *Environment) Copy(dst map[string]any)

copy all environment env to dst

func (*Environment) Get added in v0.1.1

func (g *Environment) Get(key string) (any, bool)

func (*Environment) GetAllEnvs added in v0.1.1

func (g *Environment) GetAllEnvs() map[string]any

func (*Environment) GetEnvs added in v0.1.1

func (g *Environment) GetEnvs(keys []string) map[string]any

Return envs specified by keys

func (*Environment) GetInt added in v0.1.1

func (g *Environment) GetInt(key string) int

func (*Environment) GetString added in v0.1.1

func (g *Environment) GetString(key string) string

func (*Environment) Set added in v0.1.1

func (g *Environment) Set(key string, val any)

func (*Environment) SetEnvs added in v0.1.1

func (g *Environment) SetEnvs(envs map[string]any)

Clear all entries from the map and copy the new values while maintaining the same old reference.

func (*Environment) UnsetEnvs added in v0.1.1

func (g *Environment) UnsetEnvs(keys []string)

type FileInfo

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

func FsFileInfo

func FsFileInfo(fi fs.FileInfo) *FileInfo

func NewFileInfo

func NewFileInfo(
	name string,
	size int64,
	mode uint32,
	modTime time.Time,
	isDir bool,
) *FileInfo

func (*FileInfo) IsDir

func (r *FileInfo) IsDir() bool

func (FileInfo) MarshalJSON

func (fi FileInfo) MarshalJSON() ([]byte, error)

func (*FileInfo) ModTime

func (r *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (r *FileInfo) Mode() fs.FileMode

func (*FileInfo) Name

func (r *FileInfo) Name() string

func (*FileInfo) Size

func (r *FileInfo) Size() int64

func (*FileInfo) Sys

func (r *FileInfo) Sys() any

func (*FileInfo) UnmarshalJSON

func (fi *FileInfo) UnmarshalJSON(data []byte) error

type Flow added in v0.9.0

type Flow struct {
	Type FlowType
	// Expression string
	// Concurrency int
	// Retry       int
	Actions []*Action
	Script  string
}

type FlowConfig added in v0.9.0

type FlowConfig struct {
	Type FlowType `yaml:"type"`

	// agent/tool list for non script flow
	Actions []string `yaml:"actions"`

	// content of the script for flow type: script
	Script string `yaml:"script"`
}

type FlowType added in v0.1.1

type FlowType string
const (
	// FlowTypeSequence executes actions one after another, where each
	// subsequent action uses the previous action's response as input.
	FlowTypeSequence FlowType = "sequence"

	// FlowTypeParallel executes actions simultaneously, returning the combined results as a list.
	// This allows for concurrent processing of independent actions.
	FlowTypeParallel FlowType = "parallel"

	// FlowTypeMap applies specified action(s) to each element in the input array, creating a new
	// array populated with the results.
	FlowTypeMap FlowType = "map"

	// FlowTypeShell delegates control to a shell script using bash script syntax, enabling
	// complex flow control scenarios driven by external scripting logic.
	FlowTypeShell FlowType = "shell"
)

type FuncBody added in v0.1.1

type FuncBody struct {
	Language string `yaml:"language"`
	Code     string `yaml:"code"`
	Url      string `yaml:"url"`
}

type Handler added in v0.1.0

type Handler interface {
	Serve(*Request, *Response) error
}

Action handler

type HandlerFunc added in v0.1.1

type HandlerFunc func(req *Request, res *Response) error

func (HandlerFunc) Serve added in v0.1.1

func (f HandlerFunc) Serve(req *Request, res *Response) error

type IOFilter added in v0.5.0

type IOFilter struct {
	Agent string
}

type InternalServerError added in v0.1.1

type InternalServerError struct {
	Message string
}

func (*InternalServerError) Error added in v0.1.1

func (e *InternalServerError) Error() string

type Kitname added in v0.1.1

type Kitname string

Took Kit and Name

func (Kitname) Decode added in v0.1.1

func (r Kitname) Decode() (string, string)

kit__name kit:* kit:name agent:name @name @:name

func (Kitname) ID added in v0.1.1

func (r Kitname) ID() string

^[a-zA-Z0-9_-]+$

func (Kitname) IsAgent added in v0.11.1

func (r Kitname) IsAgent() bool

agent: agent__

func (Kitname) String added in v0.1.1

func (r Kitname) String() string

type Level added in v0.0.3

type Level = string

Level represents the "intelligence" level of the model. i.e. basic, regular, advanced for example, OpenAI: gpt-4.1-mini, gpt-4.1, o3

const (
	// any of L1/L2/L3
	Any Level = "any"

	L1 Level = "L1"
	L2 Level = "L2"
	L3 Level = "L3"
	//
	Image Level = "image"
	TTS   Level = "tts"
)

type LogLevel added in v0.1.1

type LogLevel int
const (
	Quiet LogLevel = iota + 1
	Informative
	Verbose
	Tracing
)

func ToLogLevel added in v0.1.1

func ToLogLevel(level string) LogLevel

func (LogLevel) String added in v0.1.1

func (r LogLevel) String() string

type MemOption added in v0.0.3

type MemOption struct {
	MaxHistory int
	MaxSpan    int
}

Memory store

type MemStore added in v0.0.3

type MemStore interface {
	Save([]*Message) error
	Load(*MemOption) ([]*Message, error)
	Get(string) (*Message, error)
}

type Message

type Message struct {
	// message id
	ID string `json:"id"`

	// thread id
	Session string    `json:"session"`
	Created time.Time `json:"created"`

	// data
	ContentType string `json:"content_type"`
	Content     string `json:"content"`

	// system | assistant | user
	Role string `json:"role"`

	// user/agent
	Sender string `json:"sender"`
}

type Middleware added in v0.1.1

type Middleware func(*Agent, Handler) Handler

type Model

type Model struct {
	// model @agent or resolved provider model name
	// example:
	//   @model
	//   gemini-2.0-flash-lite
	Model string `json:"model"`

	Provider string `json:"provider"`
	BaseUrl  string `json:"base_url"`

	// api token lookup key
	ApiKey string `json:"api_key"`
}

func (*Model) String added in v0.1.1

func (r *Model) String() string

type ModelConfig

type ModelConfig struct {
	// LLM model
	Model string `yaml:"model"`

	// LLM service provider: openai | gemini | anthropic
	Provider string `yaml:"provider"`
	BaseUrl  string `yaml:"base_url"`
	// name of api key
	ApiKey string `yaml:"api_key"`
}

type ModelsConfig added in v0.0.3

type ModelsConfig AppConfig

modelset config

type NotFoundError added in v0.1.1

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error added in v0.1.1

func (e *NotFoundError) Error() string

type Output

type Output struct {
	// Agent icon and name
	Display string `json:"display"`

	Content     string `json:"content"`
	ContentType string `json:"content_type"`
}

type Packname added in v0.1.1

type Packname string

@pack[/sub] agent:pack[/sub] @*

func (Packname) Decode added in v0.1.1

func (a Packname) Decode() (string, string)

@pack[/sub] agent:pack[/sub]

func (Packname) Equal added in v0.1.1

func (a Packname) Equal(s string) bool

func (Packname) String added in v0.1.1

func (a Packname) String() string

type Record added in v0.1.1

type Record struct {
	ID uuid.UUID

	Owner   string
	Name    string
	Display string
	Content string

	// source
	Store AssetStore
}

type Request

type Request struct {
	// parent agent
	Agent *Agent

	// active action name
	Name      string
	Arguments *Arguments

	// LLM
	Model *Model

	Messages []*Message

	Runner ActionRunner

	Tools []*ToolFunc

	// get api token for LLM model
	Token func() string
	// contains filtered or unexported fields
}

func NewRequest added in v0.1.1

func NewRequest(ctx context.Context, name string, args map[string]any) *Request

func (*Request) Clone

func (r *Request) Clone() *Request

Clone returns a shallow copy of r while ensuring proper copying of slices and maps

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the request's context. To change the context, use Request.WithContext.

The returned context is always non-nil; it defaults to the background context.

For outgoing client requests, the context controls cancellation.

For incoming server requests, the context is canceled when the client's connection closes, the request is canceled (with HTTP/2), or when the ServeHTTP method returns.

func (*Request) MaxTurns added in v0.1.1

func (r *Request) MaxTurns() int

func (*Request) MemOption added in v0.1.1

func (r *Request) MemOption() *MemOption

func (*Request) Message added in v0.1.1

func (r *Request) Message() string

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) *Request

WithContext returns a shallow copy of r with its context changed to ctx. The provided ctx must be non-nil.

For outgoing client request, the context controls the entire lifetime of a request and its response: obtaining a connection, sending the request, and reading the response headers and body.

To create a new request with a context, use NewRequest. To make a deep copy of a request with a new context, use Request.Clone.

type Resource

type Resource struct {
	// web resource base url
	// http://localhost:18080/resource
	// https://ai.dhnt.io/resource
	Base string `json:"base"`

	// access token
	Token string `json:"token"`
}

type ResourceConfig added in v0.1.1

type ResourceConfig struct {
	Type  string `json:"type"`
	Base  string `json:"base"`
	Token string `json:"token"`
}

type Response

type Response struct {
	// A list of message objects generated during the conversation
	// with a sender field indicating which Agent the message originated from.
	Messages []*Message

	// The last agent to handle a message
	Agent *Agent

	Result *Result
}

type Result

type Result struct {
	// author of the reponse: assistant
	Role string
	// The result value as a string
	Value string

	// media content
	// https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types
	MimeType string
	Content  []byte

	// transition
	// The agent state
	State State
	// The agent name to transfer to for StateTransfer
	NextAgent string

	//
	Actions []*ToolCall
}

Result encapsulates the possible return values for agent/function.

func ToResult added in v0.1.1

func ToResult(data any) *Result

func (*Result) String

func (r *Result) String() string

type SecretStore added in v0.1.1

type SecretStore interface {
	Get(owner, key string) (string, error)
}

type State

type State int
const (
	StateExit State = iota

	// TODO terminate state for early tool call termination/cancclation
	StateTransfer
	StateInputWait
	StateToolCall
)

func ParseState

func ParseState(state string) State

func (State) Equal

func (s State) Equal(state string) bool

func (State) String

func (s State) String() string

type TemplateFuncMap

type TemplateFuncMap = template.FuncMap

type ToolCall added in v0.1.1

type ToolCall Action

openai: ChatCompletionMessageToolCallUnion genai: FunctionCall anthropic: ToolUseBlock

func NewToolCall added in v0.1.1

func NewToolCall(id string, name string, args map[string]any) *ToolCall

type ToolCallEntry added in v0.1.1

type ToolCallEntry struct {
	ID        string         `json:"id"`
	Kit       string         `json:"kit"`
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments"`

	Error  error `json:"error"`
	Result any   `json:"result"`

	Timestamp time.Time `json:"timestamp"`
}

func (*ToolCallEntry) ToJSON added in v0.1.1

func (r *ToolCallEntry) ToJSON() (string, error)

type ToolCondition

type ToolCondition struct {
	// required env list
	Env []string `yaml:"env"`

	// found on PATH
	Lookup *string `yaml:"lookup"`

	// shell required
	Shell map[string]any `yaml:"shell"`
}

TODO condidtion needs to be met for tools to be enabled

type ToolConfig

type ToolConfig struct {
	Type string `yaml:"type"`

	Name        string `yaml:"name"`
	Description string `yaml:"description"`

	Parameters map[string]any `yaml:"parameters"`

	Body *FuncBody `yaml:"body"`

	Condition *ToolCondition `yaml:"condition"`

	// agent name for agent tool type
	// description/parameters defined here take precedence
	Agent string `yaml:"agent"`

	//
	Provider string `yaml:"provider"`
	BaseUrl  string `yaml:"base_url"`
	// name of api key
	ApiKey string `yaml:"api_key"`

	// filter by match key=values (comma, separated)
	// include all tools that match
	Filter map[string]string `yaml:"filter"`
}

type ToolEnv added in v0.9.0

type ToolEnv struct {
	Owner string
	Agent *Agent
	FS    fs.FS
}

per tool call vars

type ToolFunc

type ToolFunc struct {
	Type string

	Kit         string
	Name        string
	Description string
	Parameters  map[string]any

	Body *FuncBody

	// agent name if this tool references an agent
	Agent string

	//
	State State

	//
	Provider string
	BaseUrl  string
	// name of api key - used to resolve api key/token before tool call
	ApiKey string

	// extra features.
	// e.g labels for mcp for filtering tools
	Extra map[string]any

	// default arguments
	Arguments map[string]any
}

func (*ToolFunc) Clone added in v0.11.0

func (r *ToolFunc) Clone() *ToolFunc

func (*ToolFunc) ID

func (r *ToolFunc) ID() string

ID returns a unique identifier for the tool, combining the tool kit and name. A string that must match the pattern '^[a-zA-Z0-9_-]+$'."

type ToolGuard added in v0.1.1

type ToolGuard struct {
	Agent string
}

type ToolKit added in v0.1.1

type ToolKit interface {
	Call(context.Context, *Vars, *ToolEnv, *ToolFunc, map[string]any) (any, error)
}

type ToolSystem added in v0.0.2

type ToolSystem interface {
	GetKit(key any) (ToolKit, error)
	AddKit(key any, kit ToolKit)
}

type ToolType added in v0.1.1

type ToolType = string

TODO real type of string

const (
	ToolTypeFunc   ToolType = "func"
	ToolTypeSystem ToolType = "system"
	ToolTypeWeb    ToolType = "web"
	ToolTypeMcp    ToolType = "mcp"
	ToolTypeFaas   ToolType = "faas"
	ToolTypeAgent  ToolType = "agent"
)

type ToolsConfig

type ToolsConfig AppConfig

Toolkit config

type UnauthorizedError added in v0.1.1

type UnauthorizedError struct {
	Message string
}

func (*UnauthorizedError) Error added in v0.1.1

func (e *UnauthorizedError) Error() string

type UnsupportedError added in v0.1.1

type UnsupportedError struct {
	Message string
}

func (*UnsupportedError) Error added in v0.1.1

func (e *UnsupportedError) Error() string

type User

type User struct {
	// uuid
	ID string `json:"id"`

	// emoji + nickname
	Display string `json:"display"`

	Email string `json:"email"`

	// full/first,last
	Name string `json:"name"`

	Avatar string `json:"avatar"`

	Settings map[string]any `json:"settings"`
}

func (*User) Agent added in v0.1.1

func (r *User) Agent() string

func (*User) SetAgent added in v0.1.1

func (r *User) SetAgent(s string)

type UserInput

type UserInput struct {
	// cached media contents
	Messages []*Message `json:"-"`

	Arguments map[string]any `json:"arguments"`
}

func (*UserInput) Clone added in v0.4.0

func (r *UserInput) Clone() *UserInput

func (*UserInput) Intent

func (r *UserInput) Intent() string

Intent returns a clipped version of the query. This is intended for "smart" agents to make decisions based on user inputs.

func (*UserInput) IsEmpty

func (r *UserInput) IsEmpty() bool

No user input.

func (*UserInput) Query

func (r *UserInput) Query() string

Text input from command line args, clipboard, stdin, or editor

func (*UserInput) String

func (r *UserInput) String() string

type Vars

type Vars struct {
	Global *Environment `json:"-"`
	// contains filtered or unexported fields
}

global context

func NewVars

func NewVars() *Vars

func (*Vars) AddToolCall added in v0.11.1

func (v *Vars) AddToolCall(item *ToolCallEntry)

func (*Vars) ToolCalllog added in v0.11.1

func (v *Vars) ToolCalllog() (string, error)

Jump to

Keyboard shortcuts

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