feat: Add DataSchema tool for retrieving schema information from CSV and Excel files

This commit is contained in:
begoniezhao
2025-12-23 16:56:30 +08:00
parent ddf5ae4e65
commit 907e9a5522
51 changed files with 2784 additions and 1307 deletions
+20 -20
View File
@@ -10,22 +10,22 @@ import (
// AgentConfig represents the full agent configuration (used at tenant level and runtime)
// This includes all configuration parameters for agent execution
type AgentConfig struct {
MaxIterations int `json:"max_iterations"` // Maximum number of ReAct iterations
ReflectionEnabled bool `json:"reflection_enabled"` // Whether to enable reflection
AllowedTools []string `json:"allowed_tools"` // List of allowed tool names
Temperature float64 `json:"temperature"` // LLM temperature for agent
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs
KnowledgeIDs []string `json:"knowledge_ids"` // Accessible knowledge IDs (individual documents)
SystemPrompt string `json:"system_prompt,omitempty"` // Unified system prompt (uses {{web_search_status}} placeholder for dynamic behavior)
MaxIterations int `json:"max_iterations"` // Maximum number of ReAct iterations
ReflectionEnabled bool `json:"reflection_enabled"` // Whether to enable reflection
AllowedTools []string `json:"allowed_tools"` // List of allowed tool names
Temperature float64 `json:"temperature"` // LLM temperature for agent
KnowledgeBases []string `json:"knowledge_bases"` // Accessible knowledge base IDs
KnowledgeIDs []string `json:"knowledge_ids"` // Accessible knowledge IDs (individual documents)
SystemPrompt string `json:"system_prompt,omitempty"` // Unified system prompt (uses {{web_search_status}} placeholder for dynamic behavior)
// Deprecated: Use SystemPrompt instead. Kept for backward compatibility during migration.
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"` // Deprecated: Custom prompt when web search is enabled
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"` // Deprecated: Custom prompt when web search is disabled
UseCustomSystemPrompt bool `json:"use_custom_system_prompt"` // Whether to use custom system prompt instead of default
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search tool is enabled
WebSearchMaxResults int `json:"web_search_max_results"` // Maximum number of web search results (default: 5)
MultiTurnEnabled bool `json:"multi_turn_enabled"` // Whether multi-turn conversation is enabled
HistoryTurns int `json:"history_turns"` // Number of history turns to keep in context
SearchTargets SearchTargets `json:"-"` // Pre-computed unified search targets (runtime only)
SystemPromptWebEnabled string `json:"system_prompt_web_enabled,omitempty"` // Deprecated: Custom prompt when web search is enabled
SystemPromptWebDisabled string `json:"system_prompt_web_disabled,omitempty"` // Deprecated: Custom prompt when web search is disabled
UseCustomSystemPrompt bool `json:"use_custom_system_prompt"` // Whether to use custom system prompt instead of default
WebSearchEnabled bool `json:"web_search_enabled"` // Whether web search tool is enabled
WebSearchMaxResults int `json:"web_search_max_results"` // Maximum number of web search results (default: 5)
MultiTurnEnabled bool `json:"multi_turn_enabled"` // Whether multi-turn conversation is enabled
HistoryTurns int `json:"history_turns"` // Number of history turns to keep in context
SearchTargets SearchTargets `json:"-"` // Pre-computed unified search targets (runtime only)
// MCP service selection
MCPSelectionMode string `json:"mcp_selection_mode"` // MCP selection mode: "all", "selected", "none"
MCPServices []string `json:"mcp_services"` // Selected MCP service IDs (when mode is "selected")
@@ -109,10 +109,10 @@ type Tool interface {
Description() string
// Parameters returns the JSON Schema for the tool's parameters
Parameters() map[string]interface{}
Parameters() json.RawMessage
// Execute runs the tool with the given arguments
Execute(ctx context.Context, args map[string]interface{}) (*ToolResult, error)
Execute(ctx context.Context, args json.RawMessage) (*ToolResult, error)
}
// ToolResult represents the result of a tool execution
@@ -167,7 +167,7 @@ type AgentState struct {
// FunctionDefinition represents a function definition for LLM function calling
type FunctionDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
Parameters map[string]interface{} `json:"parameters"`
Name string `json:"name"`
Description string `json:"description"`
Parameters json.RawMessage `json:"parameters"`
}
+2
View File
@@ -140,6 +140,7 @@ const (
ENTITY_SEARCH EventType = "entity_search" // Search for relevant entities
CHUNK_RERANK EventType = "chunk_rerank" // Rerank search results
CHUNK_MERGE EventType = "chunk_merge" // Merge similar chunks
DATA_ANALYSIS EventType = "data_analysis" // Data analysis for CSV/Excel files
INTO_CHAT_MESSAGE EventType = "into_chat_message" // Convert chunks into chat messages
CHAT_COMPLETION EventType = "chat_completion" // Generate chat completion
CHAT_COMPLETION_STREAM EventType = "chat_completion_stream" // Stream chat completion
@@ -174,6 +175,7 @@ var Pipline = map[string][]EventType{
CHUNK_RERANK,
CHUNK_MERGE,
FILTER_TOP_K,
DATA_ANALYSIS,
INTO_CHAT_MESSAGE,
CHAT_COMPLETION_STREAM,
STREAM_FILTER,
+5 -1
View File
@@ -9,7 +9,7 @@ import (
)
// ChunkType 定义了不同类型的 Chunk
type ChunkType string
type ChunkType = string
const (
// ChunkTypeText 表示普通的文本 Chunk
@@ -28,6 +28,10 @@ const (
ChunkTypeFAQ ChunkType = "faq"
// ChunkTypeWebSearch 表示 Web 搜索结果的 Chunk
ChunkTypeWebSearch ChunkType = "web_search"
// ChunkTypeTableSummary 表示数据表摘要的 Chunk
ChunkTypeTableSummary ChunkType = "table_summary"
// ChunkTypeTableColumn 表示数据表列描述的 Chunk
ChunkTypeTableColumn ChunkType = "table_column"
)
// ChunkStatus 定义了不同状态的 Chunk
+3 -2
View File
@@ -20,8 +20,9 @@ const (
MatchTypeParentChunk // 父Chunk匹配类型
MatchTypeRelationChunk // 关系Chunk匹配类型
MatchTypeGraph
MatchTypeWebSearch // 网络搜索匹配类型
MatchTypeDirectLoad // 直接加载匹配类型
MatchTypeWebSearch // 网络搜索匹配类型
MatchTypeDirectLoad // 直接加载匹配类型
MatchTypeDataAnalysis // 数据分析匹配类型
)
// IndexInfo contains information about indexed content
+18 -17
View File
@@ -1,14 +1,15 @@
package types
const (
TypeChunkExtract = "chunk:extract"
TypeDocumentProcess = "document:process" // 文档处理任务
TypeFAQImport = "faq:import" // FAQ导入任务
TypeQuestionGeneration = "question:generation" // 问题生成任务
TypeSummaryGeneration = "summary:generation" // 摘要生成任务
TypeKBClone = "kb:clone" // 知识库复制任务
TypeIndexDelete = "index:delete" // 索引删除任务
TypeKBDelete = "kb:delete" // 知识库删除任务
TypeChunkExtract = "chunk:extract"
TypeDocumentProcess = "document:process" // 文档处理任务
TypeFAQImport = "faq:import" // FAQ导入任务
TypeQuestionGeneration = "question:generation" // 问题生成任务
TypeSummaryGeneration = "summary:generation" // 摘要生成任务
TypeKBClone = "kb:clone" // 知识库复制任务
TypeIndexDelete = "index:delete" // 索引删除任务
TypeKBDelete = "kb:delete" // 知识库删除任务
TypeDataTableSummary = "datatable:summary" // 表格摘要任务
)
// ExtractChunkPayload represents the extract chunk task payload
@@ -24,11 +25,11 @@ type DocumentProcessPayload struct {
TenantID uint64 `json:"tenant_id"`
KnowledgeID string `json:"knowledge_id"`
KnowledgeBaseID string `json:"knowledge_base_id"`
FilePath string `json:"file_path,omitempty"` // 文件路径(文件导入时使用)
FileName string `json:"file_name,omitempty"` // 文件名(文件导入时使用)
FileType string `json:"file_type,omitempty"` // 文件类型(文件导入时使用)
URL string `json:"url,omitempty"` // URL(URL导入时使用)
Passages []string `json:"passages,omitempty"` // 文本段落(文本导入时使用)
FilePath string `json:"file_path,omitempty"` // 文件路径(文件导入时使用)
FileName string `json:"file_name,omitempty"` // 文件名(文件导入时使用)
FileType string `json:"file_type,omitempty"` // 文件类型(文件导入时使用)
URL string `json:"url,omitempty"` // URL(URL导入时使用)
Passages []string `json:"passages,omitempty"` // 文本段落(文本导入时使用)
EnableMultimodel bool `json:"enable_multimodel"`
EnableQuestionGeneration bool `json:"enable_question_generation"` // 是否启用问题生成
QuestionCount int `json:"question_count,omitempty"` // 每个chunk生成的问题数量
@@ -111,10 +112,10 @@ type KBCloneProgress struct {
// ChunkContext represents chunk content with surrounding context
type ChunkContext struct {
ChunkID string `json:"chunk_id"`
Content string `json:"content"`
PrevContent string `json:"prev_content,omitempty"` // Previous chunk content for context
NextContent string `json:"next_content,omitempty"` // Next chunk content for context
ChunkID string `json:"chunk_id"`
Content string `json:"content"`
PrevContent string `json:"prev_content,omitempty"` // Previous chunk content for context
NextContent string `json:"next_content,omitempty"` // Next chunk content for context
}
// PromptTemplateStructured represents the prompt template structured
-1
View File
@@ -39,7 +39,6 @@ type AgentService interface {
eventBus *event.EventBus,
contextManager ContextManager,
sessionID string,
sessionService SessionService,
) (AgentEngine, error)
// ValidateConfig validates an agent configuration
-13
View File
@@ -1,13 +0,0 @@
package interfaces
import (
"context"
"github.com/hibiken/asynq"
)
// Extracter is a interface for extracting entities
type Extracter interface {
// Extract extracts entities from a task
Extract(ctx context.Context, t *asynq.Task) error
}
-16
View File
@@ -61,22 +61,6 @@ type SessionService interface {
) error
// ClearContext clears the LLM context for a session
ClearContext(ctx context.Context, sessionID string) error
// GetWebSearchTempKBState retrieves the temporary KB state for web search from Redis
GetWebSearchTempKBState(
ctx context.Context,
sessionID string,
) (tempKBID string, seenURLs map[string]bool, knowledgeIDs []string)
// SaveWebSearchTempKBState saves the temporary KB state for web search to Redis
SaveWebSearchTempKBState(
ctx context.Context,
sessionID string,
tempKBID string,
seenURLs map[string]bool,
knowledgeIDs []string,
)
// DeleteWebSearchTempKBState deletes the temporary KB state for web search from Redis
// and cleans up associated knowledge base and knowledge items
DeleteWebSearchTempKBState(ctx context.Context, sessionID string) error
}
// SessionRepository defines the session repository interface
+13
View File
@@ -0,0 +1,13 @@
package interfaces
import (
"context"
"github.com/hibiken/asynq"
)
// TaskHandler is a interface for handling asynchronous tasks
type TaskHandler interface {
// Handle handles the task
Handle(ctx context.Context, t *asynq.Task) error
}
@@ -0,0 +1,26 @@
package interfaces
import (
"context"
)
// WebSearchStateService defines the service interface for managing web search temporary KB state
type WebSearchStateService interface {
// GetWebSearchTempKBState retrieves the temporary KB state for web search from Redis
GetWebSearchTempKBState(
ctx context.Context,
sessionID string,
) (tempKBID string, seenURLs map[string]bool, knowledgeIDs []string)
// SaveWebSearchTempKBState saves the temporary KB state for web search to Redis
SaveWebSearchTempKBState(
ctx context.Context,
sessionID string,
tempKBID string,
seenURLs map[string]bool,
knowledgeIDs []string,
)
// DeleteWebSearchTempKBState deletes the temporary KB state for web search from Redis
DeleteWebSearchTempKBState(ctx context.Context, sessionID string) error
}
+3 -3
View File
@@ -65,9 +65,9 @@ type MCPEnvVars map[string]string
// MCPTool represents a tool exposed by an MCP service
type MCPTool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"` // JSON Schema for tool parameters
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"` // JSON Schema for tool parameters
}
// MCPResource represents a resource exposed by an MCP service