role

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package role defines the core interfaces for agent roles.

A Role is a high-level persona that composes skills and defines behavior. Roles encapsulate:

  • A persona (how the agent behaves and communicates)
  • Skill composition (which skills/tools the role uses)
  • Workflows (structured sequences of actions)

Roles are easy to understand: "Meeting PM", "Code Reviewer", "Support Agent". Each role can have subroles for more specialized behavior.

Example:

type MeetingPMRole struct {
    skills map[string]skill.Skill
}

func (r *MeetingPMRole) Name() string        { return "meeting-pm" }
func (r *MeetingPMRole) Description() string { return "Meeting Program Manager" }
func (r *MeetingPMRole) RequiredSkills() []string { return []string{"meeting", "google", "confluence"} }

Index

Constants

View Source
const (
	TriggerTypeEvent     = "event"
	TriggerTypeSchedule  = "schedule"
	TriggerTypeCondition = "condition"
	TriggerTypeManual    = "manual"
)

TriggerTypes for BehaviorTrigger.Type

View Source
const (
	ActionTypeToolCall = "tool_call"
	ActionTypeMessage  = "message"
	ActionTypeWorkflow = "workflow"
)

ActionTypes for BehaviorAction.Type

View Source
const (
	EventMeetingStart    = "meeting_start"
	EventMeetingEnd      = "meeting_end"
	EventMeetingJoined   = "meeting_joined"
	EventMessageReceived = "message_received"
	EventTaskAssigned    = "task_assigned"
	EventTaskCompleted   = "task_completed"
)

Common event names for BehaviorTrigger.Event

View Source
const (
	OperatorGreaterThanOrEqual = ">="
	OperatorLessThanOrEqual    = "<="
	OperatorEqual              = "=="
	OperatorGreaterThan        = ">"
	OperatorLessThan           = "<"
)

Target comparison operators.

View Source
const (
	UnitPercent      = "percent"
	UnitSeconds      = "seconds"
	UnitMilliseconds = "milliseconds"
	UnitCount        = "count"
	UnitBytes        = "bytes"
	UnitRequests     = "requests"
)

Common metric units.

View Source
const (
	TargetTypeTool      = "tool"
	TargetTypeData      = "data"
	TargetTypeOperation = "operation"
	TargetTypeResource  = "resource"
)

Target types for PolicyTarget.Type

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// ID is a unique identifier for this action.
	ID string `json:"id"`

	// Type categorizes the action (e.g., "task", "decision", "question").
	Type string `json:"type"`

	// Description is the action text.
	Description string `json:"description"`

	// Assignee is the person responsible (optional).
	Assignee string `json:"assignee,omitempty"`

	// DueDate is when the action should be completed (optional).
	DueDate string `json:"due_date,omitempty"`

	// Priority indicates urgency (e.g., "high", "medium", "low").
	Priority string `json:"priority,omitempty"`

	// Source indicates where this action was captured.
	Source string `json:"source,omitempty"`

	// Links are references to external systems.
	Links []ActionLink `json:"links,omitempty"`

	// Metadata contains additional action properties.
	Metadata map[string]any `json:"metadata,omitempty"`
}

Action represents a follow-up item from a workflow.

type ActionLink struct {
	// System is the external platform (e.g., "jira", "aha", "github").
	System string `json:"system"`

	// Type is the link kind (e.g., "issue", "feature", "pr").
	Type string `json:"type"`

	// ID is the external identifier.
	ID string `json:"id"`

	// URL is the direct link.
	URL string `json:"url"`
}

ActionLink connects an action to an external system.

type Artifact

type Artifact struct {
	// Name is the artifact identifier.
	Name string `json:"name"`

	// Type indicates the artifact kind (e.g., "document", "notes", "summary").
	Type string `json:"type"`

	// Format is the content format (e.g., "markdown", "html", "pdf").
	Format string `json:"format"`

	// Content is the artifact data (for inline content).
	Content string `json:"content,omitempty"`

	// URL is a link to the artifact (for external content).
	URL string `json:"url,omitempty"`

	// Metadata contains additional artifact properties.
	Metadata map[string]any `json:"metadata,omitempty"`
}

Artifact represents a document or file produced by a workflow.

type ArtifactSpec

type ArtifactSpec struct {
	// ID is a unique identifier for this artifact type.
	ID string `json:"id"`

	// Name is a human-readable name (e.g., "Meeting Notes").
	Name string `json:"name"`

	// Description explains what this artifact contains.
	Description string `json:"description,omitempty"`

	// Type categorizes the artifact (e.g., "document", "report", "summary").
	Type string `json:"type"`

	// Format is the content format (e.g., "markdown", "html", "pdf").
	Format string `json:"format,omitempty"`

	// Required indicates if this artifact must be produced.
	Required bool `json:"required,omitempty"`

	// Trigger describes when this artifact is created.
	Trigger string `json:"trigger,omitempty"`
}

ArtifactSpec defines an output that the role produces.

type BaseRole

type BaseRole struct {
	RoleName           string
	RoleDescription    string
	RolePrompt         string
	RoleSkills         []string
	RoleOptionalSkills []string
	RoleWorkflows      []Workflow

	// Skills holds the initialized skills after Init is called.
	Skills map[string]skill.Skill
}

BaseRole provides a minimal Role implementation that can be embedded.

BaseRole implements the core Role interface plus SkillRequirer and WorkflowProvider for backward compatibility. It provides a default Spec() implementation that builds a RoleSpec from the struct fields.

func (*BaseRole) Close

func (r *BaseRole) Close() error

Close is a no-op by default.

func (*BaseRole) Description

func (r *BaseRole) Description() string

Description returns the role description.

func (*BaseRole) Init

func (r *BaseRole) Init(ctx context.Context, skills map[string]skill.Skill) error

Init stores the provided skills for later use.

func (*BaseRole) Name

func (r *BaseRole) Name() string

Name returns the role name.

func (*BaseRole) OptionalSkills

func (r *BaseRole) OptionalSkills() []string

OptionalSkills returns optional skills for this role.

func (*BaseRole) RequiredSkills

func (r *BaseRole) RequiredSkills() []string

RequiredSkills returns the skills this role needs.

func (*BaseRole) Spec

func (r *BaseRole) Spec() *RoleSpec

Spec returns a RoleSpec built from the BaseRole fields.

func (*BaseRole) SystemPrompt

func (r *BaseRole) SystemPrompt(ctx context.Context) (string, error)

SystemPrompt returns the role's system prompt.

func (*BaseRole) Workflows

func (r *BaseRole) Workflows() []Workflow

Workflows returns the role's workflows.

type BaseWorkflow

type BaseWorkflow struct {
	WorkflowName        string
	WorkflowDescription string
	WorkflowTrigger     string
	WorkflowInputSchema map[string]any
	ExecuteFunc         func(ctx context.Context, input map[string]any) (WorkflowResult, error)
}

BaseWorkflow provides a minimal Workflow implementation.

func (*BaseWorkflow) Description

func (w *BaseWorkflow) Description() string

Description returns the workflow description.

func (*BaseWorkflow) Execute

func (w *BaseWorkflow) Execute(ctx context.Context, input map[string]any) (WorkflowResult, error)

Execute runs the workflow.

func (*BaseWorkflow) InputSchema

func (w *BaseWorkflow) InputSchema() map[string]any

InputSchema returns the input JSON Schema.

func (*BaseWorkflow) Name

func (w *BaseWorkflow) Name() string

Name returns the workflow name.

func (*BaseWorkflow) Trigger

func (w *BaseWorkflow) Trigger() string

Trigger returns when the workflow should be invoked.

type Behavior

type Behavior struct {
	// ID is a unique identifier for this behavior.
	ID string `json:"id"`

	// Name is a human-readable name (e.g., "Pre-meeting Preparation").
	Name string `json:"name"`

	// Description explains what this behavior does.
	Description string `json:"description,omitempty"`

	// Context specifies when this behavior applies.
	Context BehaviorContext `json:"context"`

	// Trigger defines what activates this behavior.
	Trigger BehaviorTrigger `json:"trigger"`

	// Actions define what the behavior does when activated.
	Actions []BehaviorAction `json:"actions"`

	// Enabled indicates if this behavior is active.
	Enabled bool `json:"enabled"`

	// Priority determines order when multiple behaviors match.
	Priority int `json:"priority,omitempty"`
}

Behavior defines a context-specific action pattern.

Behaviors allow roles to act differently based on context. For example, a Meeting PM might have different behaviors during pre-meeting preparation vs during the actual meeting.

type BehaviorAction

type BehaviorAction struct {
	// ID is a unique identifier for this action.
	ID string `json:"id"`

	// Type categorizes the action (e.g., "tool_call", "message", "workflow").
	Type string `json:"type"`

	// Name describes the action (e.g., "Send meeting reminder").
	Name string `json:"name,omitempty"`

	// Tool is the tool to invoke (for tool_call type).
	Tool string `json:"tool,omitempty"`

	// Workflow is the workflow to run (for workflow type).
	Workflow string `json:"workflow,omitempty"`

	// Message is the message to send (for message type).
	Message string `json:"message,omitempty"`

	// Parameters contains action-specific configuration.
	Parameters map[string]any `json:"parameters,omitempty"`
}

BehaviorAction defines a single action within a behavior.

type BehaviorContext

type BehaviorContext string

BehaviorContext defines the context in which a behavior applies.

const (
	// BehaviorContextMeeting applies when the role is in a meeting.
	BehaviorContextMeeting BehaviorContext = "meeting"

	// BehaviorContextChat applies during chat conversations.
	BehaviorContextChat BehaviorContext = "chat"

	// BehaviorContextAutonomous applies when running autonomously.
	BehaviorContextAutonomous BehaviorContext = "autonomous"

	// BehaviorContextAlways applies in all contexts.
	BehaviorContextAlways BehaviorContext = "always"
)

type BehaviorProvider

type BehaviorProvider interface {
	// Behaviors returns the behaviors defined for this role.
	Behaviors() []Behavior
}

BehaviorProvider is implemented by roles with context-aware behaviors.

type BehaviorTrigger

type BehaviorTrigger struct {
	// Type is the trigger category (e.g., "event", "schedule", "condition").
	Type string `json:"type"`

	// Event is the specific event name (for event triggers).
	Event string `json:"event,omitempty"`

	// Schedule is a cron expression (for schedule triggers).
	Schedule string `json:"schedule,omitempty"`

	// Condition is a CEL expression (for condition triggers).
	Condition string `json:"condition,omitempty"`

	// Parameters contains trigger-specific configuration.
	Parameters map[string]any `json:"parameters,omitempty"`
}

BehaviorTrigger defines what activates a behavior.

type DelegationBudget

type DelegationBudget struct {
	// MaxConcurrent is the maximum simultaneous delegated tasks.
	MaxConcurrent int `json:"max_concurrent,omitempty"`

	// MaxDaily is the maximum delegations per day.
	MaxDaily int `json:"max_daily,omitempty"`

	// MaxTokens is the maximum tokens consumed by delegated tasks.
	MaxTokens int64 `json:"max_tokens,omitempty"`

	// MaxCost is the maximum cost for delegated tasks.
	MaxCost float64 `json:"max_cost,omitempty"`

	// Currency for cost limits (e.g., "USD").
	Currency string `json:"currency,omitempty"`
}

DelegationBudget limits delegation resources.

type DelegationConfig

type DelegationConfig struct {
	// Enabled indicates if delegation is allowed for this role.
	Enabled bool `json:"enabled"`

	// Rules define when and how to delegate.
	Rules []DelegationRule `json:"rules"`

	// Budget limits delegation resources.
	Budget *DelegationBudget `json:"budget,omitempty"`

	// DefaultTimeout is the default timeout for delegated tasks.
	DefaultTimeout string `json:"default_timeout,omitempty"`

	// RetryPolicy defines how to handle failed delegations.
	RetryPolicy *DelegationRetryPolicy `json:"retry_policy,omitempty"`
}

DelegationConfig defines sub-agent orchestration settings.

Delegation allows roles to spawn or assign work to other agents. This is useful for meeting orchestrators that delegate to specialized reviewers (security, architecture, QA).

type DelegationProvider

type DelegationProvider interface {
	// DelegationRules returns the delegation rules for this role.
	DelegationRules() []DelegationRule
}

DelegationProvider is implemented by roles that orchestrate sub-agents.

type DelegationResult

type DelegationResult struct {
	// RuleID is the rule that triggered this delegation.
	RuleID string `json:"rule_id"`

	// TargetRole is the role that received the task.
	TargetRole string `json:"target_role"`

	// TaskID is a unique identifier for the delegated task.
	TaskID string `json:"task_id"`

	// Status is the delegation outcome (e.g., "completed", "failed", "timeout").
	Status DelegationStatus `json:"status"`

	// Output contains the result data from the delegated task.
	Output map[string]any `json:"output,omitempty"`

	// Error contains error details if the delegation failed.
	Error string `json:"error,omitempty"`

	// Duration is how long the delegation took.
	Duration string `json:"duration,omitempty"`

	// TokensUsed is the number of tokens consumed.
	TokensUsed int64 `json:"tokens_used,omitempty"`
}

DelegationResult contains the outcome of a delegated task.

type DelegationRetryPolicy

type DelegationRetryPolicy struct {
	// MaxRetries is the maximum number of retry attempts.
	MaxRetries int `json:"max_retries,omitempty"`

	// InitialDelay is the delay before the first retry.
	InitialDelay string `json:"initial_delay,omitempty"`

	// MaxDelay is the maximum delay between retries.
	MaxDelay string `json:"max_delay,omitempty"`

	// Multiplier increases delay between retries.
	Multiplier float64 `json:"multiplier,omitempty"`
}

DelegationRetryPolicy defines how to handle failed delegations.

type DelegationRule

type DelegationRule struct {
	// ID is a unique identifier for this rule.
	ID string `json:"id"`

	// Name is a human-readable name (e.g., "Security Review Delegation").
	Name string `json:"name"`

	// Description explains when this rule applies.
	Description string `json:"description,omitempty"`

	// TaskPatterns are glob patterns matching task types to delegate.
	TaskPatterns []string `json:"task_patterns"`

	// TargetRoles are roles that can receive delegated work.
	TargetRoles []string `json:"target_roles"`

	// Autonomous indicates if delegation can happen without user approval.
	Autonomous bool `json:"autonomous"`

	// Priority determines rule precedence when multiple rules match.
	Priority int `json:"priority,omitempty"`

	// Condition is an optional CEL expression for conditional delegation.
	Condition string `json:"condition,omitempty"`

	// Timeout overrides the default timeout for this rule.
	Timeout string `json:"timeout,omitempty"`
}

DelegationRule defines when and how to delegate to sub-agents.

type DelegationStatus

type DelegationStatus string

DelegationStatus represents the outcome of a delegation.

const (
	// DelegationStatusPending indicates the task is queued.
	DelegationStatusPending DelegationStatus = "pending"

	// DelegationStatusRunning indicates the task is in progress.
	DelegationStatusRunning DelegationStatus = "running"

	// DelegationStatusCompleted indicates successful completion.
	DelegationStatusCompleted DelegationStatus = "completed"

	// DelegationStatusFailed indicates the task failed.
	DelegationStatusFailed DelegationStatus = "failed"

	// DelegationStatusTimeout indicates the task timed out.
	DelegationStatusTimeout DelegationStatus = "timeout"

	// DelegationStatusCancelled indicates the task was cancelled.
	DelegationStatusCancelled DelegationStatus = "cancelled"
)

type EnforcementMode

type EnforcementMode string

EnforcementMode specifies the response to policy violations.

const (
	// EnforcementModeBlock prevents the action.
	EnforcementModeBlock EnforcementMode = "block"

	// EnforcementModeWarn allows but logs a warning.
	EnforcementModeWarn EnforcementMode = "warn"

	// EnforcementModeAudit logs for later review but takes no action.
	EnforcementModeAudit EnforcementMode = "audit"

	// EnforcementModeConfirm requires user confirmation before proceeding.
	EnforcementModeConfirm EnforcementMode = "confirm"
)

type MemoryPolicy

type MemoryPolicy struct {
	// Enabled indicates if memory is enabled for this role.
	Enabled bool `json:"enabled"`

	// Scope defines memory visibility (e.g., "session", "user", "global").
	Scope string `json:"scope,omitempty"`

	// RetentionDays is how long memories are kept (0 = forever).
	RetentionDays int `json:"retention_days,omitempty"`

	// Categories lists types of information to remember.
	Categories []string `json:"categories,omitempty"`
}

MemoryPolicy defines how the role manages memory and state.

type MetricDefinition

type MetricDefinition struct {
	// ID is a unique identifier for this metric.
	ID string `json:"id"`

	// Name is a human-readable name (e.g., "Action Capture Rate").
	Name string `json:"name"`

	// Description explains what this metric measures.
	Description string `json:"description,omitempty"`

	// Type specifies how this metric is measured.
	Type MetricType `json:"type"`

	// Unit is the measurement unit (e.g., "percent", "seconds", "count").
	Unit string `json:"unit,omitempty"`

	// Target defines success thresholds.
	Target *MetricTarget `json:"target,omitempty"`

	// Labels are additional dimensions for this metric.
	Labels []string `json:"labels,omitempty"`

	// Buckets are histogram bucket boundaries (for histogram type).
	Buckets []float64 `json:"buckets,omitempty"`
}

MetricDefinition defines a success metric or KPI for the role.

MetricDefinition is data only - actual collection and storage happens in the runtime MetricsStore.

func NewCounterMetric

func NewCounterMetric(id, name, description string) MetricDefinition

NewCounterMetric creates a counter MetricDefinition.

func NewGaugeMetric

func NewGaugeMetric(id, name, description, unit string) MetricDefinition

NewGaugeMetric creates a gauge MetricDefinition.

func NewHistogramMetric

func NewHistogramMetric(id, name, description, unit string, buckets []float64) MetricDefinition

NewHistogramMetric creates a histogram MetricDefinition with custom buckets.

type MetricTarget

type MetricTarget struct {
	// Value is the target value to achieve.
	Value float64 `json:"value"`

	// Operator specifies how to compare (e.g., ">=", "<=", "==").
	Operator string `json:"operator,omitempty"`

	// WarningThreshold triggers a warning when crossed.
	WarningThreshold float64 `json:"warning_threshold,omitempty"`

	// CriticalThreshold triggers an alert when crossed.
	CriticalThreshold float64 `json:"critical_threshold,omitempty"`

	// Period is the time window for evaluation (e.g., "1h", "24h", "7d").
	Period string `json:"period,omitempty"`
}

MetricTarget defines success thresholds for a metric.

type MetricType

type MetricType string

MetricType categorizes metrics by how they're measured.

const (
	// MetricTypeCounter counts cumulative occurrences.
	MetricTypeCounter MetricType = "counter"

	// MetricTypeGauge measures a point-in-time value.
	MetricTypeGauge MetricType = "gauge"

	// MetricTypeHistogram measures distribution of values.
	MetricTypeHistogram MetricType = "histogram"

	// MetricTypeSummary provides quantiles over time.
	MetricTypeSummary MetricType = "summary"
)

type MetricsProvider

type MetricsProvider interface {
	// Metrics returns the metric definitions for this role.
	Metrics() []MetricDefinition
}

MetricsProvider is implemented by roles that define success metrics.

type PersonaSpec

type PersonaSpec struct {
	// Tone describes the communication style (e.g., "professional", "friendly").
	Tone string `json:"tone,omitempty"`

	// Language is the preferred language code (e.g., "en", "es").
	Language string `json:"language,omitempty"`

	// Formality indicates the level of formality (e.g., "formal", "casual").
	Formality string `json:"formality,omitempty"`

	// Voice describes first/third person usage (e.g., "first", "third").
	Voice string `json:"voice,omitempty"`

	// Traits lists personality characteristics.
	Traits []string `json:"traits,omitempty"`
}

PersonaSpec defines the communication style for a role.

type Policy

type Policy struct {
	// ID is a unique identifier for this policy.
	ID string `json:"id"`

	// Name is a human-readable name (e.g., "No external API calls").
	Name string `json:"name"`

	// Description explains the policy's purpose.
	Description string `json:"description,omitempty"`

	// Type categorizes what this policy controls.
	Type PolicyType `json:"type"`

	// Rules define the specific restrictions or allowances.
	Rules []PolicyRule `json:"rules"`

	// Enforcement specifies how violations are handled.
	Enforcement PolicyEnforcement `json:"enforcement"`

	// Enabled indicates if this policy is active.
	Enabled bool `json:"enabled"`

	// Priority determines order when multiple policies apply.
	Priority int `json:"priority,omitempty"`
}

Policy defines a governance rule for the role.

Policies are data definitions only - enforcement happens in the runtime engine. This separation allows policies to be defined in role specs without coupling to enforcement implementation.

type PolicyAction

type PolicyAction string

PolicyAction specifies whether a rule allows or denies.

const (
	// PolicyActionAllow permits the target.
	PolicyActionAllow PolicyAction = "allow"

	// PolicyActionDeny blocks the target.
	PolicyActionDeny PolicyAction = "deny"
)

type PolicyEnforcement

type PolicyEnforcement struct {
	// Mode is how to handle violations (e.g., "block", "warn", "audit").
	Mode EnforcementMode `json:"mode"`

	// Message is shown when the policy is triggered.
	Message string `json:"message,omitempty"`

	// Escalation specifies who to notify on violations.
	Escalation string `json:"escalation,omitempty"`
}

PolicyEnforcement specifies how violations are handled.

type PolicyProvider

type PolicyProvider interface {
	// Policies returns the policies defined for this role.
	Policies() []Policy
}

PolicyProvider is implemented by roles with governance rules.

type PolicyRule

type PolicyRule struct {
	// ID is a unique identifier for this rule.
	ID string `json:"id"`

	// Action specifies allow or deny.
	Action PolicyAction `json:"action"`

	// Target specifies what this rule applies to.
	Target PolicyTarget `json:"target"`

	// Condition is an optional CEL expression for conditional rules.
	Condition string `json:"condition,omitempty"`

	// Reason explains why this rule exists.
	Reason string `json:"reason,omitempty"`
}

PolicyRule defines a specific restriction or allowance.

type PolicyTarget

type PolicyTarget struct {
	// Type specifies the target category (e.g., "tool", "data", "operation").
	Type string `json:"type"`

	// Pattern is a glob pattern matching target names.
	Pattern string `json:"pattern"`

	// Attributes contains additional matching criteria.
	Attributes map[string]any `json:"attributes,omitempty"`
}

PolicyTarget specifies what a rule applies to.

type PolicyType

type PolicyType string

PolicyType categorizes policies by what they control.

const (
	// PolicyTypeToolAccess controls which tools can be used.
	PolicyTypeToolAccess PolicyType = "tool_access"

	// PolicyTypeDataAccess controls access to data types.
	PolicyTypeDataAccess PolicyType = "data_access"

	// PolicyTypeActionLimit restricts certain actions.
	PolicyTypeActionLimit PolicyType = "action_limit"

	// PolicyTypeRateLimit enforces usage limits.
	PolicyTypeRateLimit PolicyType = "rate_limit"

	// PolicyTypeConfirmation requires user confirmation for actions.
	PolicyTypeConfirmation PolicyType = "confirmation_required"
)

type Responsibility

type Responsibility struct {
	// ID is a unique identifier for this responsibility.
	ID string `json:"id"`

	// Name is a short description (e.g., "Prepare meeting agenda").
	Name string `json:"name"`

	// Description provides details about what this responsibility entails.
	Description string `json:"description,omitempty"`

	// Phase indicates when this responsibility applies (e.g., "pre-meeting").
	Phase string `json:"phase,omitempty"`

	// Priority indicates relative importance (e.g., "high", "medium", "low").
	Priority string `json:"priority,omitempty"`
}

Responsibility defines a specific accountability for a role.

type Role

type Role interface {
	// Name returns the role identifier (e.g., "meeting-pm", "code-reviewer").
	// Names should be lowercase with hyphens.
	Name() string

	// Description returns a human-readable description of the role.
	Description() string

	// Spec returns the complete role specification.
	// This includes all metadata, behaviors, policies, and metrics.
	Spec() *RoleSpec

	// SystemPrompt returns the system prompt that defines the role's persona.
	// The context can be used to incorporate dynamic information.
	SystemPrompt(ctx context.Context) (string, error)

	// RequiredSkills returns the names of skills this role needs.
	// These are validated and provided during Init.
	RequiredSkills() []string

	// Init initializes the role with its required skills.
	// Skills are provided as a map keyed by skill name.
	Init(ctx context.Context, skills map[string]skill.Skill) error

	// Close releases any resources held by the role.
	Close() error

	// Workflows returns the structured workflows this role supports.
	// Workflows are optional; roles can function with just the system prompt.
	Workflows() []Workflow
}

Role represents a high-level agent persona that composes skills.

Roles define how an agent behaves in a specific context. They are the primary abstraction for configuring agent behavior, combining skills with prompts and workflows.

Additional capabilities are provided through optional interfaces that roles can implement:

  • SkillRequirer: for roles that need optional skills beyond required
  • BehaviorProvider: for roles with context-aware behaviors
  • MetricsProvider: for roles with KPIs and success metrics
  • DelegationProvider: for roles that orchestrate sub-agents
  • PolicyProvider: for roles with governance rules

type RoleSpec

type RoleSpec struct {
	// ID is the unique identifier for this role (e.g., "meeting-pm").
	ID string `json:"id"`

	// Name is the human-readable name (e.g., "Meeting Program Manager").
	Name string `json:"name"`

	// Description provides a detailed explanation of the role.
	Description string `json:"description"`

	// Version is the semantic version of this role spec (e.g., "1.0.0").
	Version string `json:"version,omitempty"`

	// Purpose explains why this role exists.
	Purpose string `json:"purpose,omitempty"`

	// Goals define what success looks like for this role.
	Goals []string `json:"goals,omitempty"`

	// Responsibilities define what this role is accountable for.
	Responsibilities []Responsibility `json:"responsibilities,omitempty"`

	// Skills defines required and optional skill dependencies.
	Skills SkillRequirements `json:"skills"`

	// Policies define governance rules for the role.
	Policies []Policy `json:"policies,omitempty"`

	// Memory defines memory retention policies.
	Memory *MemoryPolicy `json:"memory,omitempty"`

	// Behaviors define context-specific actions.
	Behaviors []Behavior `json:"behaviors,omitempty"`

	// Artifacts define documents and outputs the role produces.
	Artifacts []ArtifactSpec `json:"artifacts,omitempty"`

	// Metrics define success measurements and KPIs.
	Metrics []MetricDefinition `json:"metrics,omitempty"`

	// Delegation configures sub-agent orchestration.
	Delegation *DelegationConfig `json:"delegation,omitempty"`

	// Persona defines communication style and tone.
	Persona *PersonaSpec `json:"persona,omitempty"`

	// Metadata contains arbitrary extension data.
	Metadata map[string]any `json:"metadata,omitempty"`
}

RoleSpec defines a complete role specification.

RoleSpec is the central data structure that captures everything about a role's identity, responsibilities, capabilities, and behaviors. It is designed to be serializable to JSON for machine-readable role definitions.

type SkillRef

type SkillRef struct {
	// Name is the skill identifier (e.g., "meeting", "google").
	Name string `json:"name"`

	// MinVersion is the minimum required version (optional).
	MinVersion string `json:"min_version,omitempty"`

	// Purpose explains why this skill is needed.
	Purpose string `json:"purpose,omitempty"`
}

SkillRef references a skill by name with optional version constraints.

func SkillRefsFromStrings

func SkillRefsFromStrings(names []string) []SkillRef

SkillRefsFromStrings converts a slice of skill names to SkillRef slice.

type SkillRequirements

type SkillRequirements struct {
	// Required lists skills that must be provided.
	Required []SkillRef `json:"required,omitempty"`

	// Optional lists skills that enhance the role but aren't mandatory.
	Optional []SkillRef `json:"optional,omitempty"`
}

SkillRequirements defines the skills a role needs.

type SkillRequirer

type SkillRequirer interface {
	// OptionalSkills returns skill names that enhance the role but aren't mandatory.
	OptionalSkills() []string
}

SkillRequirer is implemented by roles that have optional skills beyond the required skills specified in the Role interface.

type SubRole

type SubRole interface {
	Role

	// Parent returns the name of the parent role.
	Parent() string

	// Overrides returns prompt overrides or extensions for this subrole.
	Overrides() SubRoleOverrides
}

SubRole represents a specialized variant of a parent role. SubRoles inherit from a parent and can override or extend behavior.

type SubRoleOverrides

type SubRoleOverrides struct {
	// SystemPromptSuffix is appended to the parent's system prompt.
	SystemPromptSuffix string

	// AdditionalSkills are skills needed beyond the parent's requirements.
	AdditionalSkills []string

	// WorkflowOverrides maps workflow names to replacement workflows.
	WorkflowOverrides map[string]Workflow
}

SubRoleOverrides defines how a subrole modifies its parent.

type Workflow

type Workflow interface {
	// Name returns the workflow identifier (e.g., "prepare-meeting").
	Name() string

	// Description returns a human-readable description.
	Description() string

	// Trigger describes when this workflow should be invoked.
	// Can be "manual", "on_meeting_start", "on_meeting_end", etc.
	Trigger() string

	// InputSchema returns JSON Schema for the workflow's input parameters.
	// Returns nil if no input is required.
	InputSchema() map[string]any

	// Execute runs the workflow with the given input.
	// Returns the workflow result or an error.
	Execute(ctx context.Context, input map[string]any) (WorkflowResult, error)
}

Workflow represents a structured sequence of actions a role can execute.

Workflows provide deterministic, repeatable processes that the role can invoke. They're useful for multi-step operations like:

  • Pre-meeting preparation
  • Post-meeting wrap-up
  • Document review cycles

Workflows can be triggered explicitly by the user or automatically by the role based on context.

type WorkflowResult

type WorkflowResult struct {
	// Success indicates whether the workflow completed successfully.
	Success bool `json:"success"`

	// Output contains workflow-specific result data.
	Output map[string]any `json:"output,omitempty"`

	// Artifacts are files or documents produced by the workflow.
	Artifacts []Artifact `json:"artifacts,omitempty"`

	// Actions are follow-up items identified by the workflow.
	Actions []Action `json:"actions,omitempty"`

	// Message is a human-readable summary of the result.
	Message string `json:"message,omitempty"`

	// Error contains error details if Success is false.
	Error string `json:"error,omitempty"`
}

WorkflowResult contains the output of a workflow execution.

Jump to

Keyboard shortcuts

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