51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
|
|
"eino-test/config"
|
|
"eino-test/internal/rag"
|
|
|
|
"github.com/cloudwego/eino/adk"
|
|
"github.com/cloudwego/eino/adk/prebuilt/supervisor"
|
|
)
|
|
|
|
func NewSupervisorAgent(ctx context.Context, cfg *config.Config, pipeline *rag.RAGPipeline) (adk.Agent, error) {
|
|
chatModel, err := NewChatModel(ctx, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
retrievalAgent := NewRetrievalAgent(ctx, chatModel, pipeline)
|
|
writerAgent := NewWriterAgent(ctx, chatModel, pipeline)
|
|
organizerAgent := NewOrganizerAgent(ctx, chatModel, pipeline)
|
|
|
|
supervisorAgent, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
|
|
Name: "KnowledgeSupervisor",
|
|
Description: "Personal knowledge assistant that routes tasks to specialized agents.",
|
|
Instruction: `You are a personal knowledge assistant supervisor. Your job is to understand the user's request and route it to the right specialist agent.
|
|
|
|
Available agents:
|
|
- RetrievalAgent: For searching and finding information in the knowledge base. Use when the user asks to find, search, or look up notes.
|
|
- WriterAgent: For creating new notes or generating summaries. Use when the user wants to write, create, or summarize content.
|
|
- OrganizerAgent: For tagging notes and discovering related content. Use when the user wants to organize, categorize, or find connections.
|
|
|
|
Workflow:
|
|
1. Analyze the user's request to determine which agent(s) should handle it.
|
|
2. Transfer the task to the appropriate agent.
|
|
3. If the task requires multiple agents (e.g., search then summarize), coordinate them in sequence.
|
|
4. After all sub-agents complete, synthesize their results into a clear final response for the user.
|
|
|
|
If the request is simple conversation (greetings, general questions), respond directly without transferring.`,
|
|
Model: chatModel,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return supervisor.New(ctx, &supervisor.Config{
|
|
Supervisor: supervisorAgent,
|
|
SubAgents: []adk.Agent{retrievalAgent, writerAgent, organizerAgent},
|
|
})
|
|
}
|