feat(orchestration): 子代理编排调度器(创建/生命周期/并行上限4/超时/防失控/结果合并/进度事件/隔离上下文+独立工作记忆)
This commit is contained in:
1 parent
20f4a91d02
commit
d90ec7bd4f
8 files changed
+1618
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package orchestration
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/bus"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/loop"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/memory"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/orchestration/audit"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/orchestration/comm"
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/trace"
|
||||
)
|
||||
|
||||
// Defaults for the orchestration layer.
|
||||
const (
|
||||
// DefaultMaxParallel is the maximum number of sub-agents that run at once
|
||||
// when Options.MaxParallel is non-positive.
|
||||
DefaultMaxParallel = 4
|
||||
|
||||
// defaultAgentID is the comm probe identity used when Options.AgentID is
|
||||
// blank and a probe must be built from Bus.
|
||||
defaultAgentID = "orchestrator"
|
||||
)
|
||||
|
||||
// Options configures a Scheduler built by New. All fields are optional; each nil
|
||||
// dependency degrades gracefully (a missing Loop makes sub-agents fail fast, a
|
||||
// missing Comm skips progress events, a missing Approver makes Approve error,
|
||||
// and so on).
|
||||
type Options struct {
|
||||
// MaxParallel caps how many sub-agents execute concurrently. Excess sub-agents
|
||||
// queue until a slot frees. Non-positive selects DefaultMaxParallel (4).
|
||||
MaxParallel int
|
||||
|
||||
// PerAgentTimeout bounds every sub-agent's run. When it elapses the sub-agent
|
||||
// is aborted (status aborted). Non-positive means no timeout.
|
||||
PerAgentTimeout time.Duration
|
||||
|
||||
// Loop is the execution template: a *loop.Loop used to run every sub-agent.
|
||||
// It must be safe for concurrent Run calls (as loop.Loop documents); the
|
||||
// template's agent/tools/guardrails/persona apply to every sub-agent. When
|
||||
// nil, sub-agents fail fast with ErrNoRunner.
|
||||
Loop *loop.Loop
|
||||
|
||||
// Bus is the in-process event bus used for progress events and, when Comm is
|
||||
// nil, to build a default comm probe. When nil no events are published.
|
||||
Bus bus.Bus
|
||||
|
||||
// Comm is the comm probe used to publish progress events. When nil, a probe
|
||||
// bound to AgentID is built from Bus (when Bus is non-nil).
|
||||
Comm *comm.Probe
|
||||
|
||||
// Memory is the long-term memory store used by SinkMemory. Optional.
|
||||
Memory *memory.Store
|
||||
|
||||
// Tracer emits a per-sub-agent span (kind subagent) around each run. Optional.
|
||||
Tracer *trace.Tracer
|
||||
|
||||
// Approver records sensitive-operation review-and-approve (代审) triggered by
|
||||
// Approve. Policy judgement belongs to the upper layer. Optional.
|
||||
Approver *audit.Approver
|
||||
|
||||
// Logger is the base logger. Nil is replaced with a discard logger tagged with
|
||||
// source "orchestration".
|
||||
Logger *slog.Logger
|
||||
|
||||
// AgentID is the comm probe identity. When blank and a probe must be built
|
||||
// from Bus, "orchestrator" is used.
|
||||
AgentID string
|
||||
}
|
||||
Reference in new issue
Block a user