Add files via upload

This commit is contained in:
公明
2026-08-15 01:45:01 +08:00
committed by GitHub
parent 31f80b2f0c
commit a6631a5cde
46 changed files with 4672 additions and 317 deletions
+54 -1
View File
@@ -10,6 +10,7 @@ import (
"github.com/cloudwego/eino/adk"
"github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/schema"
)
const userContextSupplementHeader = "\n\n## 用户历史输入(原文,子代理必读)\n"
@@ -47,10 +48,54 @@ func newTaskContextEnrichMiddleware(userMessage string, history []agent.ChatMess
return &taskContextEnrichMiddleware{supplement: supplement}
}
type agenticTaskContextEnrichMiddleware struct {
*adk.TypedBaseChatModelAgentMiddleware[*schema.AgenticMessage]
supplement string
}
func newAgenticTaskContextEnrichMiddleware(userMessage string, history []agent.ChatMessage, maxRunes int, projectBlackboard string) adk.TypedChatModelAgentMiddleware[*schema.AgenticMessage] {
supplement := buildUserContextSupplement(userMessage, history, maxRunes)
if bb := strings.TrimSpace(projectBlackboard); bb != "" {
if supplement != "" {
supplement += "\n\n" + bb
} else {
supplement = "\n\n" + bb
}
}
if supplement == "" {
return nil
}
return &agenticTaskContextEnrichMiddleware{
TypedBaseChatModelAgentMiddleware: &adk.TypedBaseChatModelAgentMiddleware[*schema.AgenticMessage]{},
supplement: supplement,
}
}
func (m *taskContextEnrichMiddleware) WrapInvokableToolCall(
ctx context.Context,
endpoint adk.InvokableToolCallEndpoint,
tCtx *adk.ToolContext,
) (adk.InvokableToolCallEndpoint, error) {
return wrapTaskContextEnrichCall(m, ctx, endpoint, tCtx)
}
func (m *agenticTaskContextEnrichMiddleware) WrapInvokableToolCall(
ctx context.Context,
endpoint adk.InvokableToolCallEndpoint,
tCtx *adk.ToolContext,
) (adk.InvokableToolCallEndpoint, error) {
return wrapTaskContextEnrichCall(m, ctx, endpoint, tCtx)
}
type taskContextEnricher interface {
enrichTaskDescription(argsJSON string) string
}
func wrapTaskContextEnrichCall(
m taskContextEnricher,
ctx context.Context,
endpoint adk.InvokableToolCallEndpoint,
tCtx *adk.ToolContext,
) (adk.InvokableToolCallEndpoint, error) {
if tCtx == nil || !strings.EqualFold(strings.TrimSpace(tCtx.Name), "task") {
return endpoint, nil
@@ -65,6 +110,14 @@ func (m *taskContextEnrichMiddleware) WrapInvokableToolCall(
// to the "description" field, and re-serializes. Falls back to the original
// JSON if parsing fails or no description field exists.
func (m *taskContextEnrichMiddleware) enrichTaskDescription(argsJSON string) string {
return enrichTaskDescriptionWithSupplement(argsJSON, m.supplement)
}
func (m *agenticTaskContextEnrichMiddleware) enrichTaskDescription(argsJSON string) string {
return enrichTaskDescriptionWithSupplement(argsJSON, m.supplement)
}
func enrichTaskDescriptionWithSupplement(argsJSON, supplement string) string {
var raw map[string]interface{}
if err := json.Unmarshal([]byte(argsJSON), &raw); err != nil {
return argsJSON
@@ -73,7 +126,7 @@ func (m *taskContextEnrichMiddleware) enrichTaskDescription(argsJSON string) str
if !ok {
return argsJSON
}
raw["description"] = desc + m.supplement
raw["description"] = desc + supplement
enriched, err := json.Marshal(raw)
if err != nil {
return argsJSON