Documentation
¶
Overview ¶
Package roles provides role support for omniagent.
Roles are high-level agent personas that combine skills, workflows, and system prompts into cohesive behaviors. They provide a way to configure agents for specific use cases like "Meeting PM" or "Investment Analyst".
Role Architecture ¶
A role defines:
- Required and optional skills it needs
- System prompt modifications for the persona
- Workflows for multi-step operations
Usage ¶
// Create a role with its configuration
pmRole := meetingpm.New(meetingpm.Config{
DefaultConfluenceSpace: "TEAM",
})
// Create the skills the role needs
meetingSkill := meeting.NewSkill(...)
googleSkill := google.NewSkill(...)
// Register role with agent
agent, err := agent.New(config,
agent.WithRole(pmRole, meetingSkill, googleSkill),
)
Index ¶
- Variables
- type ActionExecution
- type BehaviorEngine
- func (e *BehaviorEngine) Context() role.BehaviorContext
- func (e *BehaviorEngine) ExecuteBehavior(ctx context.Context, behavior role.Behavior) *BehaviorExecution
- func (e *BehaviorEngine) GetActive(ctx context.Context) []role.Behavior
- func (e *BehaviorEngine) GetBehavior(id string) *role.Behavior
- func (e *BehaviorEngine) HasBehavior(id string) bool
- func (e *BehaviorEngine) MatchTrigger(ctx context.Context, event string) []role.Behavior
- func (e *BehaviorEngine) SetContext(ctx role.BehaviorContext)
- type BehaviorExecution
- type DelegationRequest
- type Delegator
- func (d *Delegator) CanDelegate(ctx context.Context, taskType string) (bool, []string)
- func (d *Delegator) Complete(req *DelegationRequest)
- func (d *Delegator) Delegate(ctx context.Context, taskType, taskID string, input map[string]any) (*DelegationRequest, error)
- func (d *Delegator) IsAutonomous(taskType string) bool
- func (d *Delegator) SelectTargetRole(ctx context.Context, taskType string) (string, error)
- type InMemoryMetricsStore
- func (s *InMemoryMetricsStore) Get(ctx context.Context, roleID, metricID string) ([]MetricPoint, error)
- func (s *InMemoryMetricsStore) GetWithLabels(ctx context.Context, roleID, metricID string, labels map[string]string) ([]MetricPoint, error)
- func (s *InMemoryMetricsStore) Record(ctx context.Context, roleID, metricID string, value float64) error
- func (s *InMemoryMetricsStore) RecordWithLabels(ctx context.Context, roleID, metricID string, value float64, ...) error
- func (s *InMemoryMetricsStore) Summary(ctx context.Context, roleID, metricID string, period time.Duration) (*MetricSummary, error)
- type Manager
- func (m *Manager) CanDelegate(ctx context.Context, taskType string) (bool, []string)
- func (m *Manager) CheckDataAccess(ctx context.Context, dataType string) error
- func (m *Manager) CheckToolAccess(ctx context.Context, toolName string) error
- func (m *Manager) Close() error
- func (m *Manager) Delegate(ctx context.Context, taskType, taskID string, input map[string]any) (*DelegationRequest, error)
- func (m *Manager) GetActiveBehaviors(ctx context.Context) []role.Behavior
- func (m *Manager) IncrementMetric(ctx context.Context, metricID string) error
- func (m *Manager) Init(ctx context.Context) error
- func (m *Manager) IsAutonomousDelegation(taskType string) bool
- func (m *Manager) MatchBehaviorTrigger(ctx context.Context, event string) []role.Behavior
- func (m *Manager) OptionalSkills() []string
- func (m *Manager) RecordMetric(ctx context.Context, metricID string, value float64) error
- func (m *Manager) RequiresConfirmation(ctx context.Context, operation string) bool
- func (m *Manager) Role() role.Role
- func (m *Manager) SetBehaviorContext(ctx role.BehaviorContext)
- func (m *Manager) Spec() *role.RoleSpec
- func (m *Manager) SystemPrompt(ctx context.Context) (string, error)
- func (m *Manager) Workflows() []role.Workflow
- type MetricPoint
- type MetricSummary
- type MetricsCollector
- type MetricsStore
- type PolicyEngine
- func (e *PolicyEngine) CheckDataAccess(ctx context.Context, dataType string) error
- func (e *PolicyEngine) CheckRateLimit(ctx context.Context, operation string) error
- func (e *PolicyEngine) CheckToolAccess(ctx context.Context, toolName string) error
- func (e *PolicyEngine) RequiresConfirmation(ctx context.Context, operation string) bool
- type PolicyViolation
Constants ¶
This section is empty.
Variables ¶
var ErrBudgetExceeded = errors.New("delegation budget exceeded")
ErrBudgetExceeded is returned when the delegation budget is exceeded.
var ErrDelegationDisabled = errors.New("delegation is not enabled for this role")
ErrDelegationDisabled is returned when delegation is not enabled.
var ErrNoDelegationRule = errors.New("no delegation rule matches the task")
ErrNoDelegationRule is returned when no delegation rule matches.
var ErrPolicyDenied = errors.New("operation denied by policy")
ErrPolicyDenied is returned when a policy blocks an operation.
Functions ¶
This section is empty.
Types ¶
type ActionExecution ¶
type ActionExecution struct {
ActionID string
Type string
Completed bool
Result map[string]any
Error error
}
ActionExecution represents the execution of a single action.
type BehaviorEngine ¶
type BehaviorEngine struct {
// contains filtered or unexported fields
}
BehaviorEngine matches behaviors to the current context.
The engine evaluates behaviors defined in a role's RoleSpec and determines which behaviors are active based on the current context (meeting, chat, autonomous) and any triggered events.
func NewBehaviorEngine ¶
func NewBehaviorEngine(behaviors []role.Behavior) *BehaviorEngine
NewBehaviorEngine creates a new BehaviorEngine with the given behaviors.
func (*BehaviorEngine) Context ¶
func (e *BehaviorEngine) Context() role.BehaviorContext
Context returns the current behavior context.
func (*BehaviorEngine) ExecuteBehavior ¶
func (e *BehaviorEngine) ExecuteBehavior(ctx context.Context, behavior role.Behavior) *BehaviorExecution
ExecuteBehavior runs the actions defined in a behavior. This is a placeholder that returns the actions to be executed. The actual execution happens in the agent runtime.
func (*BehaviorEngine) GetActive ¶
func (e *BehaviorEngine) GetActive(ctx context.Context) []role.Behavior
GetActive returns all behaviors that are active in the current context. Behaviors are sorted by priority (highest first).
func (*BehaviorEngine) GetBehavior ¶
func (e *BehaviorEngine) GetBehavior(id string) *role.Behavior
GetBehavior returns a specific behavior by ID. Returns nil if the behavior is not found.
func (*BehaviorEngine) HasBehavior ¶
func (e *BehaviorEngine) HasBehavior(id string) bool
HasBehavior checks if a behavior with the given ID exists and is enabled.
func (*BehaviorEngine) MatchTrigger ¶
MatchTrigger returns behaviors that match a specific event trigger. Only returns behaviors that are both active in the current context and have a matching event trigger.
func (*BehaviorEngine) SetContext ¶
func (e *BehaviorEngine) SetContext(ctx role.BehaviorContext)
SetContext updates the current behavior context.
type BehaviorExecution ¶
type BehaviorExecution struct {
BehaviorID string
Actions []ActionExecution
Completed bool
Error error
}
BehaviorExecution represents the execution of a behavior.
type DelegationRequest ¶
type DelegationRequest struct {
TaskID string
TaskType string
TargetRole string
Input map[string]any
Timeout time.Duration
CreatedAt time.Time
Status role.DelegationStatus
Result *role.DelegationResult
}
DelegationRequest represents a request to delegate work to another role.
type Delegator ¶
type Delegator struct {
// contains filtered or unexported fields
}
Delegator manages sub-agent delegation based on role rules.
The delegator evaluates delegation rules defined in a role's RoleSpec and determines whether tasks can be delegated to other roles.
func NewDelegator ¶
func NewDelegator(config *role.DelegationConfig) *Delegator
NewDelegator creates a new Delegator with the given configuration.
func (*Delegator) CanDelegate ¶
CanDelegate determines if a task type can be delegated. Returns true and the list of target roles if delegation is possible.
func (*Delegator) Complete ¶
func (d *Delegator) Complete(req *DelegationRequest)
Complete marks a delegation as completed, freeing budget resources.
func (*Delegator) Delegate ¶
func (d *Delegator) Delegate(ctx context.Context, taskType, taskID string, input map[string]any) (*DelegationRequest, error)
Delegate prepares a delegation request for a task. Returns a DelegationRequest that can be used to track the delegation.
func (*Delegator) IsAutonomous ¶
IsAutonomous checks if a task type can be delegated autonomously.
type InMemoryMetricsStore ¶
type InMemoryMetricsStore struct {
// contains filtered or unexported fields
}
InMemoryMetricsStore provides an in-memory implementation of MetricsStore. This is suitable for development and testing but not for production use where persistence and scalability are required.
func NewInMemoryMetricsStore ¶
func NewInMemoryMetricsStore() *InMemoryMetricsStore
NewInMemoryMetricsStore creates a new in-memory metrics store.
func (*InMemoryMetricsStore) Get ¶
func (s *InMemoryMetricsStore) Get(ctx context.Context, roleID, metricID string) ([]MetricPoint, error)
Get retrieves metric data points.
func (*InMemoryMetricsStore) GetWithLabels ¶
func (s *InMemoryMetricsStore) GetWithLabels(ctx context.Context, roleID, metricID string, labels map[string]string) ([]MetricPoint, error)
GetWithLabels retrieves metric data points filtered by labels.
func (*InMemoryMetricsStore) Record ¶
func (s *InMemoryMetricsStore) Record(ctx context.Context, roleID, metricID string, value float64) error
Record stores a metric value.
func (*InMemoryMetricsStore) RecordWithLabels ¶
func (s *InMemoryMetricsStore) RecordWithLabels(ctx context.Context, roleID, metricID string, value float64, labels map[string]string) error
RecordWithLabels stores a metric value with additional labels.
func (*InMemoryMetricsStore) Summary ¶
func (s *InMemoryMetricsStore) Summary(ctx context.Context, roleID, metricID string, period time.Duration) (*MetricSummary, error)
Summary returns aggregate statistics for a metric.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages role lifecycle and skill injection.
The enhanced Manager integrates policy enforcement, behavior matching, metrics collection, and delegation capabilities from the role's spec.
func NewManager ¶
NewManager creates a new role manager with the given role and skills.
func NewManagerWithMetrics ¶
func NewManagerWithMetrics(r role.Role, metricsStore MetricsStore, compiledSkills ...compiled.Skill) (*Manager, error)
NewManagerWithMetrics creates a Manager with a custom metrics store.
func (*Manager) CanDelegate ¶
CanDelegate checks if a task type can be delegated.
func (*Manager) CheckDataAccess ¶
CheckDataAccess validates that a data type can be accessed according to policies. Returns nil if allowed, an error if denied.
func (*Manager) CheckToolAccess ¶
CheckToolAccess validates that a tool can be used according to policies. Returns nil if allowed, an error if denied.
func (*Manager) Delegate ¶
func (m *Manager) Delegate(ctx context.Context, taskType, taskID string, input map[string]any) (*DelegationRequest, error)
Delegate creates a delegation request for a task.
func (*Manager) GetActiveBehaviors ¶
GetActiveBehaviors returns behaviors active in the current context.
func (*Manager) IncrementMetric ¶
IncrementMetric increments a counter metric by 1.
func (*Manager) IsAutonomousDelegation ¶
IsAutonomousDelegation checks if a task type can be delegated autonomously.
func (*Manager) MatchBehaviorTrigger ¶
MatchBehaviorTrigger returns behaviors matching a specific event.
func (*Manager) OptionalSkills ¶
OptionalSkills returns the optional skills for the role, if defined.
func (*Manager) RecordMetric ¶
RecordMetric records a metric value.
func (*Manager) RequiresConfirmation ¶
RequiresConfirmation checks if an operation requires user confirmation.
func (*Manager) SetBehaviorContext ¶
func (m *Manager) SetBehaviorContext(ctx role.BehaviorContext)
SetBehaviorContext updates the current behavior context.
func (*Manager) SystemPrompt ¶
SystemPrompt returns the role's system prompt.
type MetricPoint ¶
MetricPoint represents a single metric measurement.
type MetricSummary ¶
type MetricSummary struct {
MetricID string
Period time.Duration
Count int64
Sum float64
Min float64
Max float64
Avg float64
P50 float64
P90 float64
P99 float64
}
MetricSummary provides aggregate statistics for a metric.
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector provides a convenient wrapper for recording metrics for a specific role.
func NewMetricsCollector ¶
func NewMetricsCollector(store MetricsStore, roleID string, metrics []role.MetricDefinition) *MetricsCollector
NewMetricsCollector creates a collector for a specific role.
type MetricsStore ¶
type MetricsStore interface {
// Record stores a metric value.
Record(ctx context.Context, roleID, metricID string, value float64) error
// RecordWithLabels stores a metric value with additional labels.
RecordWithLabels(ctx context.Context, roleID, metricID string, value float64, labels map[string]string) error
// Get retrieves metric data points.
Get(ctx context.Context, roleID, metricID string) ([]MetricPoint, error)
// GetWithLabels retrieves metric data points filtered by labels.
GetWithLabels(ctx context.Context, roleID, metricID string, labels map[string]string) ([]MetricPoint, error)
// Summary returns aggregate statistics for a metric.
Summary(ctx context.Context, roleID, metricID string, period time.Duration) (*MetricSummary, error)
}
MetricsStore collects and stores role metrics.
The store provides methods to record metric values and retrieve historical data for analysis and reporting.
type PolicyEngine ¶
type PolicyEngine struct {
// contains filtered or unexported fields
}
PolicyEngine enforces policy rules at runtime.
The engine evaluates policies defined in a role's RoleSpec and determines whether specific operations should be allowed, warned, or blocked.
func NewPolicyEngine ¶
func NewPolicyEngine(policies []role.Policy) *PolicyEngine
NewPolicyEngine creates a new PolicyEngine with the given policies.
func (*PolicyEngine) CheckDataAccess ¶
func (e *PolicyEngine) CheckDataAccess(ctx context.Context, dataType string) error
CheckDataAccess determines if a data type can be accessed. Returns nil if allowed, ErrPolicyDenied if blocked.
func (*PolicyEngine) CheckRateLimit ¶
func (e *PolicyEngine) CheckRateLimit(ctx context.Context, operation string) error
CheckRateLimit determines if an operation is within rate limits. Returns nil if allowed, ErrPolicyDenied if rate limit exceeded.
func (*PolicyEngine) CheckToolAccess ¶
func (e *PolicyEngine) CheckToolAccess(ctx context.Context, toolName string) error
CheckToolAccess determines if a tool can be used. Returns nil if allowed, ErrPolicyDenied if blocked.
func (*PolicyEngine) RequiresConfirmation ¶
func (e *PolicyEngine) RequiresConfirmation(ctx context.Context, operation string) bool
RequiresConfirmation determines if an operation needs user confirmation.
type PolicyViolation ¶
type PolicyViolation struct {
PolicyID string
PolicyName string
RuleID string
TargetType string
TargetName string
Message string
}
PolicyViolation provides details about a policy violation.
func (*PolicyViolation) Error ¶
func (v *PolicyViolation) Error() string
Error implements the error interface.
func (*PolicyViolation) Unwrap ¶
func (v *PolicyViolation) Unwrap() error
Unwrap returns the underlying error for errors.Is compatibility.