Documentation
¶
Overview ¶
包 crews 提供基于角色分工的多智能体团队协作框架。
概述 ¶
本包用于解决"多个智能体如何以团队形式协同完成复杂任务"的问题。 通过定义角色(Role)、成员(CrewMember)和任务(CrewTask), 将多个智能体组织为一个 Crew,并支持多种任务分配与执行策略。
核心模型 ¶
- Role:定义成员的角色名称、目标、技能列表与委派权限。
- CrewMember:持有角色定义与底层 CrewAgent 接口的成员实例。
- CrewTask:描述任务内容、期望输出、优先级与依赖关系。
- Proposal / NegotiationResult:成员间的协商提案与应答机制。
- Crew:团队容器,管理成员注册、任务队列与执行流程。
主要能力 ¶
- 顺序执行(Sequential):按任务列表顺序逐一分配并执行。
- 层级执行(Hierarchical):由管理者角色委派任务,支持协商拒绝与回退。
- 共识执行(Consensus):全体成员投票决定任务归属。
- 自动成员匹配:根据指定分配或空闲状态选择最佳执行者。
- 协商协议:支持 delegate、assist、inform、request 四种提案类型。
与 agent 包协同 ¶
crews 通过 CrewAgent 接口与上层 agent 解耦:任何实现了 Execute 和 Negotiate 方法的智能体均可作为团队成员加入 Crew, 从而在不修改核心 agent 逻辑的前提下实现多智能体协作。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Crew ¶
type Crew struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Members map[string]*CrewMember `json:"members"`
Tasks []*CrewTask `json:"tasks"`
Process ProcessType `json:"process"`
Verbose bool `json:"verbose"`
// contains filtered or unexported fields
}
船员代表一组特工一起工作.
type CrewAgent ¶
type CrewAgent interface {
ID() string
Execute(ctx context.Context, task CrewTask) (*TaskResult, error)
Negotiate(ctx context.Context, proposal Proposal) (*NegotiationResult, error)
}
机组特工的机组接口
type CrewConfig ¶
type CrewConfig struct {
Name string
Description string
Process ProcessType
Verbose bool
}
CrewConfig配置一个船员.
type CrewMember ¶
type CrewMember struct {
ID string `json:"id"`
Role Role `json:"role"`
Agent CrewAgent `json:"-"`
Status MemberStatus `json:"status"`
Metadata map[string]any `json:"metadata,omitempty"`
}
船员代表一个船员的特工
type CrewResult ¶
type CrewResult struct {
CrewID string `json:"crew_id"`
TaskResults map[string]*TaskResult `json:"task_results"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
}
CrewResult载有船员行刑的结果.
type CrewTask ¶
type CrewTask struct {
ID string `json:"id"`
Description string `json:"description"`
Expected string `json:"expected_output"`
Context string `json:"context,omitempty"`
AssignedTo string `json:"assigned_to,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Priority int `json:"priority"`
Metadata map[string]any `json:"metadata,omitempty"`
}
船员任务代表着船员的任务.
type MemberStatus ¶
type MemberStatus string
成员地位代表船员地位。
const ( MemberStatusIdle MemberStatus = "idle" MemberStatusWorking MemberStatus = "working" MemberStatusWaiting MemberStatus = "waiting" )
type NegotiationResult ¶
type NegotiationResult struct {
Accepted bool `json:"accepted"`
Response string `json:"response"`
Counter *Proposal `json:"counter_proposal,omitempty"`
}
谈判成果是谈判的结果。
type ProcessType ¶
type ProcessType string
ProcessType定义任务处理方式.
const ( ProcessSequential ProcessType = "sequential" ProcessHierarchical ProcessType = "hierarchical" ProcessConsensus ProcessType = "consensus" )
type Proposal ¶
type Proposal struct {
Type ProposalType `json:"type"`
FromMember string `json:"from_member"`
ToMember string `json:"to_member,omitempty"`
Task *CrewTask `json:"task,omitempty"`
Message string `json:"message"`
Metadata map[string]any `json:"metadata,omitempty"`
}
提案是谈判提案。
type ProposalType ¶
type ProposalType string
提案Type定义了提案的类型.
const ( ProposalTypeDelegate ProposalType = "delegate" ProposalTypeAssist ProposalType = "assist" ProposalTypeInform ProposalType = "inform" ProposalTypeRequest ProposalType = "request" )
type Role ¶
type Role struct {
Name string `json:"name"`
Description string `json:"description"`
Goal string `json:"goal"`
Backstory string `json:"backstory,omitempty"`
Skills []string `json:"skills"`
Tools []string `json:"tools,omitempty"`
AllowDelegation bool `json:"allow_delegation"`
}
角色定义了代理人在船员中的角色.
Click to show internal directories.
Click to hide internal directories.