Documentation
¶
Index ¶
- func AgentNames(agents []Agent) []string
- func DateString(t time.Time) string
- func FormatMessages(messages []*llm.Message) string
- func RandomName() string
- func TruncateText(text string, maxWords int) string
- func WaitForEvent[T any](ctx context.Context, stream Stream) (T, error)
- type Agent
- type DiskOutputPlugin
- func (p *DiskOutputPlugin) Name() string
- func (p *DiskOutputPlugin) OutputExists(ctx context.Context, name, fingerprint string) (bool, error)
- func (p *DiskOutputPlugin) ReadOutput(ctx context.Context, name, fingerprint string) (string, error)
- func (p *DiskOutputPlugin) WriteOutput(ctx context.Context, name, fingerprint string, output string) error
- type Environment
- type Event
- type EventHandlerAgent
- type EventOrigin
- type GenerateOption
- type GenerateOptions
- type InMemoryOutputPlugin
- func (p *InMemoryOutputPlugin) Name() string
- func (p *InMemoryOutputPlugin) OutputExists(ctx context.Context, name, fingerprint string) (bool, error)
- func (p *InMemoryOutputPlugin) ReadOutput(ctx context.Context, name, fingerprint string) (string, error)
- func (p *InMemoryOutputPlugin) WriteOutput(ctx context.Context, name, fingerprint string, output string) error
- type Input
- type Output
- type OutputFormat
- type OutputPlugin
- type Prompt
- type PromptContext
- type Publisher
- type RunnableAgent
- type Stream
- type Task
- type TaskResult
- type TaskStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AgentNames ¶
func DateString ¶
func FormatMessages ¶
func RandomName ¶
func RandomName() string
func TruncateText ¶
Types ¶
type Agent ¶
type Agent interface {
// Name of the Agent
Name() string
// Goal of the Agent
Goal() string
// IsSupervisor indicates whether the Agent can assign work to other Agents
IsSupervisor() bool
// SetEnvironment sets the runtime Environment to which this Agent belongs
SetEnvironment(env Environment)
// Generate gives the agent a message to respond to
Generate(ctx context.Context, message *llm.Message, opts ...GenerateOption) (*llm.Response, error)
// Stream gives the agent a message to respond to and returns a stream of events
Stream(ctx context.Context, message *llm.Message, opts ...GenerateOption) (Stream, error)
// Work gives the agent a task to complete
Work(ctx context.Context, task Task) (Stream, error)
}
Agent represents an AI agent that can perform tasks
type DiskOutputPlugin ¶
type DiskOutputPlugin struct {
// contains filtered or unexported fields
}
func NewDiskOutputPlugin ¶
func NewDiskOutputPlugin(dir string) (*DiskOutputPlugin, error)
func (*DiskOutputPlugin) Name ¶
func (p *DiskOutputPlugin) Name() string
func (*DiskOutputPlugin) OutputExists ¶
func (*DiskOutputPlugin) ReadOutput ¶
func (*DiskOutputPlugin) WriteOutput ¶
type Environment ¶
type Environment interface {
// Name of the Environment
Name() string
// Agents returns the list of all Agents belonging to this Environment
Agents() []Agent
// RegisterAgent adds an Agent to this Environment
RegisterAgent(agent Agent) error
// GetAgent returns the Agent with the given name, if found
GetAgent(name string) (Agent, error)
// DocumentRepository returns the DocumentRepository for this Environment
DocumentRepository() document.Repository
}
Environment is a container for running Agents and Workflow Executions. Interactivity between Agents is scoped to a single Environment.
type Event ¶
type Event struct {
// Type of the event
Type string
// Origin describes what produced the Event
Origin EventOrigin
// Payload contains arbitrary data associated with the Event
Payload any
// Error is set if this Event corresponds to an error
Error error
}
Event generated by a Dive Agent or Workflow Execution.
type EventHandlerAgent ¶
type EventHandlerAgent interface {
Agent
// AcceptedEvents returns the names of supported events
AcceptedEvents() []string
// HandleEvent passes an event to the event handler
HandleEvent(ctx context.Context, event *Event) error
}
EventHandlerAgent is an Agent that can handle events
type EventOrigin ¶
type EventOrigin struct {
AgentID string `json:"agent_id,omitempty"`
AgentName string `json:"agent_name,omitempty"`
TaskID string `json:"task_id,omitempty"`
TaskName string `json:"task_name,omitempty"`
WorkflowID string `json:"workflow_id,omitempty"`
WorkflowName string `json:"workflow_name,omitempty"`
EnvironmentID string `json:"environment_id,omitempty"`
EnvironmentName string `json:"environment_name,omitempty"`
}
EventOrigin carries information about what produced the event
type GenerateOption ¶
type GenerateOption func(*GenerateOptions)
GenerateOption is a type signature for defining new LLM generation options.
func WithThreadID ¶
func WithThreadID(threadID string) GenerateOption
WithThreadID associates the given conversation thread ID with a generation. This appends the new messages to any previous messages belonging to this thread.
func WithUserID ¶
func WithUserID(userID string) GenerateOption
WithUserID associates the given user ID with a generation, indicating what person is the speaker in the conversation.
type GenerateOptions ¶
GenerateOptions contains configuration for LLM generations.
func (*GenerateOptions) Apply ¶
func (o *GenerateOptions) Apply(opts []GenerateOption)
Apply invokes any supplied options. Used internally in Dive.
type InMemoryOutputPlugin ¶
type InMemoryOutputPlugin struct {
// contains filtered or unexported fields
}
func NewInMemoryOutputPlugin ¶
func NewInMemoryOutputPlugin() *InMemoryOutputPlugin
func (*InMemoryOutputPlugin) Name ¶
func (p *InMemoryOutputPlugin) Name() string
func (*InMemoryOutputPlugin) OutputExists ¶
func (*InMemoryOutputPlugin) ReadOutput ¶
func (*InMemoryOutputPlugin) WriteOutput ¶
type Input ¶
type Input struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Default interface{} `json:"default,omitempty"`
}
Input defines an expected input parameter
type Output ¶
type Output struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Format string `json:"format,omitempty"`
Default interface{} `json:"default,omitempty"`
Document string `json:"document,omitempty"`
}
Output defines an expected output parameter
type OutputFormat ¶
type OutputFormat string
OutputFormat defines the desired output format for a Task
const ( OutputText OutputFormat = "text" OutputMarkdown OutputFormat = "markdown" OutputJSON OutputFormat = "json" )
type OutputPlugin ¶
type OutputPlugin interface {
// Name of the output plugin
Name() string
// OutputExists returns true if the output for the given task and fingerprint
// already exists.
OutputExists(ctx context.Context, name, fingerprint string) (bool, error)
// ReadOutput reads the output for the given task and fingerprint
ReadOutput(ctx context.Context, name, fingerprint string) (string, error)
// WriteOutput writes the output for the given task and fingerprint
WriteOutput(ctx context.Context, name, fingerprint string, output string) error
}
OutputPlugin is a plugin that can be used to store and retrieve task outputs
type Prompt ¶
type Prompt struct {
Name string `json:"name"`
Text string `json:"text,omitempty"`
Context []*PromptContext `json:"context,omitempty"`
Output string `json:"output,omitempty"`
OutputFormat string `json:"output_format,omitempty"`
}
type PromptContext ¶
type Publisher ¶
type Publisher interface {
// Send sends an event to the stream
Send(ctx context.Context, event *Event) error
// Close closes the publisher and releases any resources
Close()
}
Publisher is an interface used to send events.
type RunnableAgent ¶
type RunnableAgent interface {
Agent
// Start the agent
Start(ctx context.Context) error
// Stop the agent
Stop(ctx context.Context) error
// IsRunning returns true if the agent is running
IsRunning() bool
}
RunnableAgent is an Agent that can be started and stopped
type Stream ¶
type Stream interface {
// Next advances the stream to the next event. It returns false when the stream
// is complete or if an error occurs. The caller should check Err() after Next
// returns false to distinguish between normal completion and errors.
Next(ctx context.Context) bool
// Event returns the current event in the stream. It should only be called
// after a successful call to Next.
Event() *Event
// Err returns any error that occurred while reading from the stream.
// It should be checked after Next returns false.
Err() error
// Close closes the stream and releases any associated resources.
Close() error
// Publisher returns a publisher for the stream
Publisher() Publisher
}
Stream is an interface used to consume Events.
type Task ¶
type Task interface {
// Name returns the name of the task
Name() string
// Timeout returns the maximum duration allowed for task execution
Timeout() time.Duration
// Prompt returns the LLM prompt for the task
Prompt() (*Prompt, error)
}
Task represents a unit of work that can be executed by an Agent
type TaskResult ¶
type TaskResult struct {
// Task is the task that was executed
Task Task
// Content contains the raw output
Content string
// Format specifies how to interpret the content
Format OutputFormat
// Object holds parsed JSON output if applicable
Object interface{}
// Error is set if task execution failed
Error error
// Usage tracks LLM token usage
Usage llm.Usage
}
TaskResult holds the output of a completed task
type TaskStatus ¶
type TaskStatus string
TaskStatus indicates a Task's execution status
const ( TaskStatusQueued TaskStatus = "queued" TaskStatusActive TaskStatus = "active" TaskStatusPaused TaskStatus = "paused" TaskStatusCompleted TaskStatus = "completed" TaskStatusBlocked TaskStatus = "blocked" TaskStatusError TaskStatus = "error" TaskStatusInvalid TaskStatus = "invalid" )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
simple_runner
command
|
|
|
stream_test
command
|
|
|
examples
|
|
|
programs/chat_example
command
|
|
|
programs/search_example
command
|
|
|
programs/tasks_example
command
|
|
|
programs/workflow_example
command
|
|