Documentation
¶
Index ¶
Constants ¶
const ( // Stage constants represent the different stages of the research process. StageThinking = "thinking" // Thinking stage StageSearching = "searching" // Searching stage StageAnalyzing = "analyzing" // Analyzing stage StageSynthesizing = "synthesizing" // Synthesizing stage StageCompleted = "completed" // Completed stage StageError = "error" // Error stage // Action constants represent specific actions within the agent's workflow. ActionGenerateQuestions Action = "generate_questions" ActionQuestionSelection Action = "question_selection" ActionNetworkSearch Action = "network_search" ActionSearchComplete Action = "search_complete" ActionWebScraping Action = "web_scraping" ActionSkipScraping Action = "skip_scraping" ActionScrapingComplete Action = "scraping_complete" ActionContentAnalysis Action = "content_analysis" ActionRealtimeAnalysis Action = "realtime_analysis" ActionAnalysisComplete Action = "analysis_complete" ActionSynthesisAnalysis Action = "synthesis_analysis" ActionRealtimeSynthesis Action = "realtime_synthesis" ActionIterationIncrement Action = "iteration_increment" ActionProgressCheck Action = "progress_check" ActionIterationComplete Action = "iteration_complete" ActionModelJudgeSufficient Action = "model_judge_sufficient" ActionContinueResearch Action = "continue_research" ActionGenerateNewQuestions Action = "generate_new_questions" ActionPrepareSynthesis Action = "prepare_synthesis" ActionStepAllocation Action = "step_allocation" ActionQuestionLimitReached Action = "question_limit_reached" ActionQuestionGenComplete Action = "question_gen_complete" ActionResearchComplete Action = "research_complete" ActionError Action = "error" // Question status constants. QuestionStatusPending = "pending" // Pending research QuestionStatusResearching = "researching" // Currently researching QuestionStatusCompleted = "completed" // Research completed // Eino node name constants. NodeStartThinking = "start_thinking" NodeGenerateQuestions = "generate_questions" NodeSelectQuestion = "select_question" NodeSearchQuestion = "search_question" NodeScrapeWebContent = "scrape_web_content" NodeAnalyzeQuestion = "analyze_question" NodeSynthesizeFinalAnswer = "synthesize_final_answer" NodeIncrementIteration = "increment_iteration" // Workflow graph name. GraphNameStreamingResearch = "StreamingResearchGraph" // Workflow step calculation constant. // Steps required for researching each sub-question: selectQuestion(1) + selectBranch(1) + searchQuestion(1) + scrapeWebContent(1) + analyzeQuestion(1) + checkCompletion(1) StepsPerQuestion = 6 // Question ID prefix. QuestionIDPrefix = "q_" // Similarity threshold constants. SimilarityThreshold = 0.5 // Threshold for question similarity judgment. MinWordLength = 2 // Minimum word length. )
Constants definition
const ( GenerateQuestionsPromptTemplate = `` /* 2758-byte string literal not displayed */ // AnalyzeQuestionPromptTemplate is the prompt template for analyzing a single research question. // It instructs the LLM to act as a research analyst, providing a concise answer based *only* // on the provided context and source URLs. It mandates strict source citation and accuracy. // The output format requires the main answer and a list of referenced URLs. AnalyzeQuestionPromptTemplate = `` /* 1593-byte string literal not displayed */ // SynthesizeFinalAnswerPromptTemplate is the prompt template for synthesizing the final research report. // It guides the LLM to act as a lead research analyst, compiling all accumulated findings // into a single, comprehensive, and well-structured document. It specifies detailed requirements // for structure, formatting, mandatory citations, and URL management. SynthesizeFinalAnswerPromptTemplate = `` /* 2951-byte string literal not displayed */ // ShouldSynthesizeEarlyPromptTemplate is the prompt template for determining if enough information // has been gathered to synthesize a final report ahead of schedule. // It asks the LLM to perform a meta-cognitive check on the coverage and depth of the // accumulated findings against the original query. // The output is strictly boolean (`true` or `false`). ShouldSynthesizeEarlyPromptTemplate = `` /* 1709-byte string literal not displayed */ )
GenerateQuestionsPromptTemplate is the prompt template for generating research questions. It instructs the LLM to act as a research strategist, deconstructing a user's query into a set of specific, actionable sub-questions. It defines a structured process for analysis and rules for question generation, including aspects like dimensionality, specificity, logical flow, and prioritization. The output is expected in a strict JSON format.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ResearchQuestion ¶
type ResearchQuestion struct {
ID string `json:"id"` // Unique identifier for the question (e.g., q_iteration_index).
Question string `json:"question"` // The content of the research question.
Status string `json:"status"` // Status: pending, researching, completed.
SearchResults []*tools.SearchResponse `json:"search_results"` // List of results from the search engine.
WebContents []*tools.WebScrapeResponse `json:"web_contents"` // Scraped web content details.
Analysis string `json:"analysis"` // In-depth analysis based on the collected information.
Priority int `json:"priority"` // Priority of the question (1-10), higher is more important.
}
ResearchQuestion represents a specific sub-question within the research process, encompassing its complete lifecycle from generation to analysis.
type StreamingResearchAgent ¶
type StreamingResearchAgent struct {
// contains filtered or unexported fields
}
StreamingResearchAgent is an intelligent research agent based on the Eino framework, supporting real-time, streaming output of the research process.
func NewStreamingResearchAgent ¶
func NewStreamingResearchAgent(ctx context.Context) (*StreamingResearchAgent, error)
NewStreamingResearchAgent creates a new StreamingResearchAgent. It initializes all necessary components (LLM, search tool, web scraping tool) and builds the workflow graph that defines the agent's behavior.
Parameters:
- ctx: A context.Context to control the initialization lifecycle.
Returns:
- *StreamingResearchAgent: An initialized research agent instance.
- error: An error if any part of the initialization fails.
func (*StreamingResearchAgent) ResearchWithStreaming ¶
func (agent *StreamingResearchAgent) ResearchWithStreaming(ctx context.Context, query string) (<-chan *StreamingThought, error)
ResearchWithStreaming executes a streaming research process. It starts an asynchronous research workflow and returns a channel that provides real-time thoughts and updates from the agent.
Parameters:
- ctx: A context.Context to control the research lifecycle.
- query: The user's original research query.
Returns:
- <-chan *StreamingThought: A read-only channel for receiving streaming thoughts.
- error: An error if the research process fails to start.
type StreamingResearchState ¶
type StreamingResearchState struct {
OriginalQuery string `json:"original_query"` // The user's original query.
CurrentIteration int `json:"current_iteration"` // The current iteration number, starting from 0.
MaxIterations int `json:"max_iterations"` // The maximum number of allowed iterations.
ResearchQuestions []*ResearchQuestion `json:"research_questions"` // List of all generated research questions.
ResearchedQuestions map[string]bool `json:"researched_questions"` // A map to track researched questions for deduplication.
CurrentResearchQ *ResearchQuestion `json:"current_research_q"` // The question currently being researched.
AccumulatedInfo string `json:"accumulated_info"` // Accumulated research information (reserved field).
FinalAnswer string `json:"final_answer"` // The final answer synthesized from all research findings.
IsComplete bool `json:"is_complete"` // Indicates if the entire research process is complete.
CompletedQuestions int `json:"completed_questions"` // The number of completed research questions.
ThoughtChannel chan *StreamingThought `json:"-"` // Channel for transmitting streaming thoughts (not serialized to JSON).
}
StreamingResearchState maintains the state of the entire research process, supporting multiple iterations and complex control flow.
type StreamingThought ¶
type StreamingThought struct {
Timestamp time.Time `json:"timestamp"` // Timestamp of when the thought was generated.
Stage string `json:"stage"` // Current stage: thinking, searching, analyzing, synthesizing.
Content string `json:"content"` // The specific content of the thought or analysis result.
Action Action `json:"action"` // The action currently being executed.
IsComplete bool `json:"is_complete"` // Indicates if the entire research process is complete.
Sources []string `json:"sources"` // List of source URLs for traceability.
}
StreamingThought represents a single thought or piece of information streamed during the research process. It provides real-time updates on the agent's state and actions.