agents

package
v0.0.0-...-7b96089 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetState

func GetState[T any](state WorldState, k WorldStateKey[T]) (def T)

func SetState

func SetState[T any](state WorldState, k WorldStateKey[T], v T)

Types

type Agent

type Agent interface {
	AnalysisSession

	Profile() *Profile
	Log() thoughtstream.Branch
	History() []*thoughtstream.Thought
	WorldState() WorldState

	AttachTo(r Router)
	ForkSession() (AnalysisSession, error)

	Step(ctx context.Context, options ...StepOption) error
}

type AgentBase

type AgentBase struct {
	psi.NodeBase
	// contains filtered or unexported fields
}

func (*AgentBase) AttachTo

func (a *AgentBase) AttachTo(router Router)

func (*AgentBase) EmitMessage

func (a *AgentBase) EmitMessage(ctx context.Context, msg *thoughtstream.Thought) error

func (*AgentBase) ForkSession

func (a *AgentBase) ForkSession() (AnalysisSession, error)

func (*AgentBase) History

func (a *AgentBase) History() []*thoughtstream.Thought

func (*AgentBase) Init

func (a *AgentBase) Init(
	self Agent,
	profile *Profile,
	repo thoughtstream.Resolver,
	log thoughtstream.Branch,
	worldState WorldState,
)

func (*AgentBase) Introspect

func (a *AgentBase) Introspect(ctx context.Context, prompt AgentPrompt, options ...StepOption) (reply *thoughtstream.Thought, err error)

func (*AgentBase) Log

func (a *AgentBase) Log() thoughtstream.Branch

func (*AgentBase) Profile

func (a *AgentBase) Profile() *Profile

func (*AgentBase) ReceiveMessage

func (a *AgentBase) ReceiveMessage(ctx context.Context, msg *thoughtstream.Thought) error

func (*AgentBase) Repo

func (a *AgentBase) Repo() thoughtstream.Resolver

func (*AgentBase) RunPostCycleHooks

func (a *AgentBase) RunPostCycleHooks(ctx context.Context) error

func (*AgentBase) Step

func (a *AgentBase) Step(ctx context.Context, options ...StepOption) error

func (*AgentBase) WorldState

func (a *AgentBase) WorldState() WorldState

type AgentContext

type AgentContext interface {
	Context() context.Context
	Profile() *Profile
	Agent() Agent
	Branch() thoughtstream.Branch
	Stream() thoughtstream.Stream
	WorldState() WorldState
}

type AgentContextBase

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

func (AgentContextBase) Agent

func (c AgentContextBase) Agent() Agent

func (AgentContextBase) Branch

func (AgentContextBase) Context

func (c AgentContextBase) Context() context.Context

func (AgentContextBase) Profile

func (c AgentContextBase) Profile() *Profile

func (AgentContextBase) Stream

func (AgentContextBase) WorldState

func (c AgentContextBase) WorldState() WorldState

type AgentPrompt

type AgentPrompt interface {
	Render(ctx AgentContext) (chat.Message, error)
}

type AgentPromptFunc

type AgentPromptFunc func(ctx AgentContext) (chat.Message, error)

func AgentMessage

func AgentMessage(name, text string) AgentPromptFunc

func ComposePrompt

func ComposePrompt(prompts ...AgentPrompt) AgentPromptFunc

func LogHistory

func LogHistory() AgentPromptFunc

func MapToPrompt

func MapToPrompt[T any](items []T, fn func(T) AgentPrompt) AgentPromptFunc

func MessageToPrompt

func MessageToPrompt(msg chat.Message) AgentPromptFunc

func SystemMessage

func SystemMessage(msg string) AgentPromptFunc

func ThoughtHistory

func ThoughtHistory(iterator thoughtstream.Iterable) AgentPromptFunc

func Tml

func Tml(rootBuilder func(ctx AgentContext) promptml.Parent) AgentPromptFunc

func TmlContainer

func TmlContainer(children ...promptml.Node) AgentPromptFunc

func (AgentPromptFunc) Render

func (a AgentPromptFunc) Render(ctx AgentContext) (chat.Message, error)

type AnalysisSession

type AnalysisSession interface {
	psi.Node

	Introspect(ctx context.Context, prompt AgentPrompt, options ...StepOption) (*thoughtstream.Thought, error)

	ReceiveMessage(ctx context.Context, msg *thoughtstream.Thought) error
}

type BroadcastRouter

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

func NewRouter

func NewRouter(log thoughtstream.Branch) *BroadcastRouter

func (*BroadcastRouter) OutgoingMessages

func (r *BroadcastRouter) OutgoingMessages() []*thoughtstream.Thought

func (*BroadcastRouter) ReceiveIncomingMessage

func (r *BroadcastRouter) ReceiveIncomingMessage(ctx context.Context, msg *thoughtstream.Thought)

func (*BroadcastRouter) RegisterAgent

func (r *BroadcastRouter) RegisterAgent(agent Agent)

func (*BroadcastRouter) ResetOutbox

func (r *BroadcastRouter) ResetOutbox()

func (*BroadcastRouter) RouteIncomingMessages

func (r *BroadcastRouter) RouteIncomingMessages(ctx context.Context) error

func (*BroadcastRouter) RouteMessage

func (r *BroadcastRouter) RouteMessage(ctx context.Context, msg *thoughtstream.Thought) error

type Colab

type Colab struct {
	psi.NodeBase
	// contains filtered or unexported fields
}

func NewColab

func NewColab(state WorldState, log thoughtstream.Branch, scheduler Scheduler, leader Agent, members ...Agent) (*Colab, error)

func (*Colab) AttachTo

func (c *Colab) AttachTo(r Router)

func (*Colab) ForkSession

func (c *Colab) ForkSession() (AnalysisSession, error)

func (*Colab) History

func (c *Colab) History() []*thoughtstream.Thought

func (*Colab) Introspect

func (c *Colab) Introspect(ctx context.Context, prompt AgentPrompt, options ...StepOption) (*thoughtstream.Thought, error)

func (*Colab) IntrospectWith

func (c *Colab) IntrospectWith(ctx context.Context, profileName string, prompt AgentPrompt, options ...StepOption) (*thoughtstream.Thought, error)

func (*Colab) Log

func (c *Colab) Log() thoughtstream.Branch

func (*Colab) Members

func (c *Colab) Members() []Agent

func (*Colab) Profile

func (c *Colab) Profile() *Profile

func (*Colab) ReceiveMessage

func (c *Colab) ReceiveMessage(ctx context.Context, msg *thoughtstream.Thought) error

func (*Colab) Router

func (c *Colab) Router() Router

func (*Colab) Step

func (c *Colab) Step(ctx context.Context, options ...StepOption) error

func (*Colab) StepWith

func (c *Colab) StepWith(ctx context.Context, profileName string, options ...StepOption) error

func (*Colab) WorldState

func (c *Colab) WorldState() WorldState

type PostStepHook

type PostStepHook func(ctx AgentContext, thought *thoughtstream.Thought) error

type Profile

type Profile struct {
	psi.NodeBase

	Name        string
	Description any

	BaselineSystemPrompt string

	Rank     float64
	Priority float64

	Provides []string
	Requires []string

	PostStep PostStepHook
}

type RoundRobinScheduler

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

func (*RoundRobinScheduler) NextSpeaker

func (r *RoundRobinScheduler) NextSpeaker(ctx AgentContext, candidates ...Agent) (Agent, error)

type Router

type Router interface {
	RegisterAgent(agent Agent)

	ReceiveIncomingMessage(ctx context.Context, msg *thoughtstream.Thought)
	RouteIncomingMessages(ctx context.Context) error

	RouteMessage(ctx context.Context, msg *thoughtstream.Thought) error

	OutgoingMessages() []*thoughtstream.Thought
	ResetOutbox()
}

type Scheduler

type Scheduler interface {
	NextSpeaker(ctx AgentContext, candidates ...Agent) (Agent, error)
}

type StepOption

type StepOption func(*StepOptions) error

func WithBranch

func WithBranch(branch thoughtstream.Branch) StepOption

func WithHeadPointer

func WithHeadPointer(head thoughtstream.Pointer) StepOption

func WithStream

func WithStream(stream thoughtstream.Stream) StepOption

type StepOptions

type StepOptions struct {
	Base   thoughtstream.Branch
	Head   thoughtstream.Pointer
	Stream thoughtstream.Stream
}

func NewStepOptions

func NewStepOptions(options ...StepOption) (opts StepOptions, err error)

func (*StepOptions) Apply

func (opts *StepOptions) Apply(options ...StepOption) error

type WorldState

type WorldState interface {
	psi.Node

	Get(key string) any
	Set(key string, value any)
}

type WorldStateKey

type WorldStateKey[T any] string

func (WorldStateKey[T]) String

func (k WorldStateKey[T]) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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