Skip to content

Commit d645748

Browse files
committed
Merge branch 'main' into feat/skills
2 parents 85166bf + e4afab8 commit d645748

18 files changed

Lines changed: 411 additions & 8 deletions

File tree

docs/docs/memory/long-term-memory.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,25 @@ Session archived to Long-Term Memory
417417
Runner2 Question: favorite project
418418
Runner2 Answer: Your favorite project is Project Alpha.
419419
```
420+
421+
## 自动保存 session 到长期记忆
422+
423+
为简化操作流程,VeADK 的 Agent 模块支持将对话 Session 自动保存至长期记忆。只需在初始化 Agent 时,开启 auto_save_session 属性并完成长期记忆组件的初始化配置即可,具体示例如下:
424+
425+
```python
426+
from veadk import Agent
427+
from veadk.memory import LongTermMemory
428+
429+
# 初始化长期记忆组件
430+
long_term_memory = LongTermMemory(
431+
backend="viking", app_name=APP_NAME, user_id=USER_ID
432+
)
433+
434+
# 初始化 Agent 并开启 Session 自动保存
435+
agent = Agent(
436+
auto_save_session=True,
437+
long_term_memory=long_term_memory
438+
)
439+
```
440+
441+
为避免索引被频繁初始化,VeADK 提供 MIN_MESSAGES_THRESHOLD 和 MIN_TIME_THRESHOLD 两个环境变量,支持自定义 Session 保存周期。其中,默认触发保存的条件为累计 10 条 event 或间隔 60 秒;此外,当切换 Session 并发起新的问答请求时,VeADK 会自动将旧 Session 的会话内容保存至长期记忆中。

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "veadk-python"
3-
version = "0.5.2"
3+
version = "0.5.3"
44
description = "Volcengine agent development kit, integrations with Volcengine cloud services."
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -13,7 +13,7 @@ authors = [
1313
]
1414
dependencies = [
1515
"pydantic-settings==2.10.1", # Config management
16-
"a2a-sdk==0.3.7", # For Google Agent2Agent protocol
16+
"a2a-sdk>=0.3.7", # For Google Agent2Agent protocol
1717
"deprecated==1.2.18",
1818
"google-adk>=1.19.0", # For basic agent architecture
1919
"litellm>=1.74.3", # For model inference

veadk/cli/cli_web.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import logging
1516
from functools import wraps
1617

1718
import click
@@ -139,5 +140,14 @@ async def wrapper(*args, **kwargs) -> ADKRunner:
139140
# from Google ADK and Litellm
140141
if "--log_level" not in extra_args:
141142
extra_args.extend(["--log_level", "ERROR"])
143+
logging.basicConfig(level=logging.ERROR, force=True)
144+
145+
if "--log_level" in extra_args:
146+
logging.basicConfig(
147+
level=getattr(
148+
logging, extra_args[extra_args.index("--log_level") + 1].upper()
149+
),
150+
force=True,
151+
)
142152

143153
cli_web.main(args=extra_args, standalone_mode=False)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from langchain.agents import AgentState
18+
from langchain.agents.middleware import after_agent
19+
from langchain_core.messages.ai import AIMessage
20+
from langchain_core.messages.human import HumanMessage
21+
from langgraph.runtime import Runtime
22+
23+
from veadk.community.langchain_ai.store.memory.viking_memory import (
24+
VikingMemoryStore,
25+
)
26+
from veadk.utils.logger import get_logger
27+
28+
logger = get_logger(__name__)
29+
30+
31+
@after_agent
32+
def save_session(state: AgentState, runtime: Runtime) -> None:
33+
"""Save the session to the memory store."""
34+
store: VikingMemoryStore | None = runtime.store
35+
if not store:
36+
return
37+
38+
app_name = store.index
39+
user_id = runtime.context.user_id
40+
session_id = runtime.context.session_id
41+
42+
messages = state.get("messages", [])
43+
logger.debug(
44+
f"Save session {session_id} for user {user_id} with {len(messages)} messages. messages={messages}"
45+
)
46+
47+
events = {}
48+
for message in messages:
49+
print(type(message))
50+
if isinstance(message, HumanMessage):
51+
event = {"role": "user", "parts": [{"text": message.content}]}
52+
53+
elif isinstance(message, AIMessage):
54+
event = {"role": "assistant", "parts": [{"text": message.content}]}
55+
else:
56+
...
57+
58+
events[message.id] = event
59+
60+
store.put(namespace=(app_name, user_id), key=session_id, value=events)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from langchain_core.utils.utils import (
18+
from_env,
19+
secret_from_env,
20+
)
21+
from langchain_openai import ChatOpenAI
22+
23+
24+
class ArkChatModel(ChatOpenAI):
25+
def __init__(self, model: str, **kwargs):
26+
super().__init__(
27+
model=model,
28+
api_key=secret_from_env("MODEL_AGENT_API_KEY")(),
29+
base_url=from_env(
30+
"MODEL_AGENT_API_BASE",
31+
default="https://ark.cn-beijing.volces.com/api/v3",
32+
)(),
33+
**kwargs,
34+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)