Skip to content
This repository was archived by the owner on Nov 8, 2025. It is now read-only.

Commit efc36ad

Browse files
添加总结节点
1 parent 29f3ab4 commit efc36ad

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/main_agent/utils/nodes/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
__all__ = [
88
"welcome", "finish_interrupt", "agent_execution",
9-
"should_tool", "no_tools_warning", "tool_result_transport", "ask_interrupt"
9+
"should_tool", "no_tools_warning", "tool_result_transport", "ask_interrupt",
10+
"summarization_node"
1011
]

src/main_agent/utils/nodes/execution.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22

33
from langchain_openai import ChatOpenAI
44
from langchain_core.runnables import RunnableConfig
5+
from langchain_core.messages.utils import count_tokens_approximately
6+
from langmem.short_term import SummarizationNode
7+
from pathlib import Path
58
from aiopath import AsyncPath
69
from typing import Any, Dict
710

811
from src.main_agent.utils.state import MainAgentState
912
from src.main_agent.utils.tools import tool_list
1013

1114

15+
summarization_node = SummarizationNode(
16+
token_counter=count_tokens_approximately,
17+
model=ChatOpenAI(
18+
model="deepseek/deepseek-chat-v3-0324",
19+
temperature=0.3,
20+
base_url="https://openrouter.ai/api/v1",
21+
api_key=(Path(__file__).parent.parent / "api_key").read_text(encoding="utf-8").strip(),
22+
max_retries=3,
23+
max_tokens=8192,
24+
), # TODO: 更灵活的模型配置
25+
max_tokens=16384,
26+
max_tokens_before_summary=65536,
27+
max_summary_tokens=16384,
28+
)
29+
30+
1231
async def agent_execution(state: MainAgentState, config: RunnableConfig) -> Dict[str, Any]:
1332
"""
1433
Agent 执行节点,处理用户输入并执行任务

src/main_agent/utils/nodes/routing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def tool_result_transport(state: MainAgentState, config: RunnableConfig) -> str:
3939
# 检查是否有工具调用
4040
match tool_call["name"]:
4141
case "attempt_completion":
42-
return "finish_interrupt"
42+
return "summarization"
4343
case "ask_question":
4444
return "ask_interrupt"
4545

0 commit comments

Comments
 (0)