reviewer.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """论文审校服务"""
  2. from typing import Callable
  3. from hello_agents import ToolAwareSimpleAgent
  4. from config import Configuration
  5. from models import PaperState
  6. from utils import strip_thinking_tokens, strip_tool_calls
  7. class ReviewService:
  8. """调用审校 Agent 对论文草稿进行审阅"""
  9. def __init__(
  10. self,
  11. agent_factory: Callable[[], ToolAwareSimpleAgent],
  12. config: Configuration,
  13. ):
  14. self._agent_factory = agent_factory
  15. self._config = config
  16. def review(self, state: PaperState, full_draft: str) -> str:
  17. prompt = (
  18. f"论文题目:{state.paper_title or state.research_topic}\n"
  19. f"引用格式:{state.citation_style}\n\n"
  20. f"论文草稿:\n{full_draft[:8000]}\n\n"
  21. f"请从逻辑、引用、术语、连贯性和可复现性五个维度审校。"
  22. )
  23. agent = self._agent_factory()
  24. try:
  25. response = agent.run(prompt)
  26. finally:
  27. agent.clear_history()
  28. notes = response.strip()
  29. if self._config.strip_thinking_tokens:
  30. notes = strip_thinking_tokens(notes)
  31. return strip_tool_calls(notes).strip()