Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoPendingSessionMessages = errors.New("no pending session messages")
Functions ¶
func ApplyInvokedSkills ¶ added in v0.1.11
func ApplyInvokedSkills(ctx context.Context, req *agent.RequestContext) error
ApplyInvokedSkills parses leading /skill tokens from user messages, loads matching SKILL.md content, strips the tokens, and rewrites message content.
The same skill is injected only once across all messages. Later messages that mention an already loaded skill only have the token stripped.
Each message is rewritten independently using the same prompt format for one or many newly loaded skills.
It returns an error only when a requested skill is missing or has a manifest mismatch. Messages with no leading skill token are left unchanged.
func CloneRequest ¶
func CloneRequest(req *agent.RequestContext) *agent.RequestContext
CloneRequest 深拷贝一份 RequestContext,防止 Prepare 过程污染原始请求。
func TruncateForPrompt ¶
TruncateForPrompt 将字符串截断到指定长度,超长时追加截断标记。
Types ¶
type ContextBuilder ¶
type ContextBuilder struct {
SessionMessages SessionMessageProvider
}
ContextBuilder 统一为内部 Agent 和外部 CLI 构建运行上下文。
func NewContextBuilder ¶
func NewContextBuilder(cfg ContextBuilder) *ContextBuilder
NewContextBuilder 创建统一上下文构建器。
func (*ContextBuilder) BuildSystemPrompt ¶
func (b *ContextBuilder) BuildSystemPrompt(ctx context.Context, req *agent.RequestContext) (string, error)
BuildSystemPrompt 生成统一系统提示词,供所有运行时复用。 组装顺序:
- 角色定义(Leros 助手身份 + Assistant 级 SystemPrompt)
- 任务完成(反编造、持续执行直到产出真实结果)
- 工具强制(执行纪律、必须用工具而非描述意图)
- Skill 使用指导(加载指令 + 保存/patch 指令 + <available_skills>)
- Memory 工具使用指导
- 项目工作区信息(可见性规则 + 运行系统环境)
- 产物声明(必须声明交付物,否则用户不可见)
- 持久化记忆注入(USER.md + MEMORY.md)
- 运行元信息(日期 / SessionID / Model)
10. 平台格式指导(按 Channel)
func (*ContextBuilder) Prepare ¶
func (b *ContextBuilder) Prepare(ctx context.Context, req *agent.RequestContext) (*agent.RequestContext, error)
Prepare 克隆请求并注入 memory、skill、session 上下文。
type PassthroughSessionMessageProvider ¶
type PassthroughSessionMessageProvider struct{}
PassthroughSessionMessageProvider 无 DB 依赖的会话消息提供器。 不加载历史上下文,不占位消息,仅校验输入是否为空来决定是否跳过执行。
func (*PassthroughSessionMessageProvider) CompleteClaimed ¶
func (p *PassthroughSessionMessageProvider) CompleteClaimed(_ context.Context, _ *agent.RequestContext) error
CompleteClaimed 不需要做任何事。Worker 完成结果通过 NATS 事件通知 Server 侧 runnable 写入 DB。
func (*PassthroughSessionMessageProvider) Prepare ¶
func (p *PassthroughSessionMessageProvider) Prepare(_ context.Context, req *agent.RequestContext) error
Prepare 校验是否有待处理的用户输入。有则放行,无则返回 ErrNoPendingSessionMessages 让 pipeline 跳过。
type SessionMessageProvider ¶
type SessionMessageProvider interface {
// Prepare 构建历史上下文、占位本轮待处理用户消息,并填充运行输入。
Prepare(ctx context.Context, req *agent.RequestContext) error
// CompleteClaimed 将本轮已占位的用户消息标记为已处理。
CompleteClaimed(ctx context.Context, req *agent.RequestContext) error
}
SessionMessageProvider 将持久化的会话消息注入到 Agent 运行上下文中。
func NewPassthroughSessionMessageProvider ¶
func NewPassthroughSessionMessageProvider() SessionMessageProvider
NewPassthroughSessionMessageProvider 创建无 DB 依赖的会话消息提供器。