Files
Agent-System-Backend/internal/runtime/runner.go
T
weichen 53c6630eca Add submit_card explicit routing with card-as-authority and context backfill (CF1)
Why: 卡流机制(D39–D43)——产物型长内容显式路由进收件箱:模型经 submit_card 提交 result 卡,全文权威在卡片,消息只存引用,上下文回填防失忆。
Evidence: go test ./internal/runtime/(门控/产卡/引用部件)、./internal/ctxasm/(回填/截断/占位)、./internal/server/ 全绿(新增 TestMockCardflowFullLoop:#cardflow → result 卡 + cardId 部件 + finishRun 锚点回填)。
Impact: 新内置工具 submit_card(ui.cardflow 默认关闭,未声明被幻觉调用时拒绝执行);settings 增 ui.cardflow;style-cardflow 模块 + ModuleBody 注入;ctxasm 增 CardResolver 与 card(n) 观测;runmgr 增 SubmitCard/Card 与锚点回填;mock 增 #cardflow。
Refs: Dev 任务卡 feature/cardflow-r1;依赖 core bcfacee(CardPart.CardID)。
2026-09-30 16:30:13 +00:00

50 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Package runtime 定义智能体执行端口与实现:mock(脚本回放)与 LLM
// (复用 agent-native 的 OpenAI 兼容流式客户端)。执行编排归 runmgr。
package runtime
import (
"context"
core "agent-system-core"
)
// RunCtx 是 Runner 的受控环境(由 runmgr 实现):事件发布、HITL、子代理、
// 工件、检索、工具执行、历史。Runner 不得绕过 RunCtx 直接写库。
type RunCtx interface {
Context() context.Context
Run() core.Run
Profile() core.AgentProfile
Settings() core.EffectiveSettings
Emit(typ core.StreamEventType, payload any) error
SetAssistantParts(parts []core.Part) error
AskHITL(card core.HITLCard) (core.HITLResponse, error)
SpawnSubagent(name, task string, hint string) (core.AgentResultPayload, error)
UpdatePlan(p core.PlanSnapshot) error
UpdateTodos(l core.TodoList) error
WriteArtifact(name, kind, mime string, content []byte) (core.Artifact, error)
Retrieve(q core.RetrievalQuery) ([]core.RetrievalHit, error)
ExecuteTool(call core.ToolCallRequest) core.ToolCallResult
History() []core.Message
Attachments() []core.ParsedDocument
// Tools 返回注册表全部工具(画像过滤由 runner 做)。
Tools() []core.ToolDesc
// Subtask 返回子代理任务描述(仅 subagent run 有值)。
Subtask() string
// CreateCard / SetCardStatus:产收件箱任务卡(收件箱关闭时为 no-op)。
CreateCard(card core.ActivityCard) (core.ActivityCard, error)
SetCardStatus(id string, status core.CardStatus, tone, note string) error
// SubmitCard:产物卡提交(submit_card 工具)——建卡并登记,finishRun 落库助手
// 消息后回填 AnchorMessageID(卡→消息互定位)。
SubmitCard(card core.ActivityCard) (core.ActivityCard, error)
// Card:按 ID 取卡(ctxasm 回填 card 部件正文用;无则 nil)。
Card(id string) *core.ActivityCard
// SetContextObservation 记录本次运行的上下文组装观测(随 run.completed 下发)。
SetContextObservation(o core.ContextObservation)
}
// Runner 执行一个 run 至终态:返回 nil = completed;ctx 取消应返回 ctx.Err()。
type Runner interface {
Name() string
Execute(rc RunCtx) error
}