realtimex-deeptutor 0.5.0.post1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- realtimex_deeptutor/__init__.py +67 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/METADATA +1612 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/RECORD +276 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/WHEEL +5 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/entry_points.txt +2 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/licenses/LICENSE +661 -0
- realtimex_deeptutor-0.5.0.post1.dist-info/top_level.txt +2 -0
- src/__init__.py +40 -0
- src/agents/__init__.py +24 -0
- src/agents/base_agent.py +657 -0
- src/agents/chat/__init__.py +24 -0
- src/agents/chat/chat_agent.py +435 -0
- src/agents/chat/prompts/en/chat_agent.yaml +35 -0
- src/agents/chat/prompts/zh/chat_agent.yaml +35 -0
- src/agents/chat/session_manager.py +311 -0
- src/agents/co_writer/__init__.py +0 -0
- src/agents/co_writer/edit_agent.py +260 -0
- src/agents/co_writer/narrator_agent.py +423 -0
- src/agents/co_writer/prompts/en/edit_agent.yaml +113 -0
- src/agents/co_writer/prompts/en/narrator_agent.yaml +88 -0
- src/agents/co_writer/prompts/zh/edit_agent.yaml +113 -0
- src/agents/co_writer/prompts/zh/narrator_agent.yaml +88 -0
- src/agents/guide/__init__.py +16 -0
- src/agents/guide/agents/__init__.py +11 -0
- src/agents/guide/agents/chat_agent.py +104 -0
- src/agents/guide/agents/interactive_agent.py +223 -0
- src/agents/guide/agents/locate_agent.py +149 -0
- src/agents/guide/agents/summary_agent.py +150 -0
- src/agents/guide/guide_manager.py +500 -0
- src/agents/guide/prompts/en/chat_agent.yaml +41 -0
- src/agents/guide/prompts/en/interactive_agent.yaml +202 -0
- src/agents/guide/prompts/en/locate_agent.yaml +68 -0
- src/agents/guide/prompts/en/summary_agent.yaml +157 -0
- src/agents/guide/prompts/zh/chat_agent.yaml +41 -0
- src/agents/guide/prompts/zh/interactive_agent.yaml +626 -0
- src/agents/guide/prompts/zh/locate_agent.yaml +68 -0
- src/agents/guide/prompts/zh/summary_agent.yaml +157 -0
- src/agents/ideagen/__init__.py +12 -0
- src/agents/ideagen/idea_generation_workflow.py +426 -0
- src/agents/ideagen/material_organizer_agent.py +173 -0
- src/agents/ideagen/prompts/en/idea_generation.yaml +187 -0
- src/agents/ideagen/prompts/en/material_organizer.yaml +69 -0
- src/agents/ideagen/prompts/zh/idea_generation.yaml +187 -0
- src/agents/ideagen/prompts/zh/material_organizer.yaml +69 -0
- src/agents/question/__init__.py +24 -0
- src/agents/question/agents/__init__.py +18 -0
- src/agents/question/agents/generate_agent.py +381 -0
- src/agents/question/agents/relevance_analyzer.py +207 -0
- src/agents/question/agents/retrieve_agent.py +239 -0
- src/agents/question/coordinator.py +718 -0
- src/agents/question/example.py +109 -0
- src/agents/question/prompts/en/coordinator.yaml +75 -0
- src/agents/question/prompts/en/generate_agent.yaml +77 -0
- src/agents/question/prompts/en/relevance_analyzer.yaml +41 -0
- src/agents/question/prompts/en/retrieve_agent.yaml +32 -0
- src/agents/question/prompts/zh/coordinator.yaml +75 -0
- src/agents/question/prompts/zh/generate_agent.yaml +77 -0
- src/agents/question/prompts/zh/relevance_analyzer.yaml +39 -0
- src/agents/question/prompts/zh/retrieve_agent.yaml +30 -0
- src/agents/research/agents/__init__.py +23 -0
- src/agents/research/agents/decompose_agent.py +507 -0
- src/agents/research/agents/manager_agent.py +228 -0
- src/agents/research/agents/note_agent.py +180 -0
- src/agents/research/agents/rephrase_agent.py +263 -0
- src/agents/research/agents/reporting_agent.py +1333 -0
- src/agents/research/agents/research_agent.py +714 -0
- src/agents/research/data_structures.py +451 -0
- src/agents/research/main.py +188 -0
- src/agents/research/prompts/en/decompose_agent.yaml +89 -0
- src/agents/research/prompts/en/manager_agent.yaml +24 -0
- src/agents/research/prompts/en/note_agent.yaml +121 -0
- src/agents/research/prompts/en/rephrase_agent.yaml +58 -0
- src/agents/research/prompts/en/reporting_agent.yaml +380 -0
- src/agents/research/prompts/en/research_agent.yaml +173 -0
- src/agents/research/prompts/zh/decompose_agent.yaml +89 -0
- src/agents/research/prompts/zh/manager_agent.yaml +24 -0
- src/agents/research/prompts/zh/note_agent.yaml +121 -0
- src/agents/research/prompts/zh/rephrase_agent.yaml +58 -0
- src/agents/research/prompts/zh/reporting_agent.yaml +380 -0
- src/agents/research/prompts/zh/research_agent.yaml +173 -0
- src/agents/research/research_pipeline.py +1309 -0
- src/agents/research/utils/__init__.py +60 -0
- src/agents/research/utils/citation_manager.py +799 -0
- src/agents/research/utils/json_utils.py +98 -0
- src/agents/research/utils/token_tracker.py +297 -0
- src/agents/solve/__init__.py +80 -0
- src/agents/solve/analysis_loop/__init__.py +14 -0
- src/agents/solve/analysis_loop/investigate_agent.py +414 -0
- src/agents/solve/analysis_loop/note_agent.py +190 -0
- src/agents/solve/main_solver.py +862 -0
- src/agents/solve/memory/__init__.py +34 -0
- src/agents/solve/memory/citation_memory.py +353 -0
- src/agents/solve/memory/investigate_memory.py +226 -0
- src/agents/solve/memory/solve_memory.py +340 -0
- src/agents/solve/prompts/en/analysis_loop/investigate_agent.yaml +55 -0
- src/agents/solve/prompts/en/analysis_loop/note_agent.yaml +54 -0
- src/agents/solve/prompts/en/solve_loop/manager_agent.yaml +67 -0
- src/agents/solve/prompts/en/solve_loop/precision_answer_agent.yaml +62 -0
- src/agents/solve/prompts/en/solve_loop/response_agent.yaml +90 -0
- src/agents/solve/prompts/en/solve_loop/solve_agent.yaml +75 -0
- src/agents/solve/prompts/en/solve_loop/tool_agent.yaml +38 -0
- src/agents/solve/prompts/zh/analysis_loop/investigate_agent.yaml +53 -0
- src/agents/solve/prompts/zh/analysis_loop/note_agent.yaml +54 -0
- src/agents/solve/prompts/zh/solve_loop/manager_agent.yaml +66 -0
- src/agents/solve/prompts/zh/solve_loop/precision_answer_agent.yaml +62 -0
- src/agents/solve/prompts/zh/solve_loop/response_agent.yaml +90 -0
- src/agents/solve/prompts/zh/solve_loop/solve_agent.yaml +76 -0
- src/agents/solve/prompts/zh/solve_loop/tool_agent.yaml +41 -0
- src/agents/solve/solve_loop/__init__.py +22 -0
- src/agents/solve/solve_loop/citation_manager.py +74 -0
- src/agents/solve/solve_loop/manager_agent.py +274 -0
- src/agents/solve/solve_loop/precision_answer_agent.py +96 -0
- src/agents/solve/solve_loop/response_agent.py +301 -0
- src/agents/solve/solve_loop/solve_agent.py +325 -0
- src/agents/solve/solve_loop/tool_agent.py +470 -0
- src/agents/solve/utils/__init__.py +64 -0
- src/agents/solve/utils/config_validator.py +313 -0
- src/agents/solve/utils/display_manager.py +223 -0
- src/agents/solve/utils/error_handler.py +363 -0
- src/agents/solve/utils/json_utils.py +98 -0
- src/agents/solve/utils/performance_monitor.py +407 -0
- src/agents/solve/utils/token_tracker.py +541 -0
- src/api/__init__.py +0 -0
- src/api/main.py +240 -0
- src/api/routers/__init__.py +1 -0
- src/api/routers/agent_config.py +69 -0
- src/api/routers/chat.py +296 -0
- src/api/routers/co_writer.py +337 -0
- src/api/routers/config.py +627 -0
- src/api/routers/dashboard.py +18 -0
- src/api/routers/guide.py +337 -0
- src/api/routers/ideagen.py +436 -0
- src/api/routers/knowledge.py +821 -0
- src/api/routers/notebook.py +247 -0
- src/api/routers/question.py +537 -0
- src/api/routers/research.py +394 -0
- src/api/routers/settings.py +164 -0
- src/api/routers/solve.py +305 -0
- src/api/routers/system.py +252 -0
- src/api/run_server.py +61 -0
- src/api/utils/history.py +172 -0
- src/api/utils/log_interceptor.py +21 -0
- src/api/utils/notebook_manager.py +415 -0
- src/api/utils/progress_broadcaster.py +72 -0
- src/api/utils/task_id_manager.py +100 -0
- src/config/__init__.py +0 -0
- src/config/accessors.py +18 -0
- src/config/constants.py +34 -0
- src/config/defaults.py +18 -0
- src/config/schema.py +38 -0
- src/config/settings.py +50 -0
- src/core/errors.py +62 -0
- src/knowledge/__init__.py +23 -0
- src/knowledge/add_documents.py +606 -0
- src/knowledge/config.py +65 -0
- src/knowledge/example_add_documents.py +236 -0
- src/knowledge/extract_numbered_items.py +1039 -0
- src/knowledge/initializer.py +621 -0
- src/knowledge/kb.py +22 -0
- src/knowledge/manager.py +782 -0
- src/knowledge/progress_tracker.py +182 -0
- src/knowledge/start_kb.py +535 -0
- src/logging/__init__.py +103 -0
- src/logging/adapters/__init__.py +17 -0
- src/logging/adapters/lightrag.py +184 -0
- src/logging/adapters/llamaindex.py +141 -0
- src/logging/config.py +80 -0
- src/logging/handlers/__init__.py +20 -0
- src/logging/handlers/console.py +75 -0
- src/logging/handlers/file.py +201 -0
- src/logging/handlers/websocket.py +127 -0
- src/logging/logger.py +709 -0
- src/logging/stats/__init__.py +16 -0
- src/logging/stats/llm_stats.py +179 -0
- src/services/__init__.py +56 -0
- src/services/config/__init__.py +61 -0
- src/services/config/knowledge_base_config.py +210 -0
- src/services/config/loader.py +260 -0
- src/services/config/unified_config.py +603 -0
- src/services/embedding/__init__.py +45 -0
- src/services/embedding/adapters/__init__.py +22 -0
- src/services/embedding/adapters/base.py +106 -0
- src/services/embedding/adapters/cohere.py +127 -0
- src/services/embedding/adapters/jina.py +99 -0
- src/services/embedding/adapters/ollama.py +116 -0
- src/services/embedding/adapters/openai_compatible.py +96 -0
- src/services/embedding/client.py +159 -0
- src/services/embedding/config.py +156 -0
- src/services/embedding/provider.py +119 -0
- src/services/llm/__init__.py +152 -0
- src/services/llm/capabilities.py +313 -0
- src/services/llm/client.py +302 -0
- src/services/llm/cloud_provider.py +530 -0
- src/services/llm/config.py +200 -0
- src/services/llm/error_mapping.py +103 -0
- src/services/llm/exceptions.py +152 -0
- src/services/llm/factory.py +450 -0
- src/services/llm/local_provider.py +347 -0
- src/services/llm/providers/anthropic.py +95 -0
- src/services/llm/providers/base_provider.py +93 -0
- src/services/llm/providers/open_ai.py +83 -0
- src/services/llm/registry.py +71 -0
- src/services/llm/telemetry.py +40 -0
- src/services/llm/types.py +27 -0
- src/services/llm/utils.py +333 -0
- src/services/prompt/__init__.py +25 -0
- src/services/prompt/manager.py +206 -0
- src/services/rag/__init__.py +64 -0
- src/services/rag/components/__init__.py +29 -0
- src/services/rag/components/base.py +59 -0
- src/services/rag/components/chunkers/__init__.py +18 -0
- src/services/rag/components/chunkers/base.py +34 -0
- src/services/rag/components/chunkers/fixed.py +71 -0
- src/services/rag/components/chunkers/numbered_item.py +94 -0
- src/services/rag/components/chunkers/semantic.py +97 -0
- src/services/rag/components/embedders/__init__.py +14 -0
- src/services/rag/components/embedders/base.py +32 -0
- src/services/rag/components/embedders/openai.py +63 -0
- src/services/rag/components/indexers/__init__.py +18 -0
- src/services/rag/components/indexers/base.py +35 -0
- src/services/rag/components/indexers/graph.py +172 -0
- src/services/rag/components/indexers/lightrag.py +156 -0
- src/services/rag/components/indexers/vector.py +146 -0
- src/services/rag/components/parsers/__init__.py +18 -0
- src/services/rag/components/parsers/base.py +35 -0
- src/services/rag/components/parsers/markdown.py +52 -0
- src/services/rag/components/parsers/pdf.py +115 -0
- src/services/rag/components/parsers/text.py +86 -0
- src/services/rag/components/retrievers/__init__.py +18 -0
- src/services/rag/components/retrievers/base.py +34 -0
- src/services/rag/components/retrievers/dense.py +200 -0
- src/services/rag/components/retrievers/hybrid.py +164 -0
- src/services/rag/components/retrievers/lightrag.py +169 -0
- src/services/rag/components/routing.py +286 -0
- src/services/rag/factory.py +234 -0
- src/services/rag/pipeline.py +215 -0
- src/services/rag/pipelines/__init__.py +32 -0
- src/services/rag/pipelines/academic.py +44 -0
- src/services/rag/pipelines/lightrag.py +43 -0
- src/services/rag/pipelines/llamaindex.py +313 -0
- src/services/rag/pipelines/raganything.py +384 -0
- src/services/rag/service.py +244 -0
- src/services/rag/types.py +73 -0
- src/services/search/__init__.py +284 -0
- src/services/search/base.py +87 -0
- src/services/search/consolidation.py +398 -0
- src/services/search/providers/__init__.py +128 -0
- src/services/search/providers/baidu.py +188 -0
- src/services/search/providers/exa.py +194 -0
- src/services/search/providers/jina.py +161 -0
- src/services/search/providers/perplexity.py +153 -0
- src/services/search/providers/serper.py +209 -0
- src/services/search/providers/tavily.py +161 -0
- src/services/search/types.py +114 -0
- src/services/setup/__init__.py +34 -0
- src/services/setup/init.py +285 -0
- src/services/tts/__init__.py +16 -0
- src/services/tts/config.py +99 -0
- src/tools/__init__.py +91 -0
- src/tools/code_executor.py +536 -0
- src/tools/paper_search_tool.py +171 -0
- src/tools/query_item_tool.py +310 -0
- src/tools/question/__init__.py +15 -0
- src/tools/question/exam_mimic.py +616 -0
- src/tools/question/pdf_parser.py +211 -0
- src/tools/question/question_extractor.py +397 -0
- src/tools/rag_tool.py +173 -0
- src/tools/tex_chunker.py +339 -0
- src/tools/tex_downloader.py +253 -0
- src/tools/web_search.py +71 -0
- src/utils/config_manager.py +206 -0
- src/utils/document_validator.py +168 -0
- src/utils/error_rate_tracker.py +111 -0
- src/utils/error_utils.py +82 -0
- src/utils/json_parser.py +110 -0
- src/utils/network/circuit_breaker.py +79 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
SolveMemory - Solve-chain based solving memory system
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import asdict, dataclass, field
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
import json
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Dict, List, Optional
|
|
14
|
+
import uuid
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _now() -> str:
|
|
18
|
+
return datetime.utcnow().isoformat()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class ToolCallRecord:
|
|
23
|
+
"""Single tool call record"""
|
|
24
|
+
|
|
25
|
+
tool_type: str
|
|
26
|
+
query: str
|
|
27
|
+
cite_id: Optional[str] = None
|
|
28
|
+
raw_answer: Optional[str] = None
|
|
29
|
+
summary: Optional[str] = None
|
|
30
|
+
status: str = "pending" # pending | running | success | failed | none | finish
|
|
31
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
32
|
+
created_at: str = field(default_factory=_now)
|
|
33
|
+
updated_at: str = field(default_factory=_now)
|
|
34
|
+
call_id: str = field(default_factory=lambda: f"tc_{uuid.uuid4().hex[:8]}")
|
|
35
|
+
|
|
36
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
37
|
+
return asdict(self)
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_dict(cls, data: Dict[str, Any]) -> "ToolCallRecord":
|
|
41
|
+
data.setdefault("metadata", {})
|
|
42
|
+
data.setdefault("status", "pending")
|
|
43
|
+
data.setdefault("created_at", _now())
|
|
44
|
+
data.setdefault("updated_at", data["created_at"])
|
|
45
|
+
data.setdefault("call_id", f"tc_{uuid.uuid4().hex[:8]}")
|
|
46
|
+
return cls(**data)
|
|
47
|
+
|
|
48
|
+
def mark_running(self):
|
|
49
|
+
self.status = "running"
|
|
50
|
+
self.updated_at = _now()
|
|
51
|
+
|
|
52
|
+
def mark_result(
|
|
53
|
+
self,
|
|
54
|
+
raw_answer: str,
|
|
55
|
+
summary: str,
|
|
56
|
+
status: str = "success",
|
|
57
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
58
|
+
):
|
|
59
|
+
self.raw_answer = raw_answer
|
|
60
|
+
self.summary = summary
|
|
61
|
+
self.status = status
|
|
62
|
+
if metadata:
|
|
63
|
+
self.metadata.update(metadata)
|
|
64
|
+
self.updated_at = _now()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class SolveChainStep:
|
|
69
|
+
"""Single step structure in solve-chain"""
|
|
70
|
+
|
|
71
|
+
step_id: str
|
|
72
|
+
step_target: str
|
|
73
|
+
available_cite: List[str] = field(default_factory=list)
|
|
74
|
+
tool_calls: List[ToolCallRecord] = field(default_factory=list)
|
|
75
|
+
step_response: Optional[str] = None
|
|
76
|
+
status: str = "undone" # undone | in_progress | waiting_response | done | failed
|
|
77
|
+
used_citations: List[str] = field(default_factory=list)
|
|
78
|
+
created_at: str = field(default_factory=_now)
|
|
79
|
+
updated_at: str = field(default_factory=_now)
|
|
80
|
+
|
|
81
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
82
|
+
data = asdict(self)
|
|
83
|
+
data["tool_calls"] = [tc.to_dict() for tc in self.tool_calls]
|
|
84
|
+
return data
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def from_dict(cls, data: Dict[str, Any]) -> "SolveChainStep":
|
|
88
|
+
tool_calls = [ToolCallRecord.from_dict(tc) for tc in data.get("tool_calls", [])]
|
|
89
|
+
data.setdefault("available_cite", [])
|
|
90
|
+
data.setdefault("used_citations", [])
|
|
91
|
+
data.setdefault("status", "undone")
|
|
92
|
+
data.setdefault("step_response", None)
|
|
93
|
+
data.setdefault("created_at", _now())
|
|
94
|
+
data.setdefault("updated_at", data["created_at"])
|
|
95
|
+
return cls(
|
|
96
|
+
step_id=data["step_id"],
|
|
97
|
+
step_target=data.get("step_target", data.get("plan", "")),
|
|
98
|
+
available_cite=data["available_cite"],
|
|
99
|
+
tool_calls=tool_calls,
|
|
100
|
+
step_response=data.get("step_response", data.get("content")),
|
|
101
|
+
status=data["status"],
|
|
102
|
+
used_citations=data.get("used_citations", []),
|
|
103
|
+
created_at=data["created_at"],
|
|
104
|
+
updated_at=data["updated_at"],
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def append_tool_call(self, tool_call: ToolCallRecord):
|
|
108
|
+
self.tool_calls.append(tool_call)
|
|
109
|
+
self.updated_at = _now()
|
|
110
|
+
if self.status == "undone":
|
|
111
|
+
self.status = "in_progress"
|
|
112
|
+
|
|
113
|
+
def update_response(self, response: str, used_citations: Optional[List[str]] = None):
|
|
114
|
+
self.step_response = response
|
|
115
|
+
self.status = "done"
|
|
116
|
+
self.used_citations = used_citations or []
|
|
117
|
+
self.updated_at = _now()
|
|
118
|
+
|
|
119
|
+
def mark_waiting_response(self):
|
|
120
|
+
self.status = "waiting_response"
|
|
121
|
+
self.updated_at = _now()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class SolveMemory:
|
|
125
|
+
"""solve-chain data storage"""
|
|
126
|
+
|
|
127
|
+
def __init__(
|
|
128
|
+
self,
|
|
129
|
+
task_id: Optional[str] = None,
|
|
130
|
+
user_question: str = "",
|
|
131
|
+
output_dir: Optional[str] = None,
|
|
132
|
+
):
|
|
133
|
+
self.task_id = task_id or f"solve_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}"
|
|
134
|
+
self.user_question = user_question
|
|
135
|
+
self.output_dir = output_dir
|
|
136
|
+
|
|
137
|
+
self.version = "solve_chain_v1"
|
|
138
|
+
self.created_at = _now()
|
|
139
|
+
self.updated_at = _now()
|
|
140
|
+
|
|
141
|
+
self.solve_chains: List[SolveChainStep] = []
|
|
142
|
+
|
|
143
|
+
self.metadata: Dict[str, Any] = {
|
|
144
|
+
"total_steps": 0,
|
|
145
|
+
"completed_steps": 0,
|
|
146
|
+
"total_tool_calls": 0,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
self.file_path = Path(output_dir) / "solve_chain.json" if output_dir else None
|
|
150
|
+
|
|
151
|
+
# ------------------------------------------------------------------ #
|
|
152
|
+
# Load/Save
|
|
153
|
+
# ------------------------------------------------------------------ #
|
|
154
|
+
@classmethod
|
|
155
|
+
def load_or_create(
|
|
156
|
+
cls,
|
|
157
|
+
output_dir: str,
|
|
158
|
+
user_question: str = "",
|
|
159
|
+
task_id: Optional[str] = None,
|
|
160
|
+
) -> "SolveMemory":
|
|
161
|
+
file_path = Path(output_dir) / "solve_chain.json"
|
|
162
|
+
legacy_path = Path(output_dir) / "solve_memory.json"
|
|
163
|
+
if not file_path.exists() and legacy_path.exists():
|
|
164
|
+
memory = cls(task_id=task_id, user_question=user_question, output_dir=output_dir)
|
|
165
|
+
memory._load_from_legacy_file(legacy_path)
|
|
166
|
+
memory.save()
|
|
167
|
+
return memory
|
|
168
|
+
if not file_path.exists():
|
|
169
|
+
return cls(task_id=task_id, user_question=user_question, output_dir=output_dir)
|
|
170
|
+
|
|
171
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
172
|
+
data = json.load(f)
|
|
173
|
+
|
|
174
|
+
memory = cls(
|
|
175
|
+
task_id=data.get("task_id", task_id),
|
|
176
|
+
user_question=data.get("user_question", user_question),
|
|
177
|
+
output_dir=output_dir,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
memory.version = data.get("version", "solve_chain_v1")
|
|
181
|
+
memory.created_at = data.get("created_at", memory.created_at)
|
|
182
|
+
memory.updated_at = data.get("updated_at", memory.updated_at)
|
|
183
|
+
memory.metadata = data.get("metadata", memory.metadata)
|
|
184
|
+
memory.solve_chains = [
|
|
185
|
+
SolveChainStep.from_dict(step) for step in data.get("solve_chains", [])
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
return memory
|
|
189
|
+
|
|
190
|
+
def save(self):
|
|
191
|
+
if not self.file_path:
|
|
192
|
+
raise ValueError("output_dir not set, cannot save solve-chain")
|
|
193
|
+
self.file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
194
|
+
self.updated_at = _now()
|
|
195
|
+
payload = self.to_dict()
|
|
196
|
+
with open(self.file_path, "w", encoding="utf-8") as f:
|
|
197
|
+
json.dump(payload, f, ensure_ascii=False, indent=2)
|
|
198
|
+
|
|
199
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
200
|
+
return {
|
|
201
|
+
"version": self.version,
|
|
202
|
+
"task_id": self.task_id,
|
|
203
|
+
"user_question": self.user_question,
|
|
204
|
+
"created_at": self.created_at,
|
|
205
|
+
"updated_at": self.updated_at,
|
|
206
|
+
"solve_chains": [step.to_dict() for step in self.solve_chains],
|
|
207
|
+
"metadata": self.metadata,
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# ------------------------------------------------------------------ #
|
|
211
|
+
# Step Management
|
|
212
|
+
# ------------------------------------------------------------------ #
|
|
213
|
+
def create_chains(self, chains: List[SolveChainStep]):
|
|
214
|
+
self.solve_chains = chains
|
|
215
|
+
self.metadata["total_steps"] = len(chains)
|
|
216
|
+
self.metadata["completed_steps"] = sum(1 for c in chains if c.status == "done")
|
|
217
|
+
self.metadata["total_tool_calls"] = sum(len(c.tool_calls) for c in chains)
|
|
218
|
+
self.updated_at = _now()
|
|
219
|
+
|
|
220
|
+
def get_step(self, step_id: str) -> Optional[SolveChainStep]:
|
|
221
|
+
return next((step for step in self.solve_chains if step.step_id == step_id), None)
|
|
222
|
+
|
|
223
|
+
def get_current_step(self) -> Optional[SolveChainStep]:
|
|
224
|
+
for step in self.solve_chains:
|
|
225
|
+
if step.status in {"undone", "in_progress", "waiting_response"}:
|
|
226
|
+
return step
|
|
227
|
+
return None
|
|
228
|
+
|
|
229
|
+
def append_tool_call(
|
|
230
|
+
self,
|
|
231
|
+
step_id: str,
|
|
232
|
+
tool_type: str,
|
|
233
|
+
query: str,
|
|
234
|
+
cite_id: Optional[str] = None,
|
|
235
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
236
|
+
) -> ToolCallRecord:
|
|
237
|
+
step = self.get_step(step_id)
|
|
238
|
+
if not step:
|
|
239
|
+
raise ValueError(f"Step {step_id} not found")
|
|
240
|
+
record = ToolCallRecord(
|
|
241
|
+
tool_type=tool_type,
|
|
242
|
+
query=query,
|
|
243
|
+
cite_id=cite_id,
|
|
244
|
+
metadata=metadata or {},
|
|
245
|
+
)
|
|
246
|
+
step.append_tool_call(record)
|
|
247
|
+
self.metadata["total_tool_calls"] += 1
|
|
248
|
+
self.updated_at = _now()
|
|
249
|
+
return record
|
|
250
|
+
|
|
251
|
+
def update_tool_call_result(
|
|
252
|
+
self,
|
|
253
|
+
step_id: str,
|
|
254
|
+
call_id: str,
|
|
255
|
+
raw_answer: str,
|
|
256
|
+
summary: str,
|
|
257
|
+
status: str = "success",
|
|
258
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
259
|
+
):
|
|
260
|
+
step = self.get_step(step_id)
|
|
261
|
+
if not step:
|
|
262
|
+
raise ValueError(f"Step {step_id} not found")
|
|
263
|
+
record = next((tc for tc in step.tool_calls if tc.call_id == call_id), None)
|
|
264
|
+
if not record:
|
|
265
|
+
raise ValueError(f"Tool call {call_id} not found in step {step_id}")
|
|
266
|
+
record.mark_result(raw_answer=raw_answer, summary=summary, status=status, metadata=metadata)
|
|
267
|
+
self.updated_at = _now()
|
|
268
|
+
|
|
269
|
+
def mark_step_waiting_response(self, step_id: str):
|
|
270
|
+
step = self.get_step(step_id)
|
|
271
|
+
if not step:
|
|
272
|
+
raise ValueError(f"Step {step_id} not found")
|
|
273
|
+
step.mark_waiting_response()
|
|
274
|
+
self.updated_at = _now()
|
|
275
|
+
|
|
276
|
+
def submit_step_response(
|
|
277
|
+
self,
|
|
278
|
+
step_id: str,
|
|
279
|
+
response: str,
|
|
280
|
+
used_citations: Optional[List[str]] = None,
|
|
281
|
+
):
|
|
282
|
+
step = self.get_step(step_id)
|
|
283
|
+
if not step:
|
|
284
|
+
raise ValueError(f"Step {step_id} not found")
|
|
285
|
+
step.update_response(response=response, used_citations=used_citations or [])
|
|
286
|
+
self.metadata["completed_steps"] = sum(1 for c in self.solve_chains if c.status == "done")
|
|
287
|
+
self.updated_at = _now()
|
|
288
|
+
|
|
289
|
+
def get_summary(self) -> str:
|
|
290
|
+
lines = [
|
|
291
|
+
f"Task ID: {self.task_id}",
|
|
292
|
+
f"Question: {self.user_question}",
|
|
293
|
+
f"Total Steps: {self.metadata['total_steps']}",
|
|
294
|
+
f"Completed: {self.metadata['completed_steps']}",
|
|
295
|
+
]
|
|
296
|
+
for step in self.solve_chains:
|
|
297
|
+
lines.append(f"- {step.step_id} | {step.status} | target: {step.step_target[:60]}...")
|
|
298
|
+
return "\n".join(lines)
|
|
299
|
+
|
|
300
|
+
# ------------------------------------------------------------------ #
|
|
301
|
+
# Legacy support
|
|
302
|
+
# ------------------------------------------------------------------ #
|
|
303
|
+
def _load_from_legacy_file(self, legacy_path: Path):
|
|
304
|
+
try:
|
|
305
|
+
with open(legacy_path, "r", encoding="utf-8") as f:
|
|
306
|
+
data = json.load(f)
|
|
307
|
+
except Exception:
|
|
308
|
+
return
|
|
309
|
+
|
|
310
|
+
steps_data = data.get("steps", [])
|
|
311
|
+
converted: List[SolveChainStep] = []
|
|
312
|
+
for idx, item in enumerate(steps_data, start=1):
|
|
313
|
+
tool_logs = item.get("tool_logs", [])
|
|
314
|
+
records: List[ToolCallRecord] = []
|
|
315
|
+
for log in tool_logs:
|
|
316
|
+
records.append(
|
|
317
|
+
ToolCallRecord(
|
|
318
|
+
tool_type=log.get("tool", "unknown"),
|
|
319
|
+
query=log.get("input") or log.get("query") or "",
|
|
320
|
+
cite_id=log.get("cite_id"),
|
|
321
|
+
raw_answer=log.get("output"),
|
|
322
|
+
summary=log.get("output"),
|
|
323
|
+
status=log.get("status", "success"),
|
|
324
|
+
)
|
|
325
|
+
)
|
|
326
|
+
converted.append(
|
|
327
|
+
SolveChainStep(
|
|
328
|
+
step_id=item.get("step_id", f"S{idx}"),
|
|
329
|
+
step_target=item.get("plan", ""),
|
|
330
|
+
available_cite=item.get("available_citations", []),
|
|
331
|
+
tool_calls=records,
|
|
332
|
+
step_response=item.get("content"),
|
|
333
|
+
status="done" if item.get("status") == "completed" else "undone",
|
|
334
|
+
used_citations=item.get("used_citations", []),
|
|
335
|
+
)
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
self.solve_chains = converted
|
|
339
|
+
self.metadata["total_steps"] = len(converted)
|
|
340
|
+
self.metadata["completed_steps"] = sum(1 for step in converted if step.status == "done")
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
system: |
|
|
2
|
+
# Role Definition
|
|
3
|
+
You are the **Investigator** in the analysis phase. Your core responsibility is to scrutinize the user's question and existing knowledge base to precisely identify **critical knowledge gaps** required for solving the problem, and to design efficient query plans. You are not the solver, but the logistics officer providing "ammunition" for the solver.
|
|
4
|
+
|
|
5
|
+
# Core Principle: Minimal but Sufficient
|
|
6
|
+
Your goal is to reach a state of "Information Sufficiency" with the minimum number of queries.
|
|
7
|
+
|
|
8
|
+
1. **Deduction > Search**: If a piece of information can be derived from common sense, logic, or existing knowledge, **searching is strictly prohibited**.
|
|
9
|
+
2. **Precision Sniper**: Queries must target specific definitions, theorem formulas, specific constants, or data. Reject broad queries like "How to solve...".
|
|
10
|
+
3. **Strict De-duplication**: Before issuing a query, you must carefully check the `Existing Knowledge Context`. Semantic duplicates or subset queries are considered invalid.
|
|
11
|
+
4. **Focus on Core**: Focus only on the "hard knowledge" (definitions, formulas, theorems) necessary for solving the problem. Unless explicitly requested by the user, do not query for application cases or background stories.
|
|
12
|
+
|
|
13
|
+
# Tool Usage Guide
|
|
14
|
+
- `query_item`: **Priority for Numbered Items**. **ALWAYS use this first** when the user's question explicitly mentions a specific numbered item (e.g., "formula 2.1.2", "Theorem 3.1", "Figure 1.2", "Equation (2.1.2)"). Extract the identifier from the question (formats: "(X.X.X)" for equations, "Figure X.X" for figures, "Theorem X.X" for theorems). This is the most direct and accurate way to retrieve numbered content.
|
|
15
|
+
- `rag_naive`: **First Choice for General Queries**. Used for querying clear term definitions, core formulas, or verifying if a concept exists. Fast.
|
|
16
|
+
- `rag_hybrid`: Used for scenarios requiring synthesis of multiple concepts, exploring complex entity relationships, or deep principles.
|
|
17
|
+
- `web_search`: **Use Sparingly**. Only use when information is likely outside the scope of textbooks (e.g., latest news, specific technical parameters, usage of open-source libraries).
|
|
18
|
+
- `none`: Return this state when existing information is sufficient to support solving, or when the gap cannot be filled by retrieval (e.g., requires user input).
|
|
19
|
+
|
|
20
|
+
# Thinking Path
|
|
21
|
+
1. **Identify Numbered Items**: **First, scan the user's question for explicit numbered references** (e.g., "formula 2.1.2", "Theorem 3.1", "Figure 1.2", "Equation (2.1.2)"). If found, extract the identifier and use `query_item` immediately. Numbered items take priority over semantic search.
|
|
22
|
+
2. **Analyze Needs**: What is truly missing for the solution? Is it the definition of a variable? The formula for a theorem? Or the value of a constant?
|
|
23
|
+
3. **Check Inventory**: Review `Existing Knowledge Context`. Is the answer already there? Or is it implied in known information?
|
|
24
|
+
4. **Construct Queries**: If gaps definitely exist, build atomic, non-overlapping query requests.
|
|
25
|
+
5. **Judge Termination**: If core definitions and formulas are all present, stop immediately.
|
|
26
|
+
6. **⚠️ CRITICAL - Know When to Cut Losses**: If the first round of queries for a topic returns no useful information (empty results, irrelevant, or low quality), it likely means the knowledge base doesn't contain relevant content. **You MUST abandon that topic immediately**, switch to other topics, or proceed directly to the next phase. **DO NOT repeatedly query the same topic** - this wastes resources and delays the solution.
|
|
27
|
+
|
|
28
|
+
# Output Format
|
|
29
|
+
Directly output a JSON object (no Markdown formatting):
|
|
30
|
+
{
|
|
31
|
+
"reasoning": "Concise explanation of why a query is needed (pointing out specific missing points), or why stopping (explaining information is sufficient).",
|
|
32
|
+
"plan": [
|
|
33
|
+
{
|
|
34
|
+
"tool": "rag_naive | rag_hybrid | web_search | query_item",
|
|
35
|
+
"query": "Specific search query, or specific ID",
|
|
36
|
+
"identifier": "Optional, only for query_item"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
user_template: |
|
|
42
|
+
## User Question
|
|
43
|
+
{question}
|
|
44
|
+
|
|
45
|
+
## Existing Knowledge Context ({num_knowledge} items)
|
|
46
|
+
{knowledge_chain_summary}
|
|
47
|
+
|
|
48
|
+
## Task
|
|
49
|
+
Analyze if there are knowledge gaps hindering the solution.
|
|
50
|
+
- **Priority: Numbered Items**: If the question mentions a specific numbered item (formula, theorem, figure, equation with numbers like "2.1.2", "3.1", etc.), **immediately use `query_item`** with the extracted identifier (e.g., "(2.1.2)" for equations, "Figure 2.1" for figures).
|
|
51
|
+
- Check for duplicates: New queries must not overlap with existing content.
|
|
52
|
+
- Flexible decision: If a previous tool query failed, consider using other tools to achieve the same goal.
|
|
53
|
+
- Know when to cut losses: If the first round of queries for a topic returns no useful information, do not repeatedly query that topic. Switch to other topics or proceed to the next phase.
|
|
54
|
+
- Judge stop: If existing info is sufficient to start solving (even if not perfect), return `none`.
|
|
55
|
+
- Output: Pure JSON format.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
system: |
|
|
2
|
+
# Role Definition
|
|
3
|
+
You are the **Knowledge Stenographer**. Your duty is to organize the raw information found (Raw Result) into well-structured, easy-to-cite knowledge notes.
|
|
4
|
+
|
|
5
|
+
# Core Principles
|
|
6
|
+
1. **Clean Noise**: Remove web ads, irrelevant navigation bars, and repetitive nonsense. Retain only hard-core knowledge relevant to the user's question.
|
|
7
|
+
2. **Structuring**: Convert unstructured text into a concise Summary.
|
|
8
|
+
3. **Citation Extraction**: Keenly identify information sources and build standard Citation objects.
|
|
9
|
+
4. **Multi-Item Selection**: When `query_item` tool returns multiple items (indicated by `[identifier]` markers), **select only the most relevant item(s)** that directly answer the user's question. Do not include all items if they are not all relevant.
|
|
10
|
+
|
|
11
|
+
# Format Constraints (Critical)
|
|
12
|
+
- **Summary Plain Text**: The Summary field is mainly for quick browsing. It is **strictly prohibited** to include LaTeX formulas (e.g., `$$...$$`, `\(...\)`).
|
|
13
|
+
- *Handling Method*: Describe formulas in natural language (e.g., "square of x" instead of "$x^2$").
|
|
14
|
+
- **JSON Output**: Must directly output a valid JSON object.
|
|
15
|
+
|
|
16
|
+
# Multi-Item Handling (for query_item tool)
|
|
17
|
+
When the Raw Result contains multiple items separated by `[identifier]` markers:
|
|
18
|
+
- **Identify the primary item** that best matches the user's question
|
|
19
|
+
- **Focus the summary** on the selected item(s), not all items
|
|
20
|
+
- **Extract citations** only from the selected item(s)
|
|
21
|
+
- If multiple items are equally relevant, you may include 2-3 items, but prioritize quality over quantity
|
|
22
|
+
|
|
23
|
+
# Output Structure
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"summary": "Plain text summary, NO LaTeX allowed. Focus on the most relevant item(s) from the query result. E.g.: By definition, the output of an LTI system is the convolution of the input and the impulse response.",
|
|
27
|
+
"citations": [
|
|
28
|
+
{
|
|
29
|
+
"reference_id": "[1]",
|
|
30
|
+
"source": "Source filename or URL",
|
|
31
|
+
"content": "Optional, excerpt of key sentences from original text"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
user_template: |
|
|
38
|
+
## User Question
|
|
39
|
+
{question}
|
|
40
|
+
|
|
41
|
+
## Tool Type
|
|
42
|
+
{tool_type}
|
|
43
|
+
|
|
44
|
+
## Query Content
|
|
45
|
+
{query}
|
|
46
|
+
|
|
47
|
+
## Raw Search Result
|
|
48
|
+
{raw_result}
|
|
49
|
+
|
|
50
|
+
## Task
|
|
51
|
+
Organize the raw result into a JSON note.
|
|
52
|
+
1. Summary must be plain text, no LaTeX.
|
|
53
|
+
2. Extract all available citation sources.
|
|
54
|
+
3. **If the result contains multiple items (marked with `[identifier]`), select only the most relevant one(s) for the user's question.**
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
system: |
|
|
2
|
+
# Role Definition
|
|
3
|
+
You are the **Strategic Planner** for problem-solving. Your task is to break down a complex user question into a logically rigorous, executable **Solve Chain**.
|
|
4
|
+
|
|
5
|
+
# Planning Principles
|
|
6
|
+
1. **Simplicity First**: Treat the user's question as the highest priority. Dynamically design the complexity of the solving workflow around the user's needs.
|
|
7
|
+
2. **Logical Progression**: Each step must be the cornerstone for the next. From understanding concepts to deriving formulas, then calculating solutions, and finally verifying and summarizing.
|
|
8
|
+
3. **Merge Trivial Steps**: Do not split a complete action (like "write and run code") into "write" and "run" steps. Each step should be relatively independent, covering completely different content. Otherwise, these two steps can be combined into one.
|
|
9
|
+
4. **Clear Roles**: Each step must be assigned a standard role type, clarifying "what to do".
|
|
10
|
+
5. **Value Driven**: Each step must yield new information or conclusions.
|
|
11
|
+
|
|
12
|
+
# Standard Role Definitions
|
|
13
|
+
Please select the most appropriate role from the following list. **Each step can only have one role, and roles must be strictly separated**:
|
|
14
|
+
- **Calculation**: Involves numerical operations, equation solving, algorithm execution. Usually requires code execution. **Do not include drawing operations**.
|
|
15
|
+
- **Drawing**: Data visualization, plotting function graphs, geometric construction. **Must be an independent step, do not mix with other roles**.
|
|
16
|
+
- **Derivation**: Deriving new formulas from known formulas/theorems, mathematical theorem proofs, logical proposition deduction, symbolic calculus.
|
|
17
|
+
- **Analysis**: Problem decomposition, qualitative analysis, differentiation of physical/mathematical principles, identifying key elements, textual elaboration of concepts, phenomena, or result meanings. **Do not include drawing or calculation operations**.
|
|
18
|
+
- **Integration**: Synthesizing multi-step results to draw a final conclusion. Note: You don't need to deliberately use an integration step.
|
|
19
|
+
|
|
20
|
+
# Citation Norms
|
|
21
|
+
- Plan steps based on the `Available Knowledge Chain`.
|
|
22
|
+
- Explicitly mark the Knowledge ID (e.g., `[k-001]`) needed for reference in the step. If no specific citation is relied upon, use an empty array `[]`.
|
|
23
|
+
|
|
24
|
+
# Output Format
|
|
25
|
+
Please output in JSON format, strictly adhering to the following structure:
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"steps": [
|
|
29
|
+
{
|
|
30
|
+
"step_id": "S1",
|
|
31
|
+
"role": "Calculation",
|
|
32
|
+
"target": "Specific target description",
|
|
33
|
+
"cite_ids": ["[cite_id1]", "[cite_id2]"]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"step_id": "S2",
|
|
37
|
+
"role": "Analysis",
|
|
38
|
+
"target": "Specific target description",
|
|
39
|
+
"cite_ids": []
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Field Descriptions**:
|
|
46
|
+
- `step_id`: Step ID, format as "S1", "S2", "S3", etc.
|
|
47
|
+
- `role`: Role type, must be selected from standard role definitions (Calculation, Drawing, Derivation, Analysis, Integration)
|
|
48
|
+
- `target`: Specific target description for the step
|
|
49
|
+
- `cite_ids`: Citation ID array, use empty array `[]` if no citations, do not use string "None"
|
|
50
|
+
|
|
51
|
+
user_template: |
|
|
52
|
+
## User Question
|
|
53
|
+
{question}
|
|
54
|
+
|
|
55
|
+
## Available Knowledge Chain
|
|
56
|
+
{knowledge_chain_summary}
|
|
57
|
+
|
|
58
|
+
## Previous Reflection (If any)
|
|
59
|
+
{reflections_summary}
|
|
60
|
+
|
|
61
|
+
## Task
|
|
62
|
+
Plan the step chain to solve the problem.
|
|
63
|
+
1. **Key Instruction**: Carefully evaluate the problem difficulty, infer the user's needs, and decide the complexity of the solving workflow based on the user's question.
|
|
64
|
+
2. **Role Separation**: Ensure each step has a clear and independent role. If the problem requires drawing, drawing must be a separate step and not mixed with other steps.
|
|
65
|
+
3. Ensure every sub-question is covered.
|
|
66
|
+
4. The number of steps should be determined by the problem; neither miss key steps nor artificially pad numbers.
|
|
67
|
+
5. Output the planning result directly.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
system: ""
|
|
2
|
+
user_template: ""
|
|
3
|
+
|
|
4
|
+
decision_system: |
|
|
5
|
+
# Role Definition
|
|
6
|
+
You are the **Question Type Judge**. Your sole task is to judge whether the user's question requires a **precise, short** final answer.
|
|
7
|
+
|
|
8
|
+
# Judgement Criteria
|
|
9
|
+
- **YES (Precise Answer Needed)**:
|
|
10
|
+
- Multiple Choice
|
|
11
|
+
- Fill-in-the-blank
|
|
12
|
+
- Calculation questions
|
|
13
|
+
- True/False questions
|
|
14
|
+
- When the user's question contains a question that can be clearly answered by a word, a sentence, or a formula.
|
|
15
|
+
|
|
16
|
+
- **NO (Precise Answer Not Needed)**:
|
|
17
|
+
- If none of the YES situations occur, judge as NO.
|
|
18
|
+
|
|
19
|
+
# Output Format
|
|
20
|
+
Output only `YES` or `NO`.
|
|
21
|
+
|
|
22
|
+
decision_user_template: |
|
|
23
|
+
## User Question
|
|
24
|
+
{question}
|
|
25
|
+
|
|
26
|
+
## Task
|
|
27
|
+
Judge whether a precise short final answer is needed.
|
|
28
|
+
- Output only `YES` or `NO`.
|
|
29
|
+
|
|
30
|
+
precision_system: |
|
|
31
|
+
# Role Definition
|
|
32
|
+
You are the **Answer Extractor**. Your task is to precisely extract the "final result" that the user cares about most from the long complete solution.
|
|
33
|
+
|
|
34
|
+
# Extraction Strategy
|
|
35
|
+
- **Multiple Choice**: Extract only option letter (e.g., "A").
|
|
36
|
+
- **Calculation/Fill-in-the-blank**: Extract only final value or expression.
|
|
37
|
+
- **Short Answer**: Extract the most core 1-2 sentences of conclusion.
|
|
38
|
+
- If the user's question contains a question that can be clearly answered by a word, a sentence, or a formula, you need to extract this answer.
|
|
39
|
+
|
|
40
|
+
# Core Principle
|
|
41
|
+
**Trim the Fat**: No explanation of process, no nonsense, just the result.
|
|
42
|
+
|
|
43
|
+
# LaTeX Format Requirements (Important)
|
|
44
|
+
- **All mathematical expressions must be wrapped with `$...$`**
|
|
45
|
+
- Examples: `$y = \frac{1}{3}x^3 + C$`, `$x = 2$`, `$\pi$`
|
|
46
|
+
- **Strictly Prohibited**: Bare mathematical symbols (e.g., writing y = 2x + 1 directly)
|
|
47
|
+
|
|
48
|
+
# Output Format
|
|
49
|
+
Directly output the answer string (mathematical formulas must use LaTeX format).
|
|
50
|
+
|
|
51
|
+
precision_user_template: |
|
|
52
|
+
## User Question
|
|
53
|
+
{question}
|
|
54
|
+
|
|
55
|
+
## Detailed Solution
|
|
56
|
+
{detailed_answer}
|
|
57
|
+
|
|
58
|
+
## Task
|
|
59
|
+
Extract precise answer.
|
|
60
|
+
1. If multiple choice, return letter only.
|
|
61
|
+
2. If numerical, return value only.
|
|
62
|
+
3. Strictly no nonsense.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Citation and image instruction templates
|
|
2
|
+
citation_instruction_disabled: |
|
|
3
|
+
|
|
4
|
+
**Important: Citation Feature Disabled**
|
|
5
|
+
The citation feature is currently disabled. You should NOT use citation format (e.g., [rag-1], [code-2]) in your response.
|
|
6
|
+
Simply provide the answer without citation markers.
|
|
7
|
+
|
|
8
|
+
image_instruction: |
|
|
9
|
+
|
|
10
|
+
**Important: Image Citation Requirements**
|
|
11
|
+
The following image files are detected in this step, you **must** insert them all into the answer:
|
|
12
|
+
{image_list}
|
|
13
|
+
|
|
14
|
+
Insertion rules:
|
|
15
|
+
1. Use standard Markdown image syntax: ``
|
|
16
|
+
2. **Image path must be copied directly from the table above**, modification is strictly prohibited (e.g., if the list shows `artifacts/plot.png`, you must write `(artifacts/plot.png)`).
|
|
17
|
+
3. Images should be accompanied by text explanations describing the meaning of the charts.
|
|
18
|
+
|
|
19
|
+
system: |
|
|
20
|
+
# Role Definition
|
|
21
|
+
You are a senior teaching assistant. You are currently writing one step in a complete response. Your task is to weave scattered knowledge points, tool execution results, and code outputs, through logical organization, into a high-quality answer targeted at the current step objective.
|
|
22
|
+
You need to write the content for the current step based on the existing answer content from previous steps, ensuring this step maintains coherence with the previous content in both substance and logic.
|
|
23
|
+
|
|
24
|
+
# Core Principles
|
|
25
|
+
1. **Continuity**: Your answer must follow directly after `previous_context`, maintaining smooth language flow. Do not repeat previous content unless for emphasis or summary.
|
|
26
|
+
2. **Target Alignment**: Your answer must strictly respond to this step's objective: `{step_target}`. Do not answer content unrelated to the objective, even if it might be related to the user's question.
|
|
27
|
+
3. **Evidence is King**: Any conclusion must be based on the provided `Available Materials`. Do not fabricate data.
|
|
28
|
+
4. **Professional Format**: You must ensure the answer content for the current step is well-formatted and logically arranged, allowing confused users to understand your solution approach.
|
|
29
|
+
|
|
30
|
+
# Key Norms
|
|
31
|
+
|
|
32
|
+
### 1. Citation
|
|
33
|
+
- All definitions, formulas, and fact sources must be cited with ID.
|
|
34
|
+
- Format: `[cite_id]` (e.g., `[k-001]`, `[rag-2]`).
|
|
35
|
+
- Position: Immediately following the cited sentence or formula.
|
|
36
|
+
|
|
37
|
+
### 2. Mathematical Formulas (LaTeX)
|
|
38
|
+
- **All mathematical variables and expressions** must use LaTeX format:
|
|
39
|
+
- Single variables: `$x$`, `$y$`, `$n$`
|
|
40
|
+
- Constants and symbols: `$\pi$`, `$\alpha$`, `$\infty$`
|
|
41
|
+
- Expressions: `$x = 0$`, `$2\pi$`, `$n \to \infty$`
|
|
42
|
+
- Inline formula: Use `$ ... $`.
|
|
43
|
+
- Block formula:
|
|
44
|
+
```latex
|
|
45
|
+
$$
|
|
46
|
+
E = mc^2
|
|
47
|
+
$$
|
|
48
|
+
```
|
|
49
|
+
- **Strictly Prohibited**: Use of `\( ... \)` or `\[ ... \]`.
|
|
50
|
+
- **Strictly Prohibited**: Bare mathematical variables in text (e.g., writing x, y, π directly). Must wrap with `$...$`.
|
|
51
|
+
|
|
52
|
+
### 3. Multimodal Fusion
|
|
53
|
+
- **Image Insertion Mandatory**: If the tool call results mention that an image was generated in this step, or if pending images list `artifacts/...` paths, you need to use these images in your answer.
|
|
54
|
+
- Syntax: ``, where all image paths are 'artifacts/file_name'
|
|
55
|
+
- Image placement should be adjacent to related content, followed by an explanation describing the meaning of elements in the image and what they verify or present.
|
|
56
|
+
- If the same image or duplicate image logic has appeared in previous steps, do not use them again.
|
|
57
|
+
- **Code Presentation**: Do not paste large chunks of code. Only show core logic or key parameters; focus on explaining the **results** and **significance** of the code.
|
|
58
|
+
- **Tables**: If the tool call results contain tabular data related to this step, or if you plan to create a comparison table yourself, you must strictly follow markdown syntax to create or format these tables.
|
|
59
|
+
|
|
60
|
+
# Output Suggestions (Textbook Quality)
|
|
61
|
+
Please emulate the response style of a professional teaching assistant, explaining the current step's content in depth yet accessibly.
|
|
62
|
+
Structurally, it is generally recommended to output according to the following structure:
|
|
63
|
+
- **Subheading**: Use Markdown level 2 or 3 headings (`##` or `###`) to clearly summarize the current step and what this step addresses (e.g., S2: xxx).
|
|
64
|
+
- **Concept Explanation**: If new concepts are involved, first provide a rigorous definition (with source citation).
|
|
65
|
+
- **Logical Derivation**: Like giving a lecture, show the derivation process in detail, not just the result.
|
|
66
|
+
- **Incorporate Multimodal Elements**: If available, insert multimodal information included in this step at appropriate places in the explanation, and format and interpret them according to their requirements.
|
|
67
|
+
- **Summary**: Briefly summarize the content explained in the current step; just output a small concluding paragraph directly, no need to add a subheading for it (like `### Summary`).
|
|
68
|
+
|
|
69
|
+
user_template: |
|
|
70
|
+
## User Question
|
|
71
|
+
{question}
|
|
72
|
+
|
|
73
|
+
## Previous Context (Completed Steps)
|
|
74
|
+
{previous_context}
|
|
75
|
+
|
|
76
|
+
## Current Step (Step {step_id})
|
|
77
|
+
**Target**: {step_target}
|
|
78
|
+
|
|
79
|
+
## Available Materials
|
|
80
|
+
### 1. Knowledge Base Citations
|
|
81
|
+
{available_cite_details}
|
|
82
|
+
|
|
83
|
+
### 2. Tool Execution Results (Code/Search)
|
|
84
|
+
{tool_materials}
|
|
85
|
+
|
|
86
|
+
### 3. Images to Insert (Please insert each path and explain)
|
|
87
|
+
{image_materials}
|
|
88
|
+
|
|
89
|
+
## Task
|
|
90
|
+
Write the formal answer for this step, as the official output for step {step_id} of the full response:
|