agent

package
v0.0.0-...-1a4fc59 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChatAgent Metadata
	ChatAgentType = "chat"
	// ChatAgent Message Roles
	ChatAgentMessageRoleUser      ChatAgentMessageRole = "user"
	ChatAgentMessageRoleAssistant ChatAgentMessageRole = "assistant"
	ChatAgentMessageRoleSystem    ChatAgentMessageRole = "system"
	// ChatAgent Message Types
	ChatAgentMessageTypeText  ChatAgentMessageType = "text"
	ChatAgentMessageTypeFile  ChatAgentMessageType = "file"
	ChatAgentMessageTypeLink  ChatAgentMessageType = "link"
	ChatAgentMessageTypeQuery ChatAgentMessageType = "query"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	IAgent
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(name string, agentType string, config interface{}) *Agent

NewAgent creates a new agent

id: Unique ID for the agent name: Human-readable name for the agent agentType: Agent type config: Agent configuration

func (*Agent) AddTask

func (a *Agent) AddTask(task IAgentTask) error

AddTask adds a task for the agent to execute in its task loop

task: Task to add

func (*Agent) AwaitAllTasks

func (a *Agent) AwaitAllTasks()

func (*Agent) GetCompletedTasks

func (a *Agent) GetCompletedTasks() AgentTaskMap

func (*Agent) GetConfig

func (a *Agent) GetConfig() interface{}

func (*Agent) GetID

func (a *Agent) GetID() string

func (*Agent) GetKilledTasks

func (a *Agent) GetKilledTasks() AgentTaskMap

func (*Agent) GetName

func (a *Agent) GetName() string

func (*Agent) GetRunningTasks

func (a *Agent) GetRunningTasks() AgentTaskMap

func (*Agent) GetType

func (a *Agent) GetType() string

func (*Agent) IsRunning

func (a *Agent) IsRunning() bool

func (*Agent) Kill

func (a *Agent) Kill()

func (*Agent) Start

func (a *Agent) Start()

func (*Agent) Stop

func (a *Agent) Stop()

type AgentSequentialTaskQueueMap

type AgentSequentialTaskQueueMap map[AgentTaskType]chan IAgentTask

type AgentTask

type AgentTask struct {
	IAgentTask
	// contains filtered or unexported fields
}

func NewAgentTask

func NewAgentTask(name string, taskType AgentTaskType, handler HandlerFunction) *AgentTask

func (*AgentTask) AwaitCompletion

func (t *AgentTask) AwaitCompletion() interface{}

func (*AgentTask) Execute

func (t *AgentTask) Execute(callback func())

func (*AgentTask) GetID

func (t *AgentTask) GetID() string

func (*AgentTask) GetName

func (t *AgentTask) GetName() string

func (*AgentTask) GetResult

func (t *AgentTask) GetResult() interface{}

func (*AgentTask) GetType

func (t *AgentTask) GetType() AgentTaskType

func (*AgentTask) IsCompleted

func (t *AgentTask) IsCompleted() bool

func (*AgentTask) IsSequential

func (t *AgentTask) IsSequential() bool

func (*AgentTask) Kill

func (t *AgentTask) Kill()

func (*AgentTask) WasKilled

func (t *AgentTask) WasKilled() bool

type AgentTaskMap

type AgentTaskMap map[string]*IAgentTask

type AgentTaskType

type AgentTaskType struct {
	Type         string
	IsSequential bool
}

func NewAgentTaskType

func NewAgentTaskType(taskType string, isSequential bool) AgentTaskType

type ChatAgent

type ChatAgent struct {
	*Agent
	OpenAIChatClient *openai.ChatClient
	Messages         []ChatAgentMessage
}

func NewChatAgent

func NewChatAgent(name string, config *ai.AIConfig) *ChatAgent

NewChatAgent creates a new ChatAgent. The ChatAgent can be used to hold a conversation between a language model (currently using OpenAI's APIs), and the user.

Remember to call the Start() method on the ChatAgent!

func (*ChatAgent) AddMessage

func (c *ChatAgent) AddMessage(msg ChatAgentMessage)

func (*ChatAgent) GetLastMessage

func (c *ChatAgent) GetLastMessage() ChatAgentMessage

func (*ChatAgent) GetLastMessageContent

func (c *ChatAgent) GetLastMessageContent() string

func (*ChatAgent) GetLastMessageRole

func (c *ChatAgent) GetLastMessageRole() ChatAgentMessageRole

func (*ChatAgent) GetMessages

func (c *ChatAgent) GetMessages() []ChatAgentMessage

func (*ChatAgent) ProcessChatMessage

func (c *ChatAgent) ProcessChatMessage(msg ChatAgentMessage) ChatAgentMessage

func (*ChatAgent) ResetMessages

func (c *ChatAgent) ResetMessages()

func (*ChatAgent) SendChatMessage

func (c *ChatAgent) SendChatMessage(msg ChatAgentMessage) (*ChatAgentMessage, error)

SendChatMessage marshalls and sends a ChatAgentMessage to the agent. The agent will respond with a ChatAgentMessage that is returned. Note: The content is serialized to JSON before sending in the schema:

{
  "type": string,   // Your message type (e.g. "text", "file", "link", "query")
  "content": string // Your message content (e.g. "Hello", "https://example.com", "What is the weather like in 2023?")
}

func (*ChatAgent) SendChatMessageAndWriteResponseToChannel

func (c *ChatAgent) SendChatMessageAndWriteResponseToChannel(msg ChatAgentMessage, channel chan ChatAgentMessage) error

SendChatMessageAndWriteResponseToChannel serializes and sends a ChatAgentMessage to the agent. The agent will write the response to the provided channel. Note: The content is serialized to JSON before sending in the schema:

{
  "type": string,   // Your message type (e.g. "text", "file", "link", "query")
  "content": string // Your message content (e.g. "Hello", "https://example.com", "What is the weather like in 2023?")
}

func (*ChatAgent) SetMessages

func (c *ChatAgent) SetMessages(msgs []ChatAgentMessage)

type ChatAgentMessage

type ChatAgentMessage struct {
	Type    ChatAgentMessageType
	Role    ChatAgentMessageRole
	Content string
}

func ChatAgentMessageFromJSON

func ChatAgentMessageFromJSON(jsonStr string) (*ChatAgentMessage, error)

func ChatAgentMessageFromOpenAIChatMessage

func ChatAgentMessageFromOpenAIChatMessage(c openai.ChatMessage) *ChatAgentMessage

func NewChatAgentMessage

func NewChatAgentMessage(msgType ChatAgentMessageType, role ChatAgentMessageRole, content string) *ChatAgentMessage

NewChatAgentMessage creates a new ChatAgentMessage. This message can be sent to the ChatAgent to get a response and completion.

msgType: The type of message. Can be one of the following: - ChatAgentMessageTypeText - ChatAgentMessageTypeFile - ChatAgentMessageTypeLink - ChatAgentMessageTypeQuery

role: The role of the message. Can be one of the following: - ChatAgentMessageRoleUser - ChatAgentMessageRoleAssistant - ChatAgentMessageRoleSystem

content: The content of the message. The content can only be a string.

func (*ChatAgentMessage) GetContent

func (c *ChatAgentMessage) GetContent() string

func (*ChatAgentMessage) GetRole

func (*ChatAgentMessage) GetType

func (*ChatAgentMessage) IsAssistantMessage

func (c *ChatAgentMessage) IsAssistantMessage() bool

func (*ChatAgentMessage) IsFileMessage

func (c *ChatAgentMessage) IsFileMessage() bool

func (*ChatAgentMessage) IsLinkMessage

func (c *ChatAgentMessage) IsLinkMessage() bool

func (*ChatAgentMessage) IsMessageOfRole

func (c *ChatAgentMessage) IsMessageOfRole(role ChatAgentMessageRole) bool

func (*ChatAgentMessage) IsMessageOfType

func (c *ChatAgentMessage) IsMessageOfType(msgType ChatAgentMessageType) bool

func (*ChatAgentMessage) IsQueryMessage

func (c *ChatAgentMessage) IsQueryMessage() bool

func (*ChatAgentMessage) IsSystemMessage

func (c *ChatAgentMessage) IsSystemMessage() bool

func (*ChatAgentMessage) IsTextMessage

func (c *ChatAgentMessage) IsTextMessage() bool

func (*ChatAgentMessage) IsUserMessage

func (c *ChatAgentMessage) IsUserMessage() bool

func (*ChatAgentMessage) Marshal

func (c *ChatAgentMessage) Marshal() error

func (*ChatAgentMessage) Serialize

func (c *ChatAgentMessage) Serialize()

func (*ChatAgentMessage) ToJSON

func (c *ChatAgentMessage) ToJSON() (string, error)

func (*ChatAgentMessage) ToOpenAIChatMessage

func (c *ChatAgentMessage) ToOpenAIChatMessage() *openai.ChatMessage

type ChatAgentMessageRole

type ChatAgentMessageRole string

type ChatAgentMessageType

type ChatAgentMessageType string

type ChatAgentTask

type ChatAgentTask struct {
	*AgentTask
}

func NewChatAgentTask

func NewChatAgentTask(agent *ChatAgent, taskType ChatAgentTaskType, payload ChatAgentTaskPayload) (*ChatAgentTask, error)

type ChatAgentTaskPayload

type ChatAgentTaskPayload interface{}

type ChatAgentTaskType

type ChatAgentTaskType string
const (
	ChatAgentTaskTypeSendMessage ChatAgentTaskType = "send_message"
)

type HandlerFunction

type HandlerFunction func(kill chan bool) interface{}

type IAgent

type IAgent interface {
	GetID() string
	GetName() string
	GetType() string
	GetConfig() interface{}
	IsRunning() bool
	GetRunningTasks() AgentTaskMap
	GetCompletedTasks() AgentTaskMap
	GetKilledTasks() AgentTaskMap
	AddTask(task IAgentTask) error

	AwaitAllTasks()

	Start()
	Stop()
	Kill()
	// contains filtered or unexported methods
}

type IAgentTask

type IAgentTask interface {
	GetID() string
	GetName() string
	GetType() AgentTaskType
	IsSequential() bool
	WasKilled() bool
	GetResult() interface{}
	Execute(callback func())
	Kill()
	AwaitCompletion() interface{}
	IsCompleted() bool
}

Jump to

Keyboard shortcuts

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