Skip to content

Commit c4cdb5f

Browse files
chenjwyeshion23333
andauthored
Fix/bot Fix Memory Consolidation Issues and Integrate Vikingbot as OpenViking Optional Dependency (#492)
* fix * add log * add log * update * Opt memory * Opt memory * Opt memory * Opt memory * Fix memory consolidation issues: duplicate session write, hook error, and async - Fix _consolidate_memory hook error by creating temporary Session when given message list - Remove duplicate session save logic from _consolidate_memory (handled by caller) - Make normal memory consolidation async like /new command - Other fixes: streaming response in CLI and OpenAPI channel * Integrate vikingbot as openviking optional dependency - Add vikingbot dependencies to pyproject.toml optional-dependencies - Update install prompts from vikingbot[X] to openviking[bot-X] - Update README installation instructions - Configure setuptools to find vikingbot in bot/ directory - Add vikingbot package data and script entry * Remove bot/pyproject.toml vikingbot is now integrated as part of openviking, no need for separate pyproject.toml * Update vikingbot installation instructions in root READMEs - Update from 'uv pip install -e bot/' to 'uv pip install -e ".[bot]"' - Add quotes around openviking[bot] for shell safety * update * Use singleton pattern for VikingClient in hooks Cache VikingClient instances by workspace_id to avoid repeated client creation - Add _client_cache dictionary for caching - Add get_cached_client() helper function - Update both hooks to use cached client * Use global singleton for VikingClient instead of per-workspace cache - Change from per-workspace_id cache to true global singleton - Create client with None as agent_id (works for all workspaces) - Simplify client management * uv run ruff format --------- Co-authored-by: DuTao <dutao.1786@bytedance.com>
1 parent 164c3ed commit c4cdb5f

File tree

33 files changed

+2415
-1498
lines changed

33 files changed

+2415
-1498
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ VikingBot is an AI agent framework built on top of OpenViking. Here's how to get
443443

444444
```bash
445445
# Option 1: Install VikingBot from PyPI (recommended for most users)
446-
pip install openviking[bot]
446+
pip install "openviking[bot]"
447447

448448
# Option 2: Install VikingBot from source (for development)
449-
uv pip install -e bot/
449+
uv pip install -e ".[bot]"
450450

451451
# Start OpenViking server with Bot enabled
452452
openviking-server --with-bot

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ VikingBot 是构建在 OpenViking 之上的 AI 智能体框架。以下是快速
443443

444444
```bash
445445
# 选项 1:从 PyPI 安装 VikingBot(推荐大多数用户使用)
446-
pip install openviking[bot]
446+
pip install "openviking[bot]"
447447

448448
# 选项 2:从源码安装 VikingBot(用于开发)
449-
uv pip install -e bot/
449+
uv pip install -e ".[bot]"
450450

451451
# 启动 OpenViking 服务器(同时启动 Bot)
452452
openviking-server --with-bot

bot/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Vikingbot is deeply integrated with OpenViking, providing powerful knowledge man
1616

1717
**Option 1: Install from PyPI (Simplest)**
1818
```bash
19-
pip install vikingbot
19+
pip install "openviking[bot]"
2020
```
2121

2222
**Option 2: Install from source (for development)**
@@ -37,7 +37,7 @@ powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
3737

3838
```bash
3939
git clone https://github.com/volcengine/OpenViking
40-
cd OpenViking/bot
40+
cd OpenViking
4141

4242
# Create a virtual environment using Python 3.11 or higher
4343
uv venv --python 3.11
@@ -47,10 +47,10 @@ source .venv/bin/activate # macOS/Linux
4747
# .venv\Scripts\activate # Windows
4848

4949
# Install dependencies (minimal)
50-
uv pip install -e .
50+
uv pip install -e ".[bot]"
5151

5252
# Or install with optional features
53-
uv pip install -e ".[langfuse,telegram,console]"
53+
uv pip install -e ".[bot,bot-langfuse,bot-telegram]"
5454
```
5555

5656
### Optional Dependencies
@@ -59,25 +59,25 @@ Install only the features you need:
5959

6060
| Feature Group | Install Command | Description |
6161
|---------------|-----------------|-------------|
62-
| **Full** | `uv pip install -e ".[full]"` | All features included |
63-
| **Langfuse** | `uv pip install -e ".[langfuse]"` | LLM observability and tracing |
64-
| **FUSE** | `uv pip install -e ".[fuse]"` | OpenViking filesystem mount |
65-
| **Sandbox** | `uv pip install -e ".[sandbox]"` | Code execution sandbox |
66-
| **OpenCode** | `uv pip install -e ".[opencode]"` | OpenCode AI integration |
62+
| **Full** | `uv pip install -e ".[bot-full]"` | All features included |
63+
| **Langfuse** | `uv pip install -e ".[bot-langfuse]"` | LLM observability and tracing |
64+
| **FUSE** | `uv pip install -e ".[bot-fuse]"` | OpenViking filesystem mount |
65+
| **Sandbox** | `uv pip install -e ".[bot-sandbox]"` | Code execution sandbox |
66+
| **OpenCode** | `uv pip install -e ".[bot-opencode]"` | OpenCode AI integration |
6767

6868
#### Channels (chat apps)
6969

7070
| Channel | Install Command |
7171
|---------|-----------------|
72-
| **Telegram** | `uv pip install -e ".[telegram]"` |
73-
| **Feishu/Lark** | `uv pip install -e ".[feishu]"` |
74-
| **DingTalk** | `uv pip install -e ".[dingtalk]"` |
75-
| **Slack** | `uv pip install -e ".[slack]"` |
76-
| **QQ** | `uv pip install -e ".[qq]"` |
72+
| **Telegram** | `uv pip install -e ".[bot-telegram]"` |
73+
| **Feishu/Lark** | `uv pip install -e ".[bot-feishu]"` |
74+
| **DingTalk** | `uv pip install -e ".[bot-dingtalk]"` |
75+
| **Slack** | `uv pip install -e ".[bot-slack]"` |
76+
| **QQ** | `uv pip install -e ".[bot-qq]"` |
7777

7878
Multiple features can be combined:
7979
```bash
80-
uv pip install -e ".[langfuse,telegram,console]"
80+
uv pip install -e ".[bot,bot-langfuse,bot-telegram]"
8181
```
8282

8383
## 🚀 Quick Start
@@ -434,7 +434,7 @@ For Langfuse Cloud, use `https://cloud.langfuse.com` as the `base_url`.
434434

435435
**Install Langfuse support:**
436436
```bash
437-
uv pip install -e ".[langfuse]"
437+
uv pip install -e ".[bot-langfuse]"
438438
```
439439

440440
**Restart vikingbot:**

bot/README_CN.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Vikingbot 深度集成 OpenViking,提供强大的知识管理和记忆检索
1717

1818
**选项 1:从 PyPI 安装(最简单)**
1919
```bash
20-
pip install vikingbot
20+
pip install "openviking[bot]"
2121
```
2222

2323
**选项 2:从源码安装(用于开发)**
@@ -38,7 +38,7 @@ powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
3838

3939
```bash
4040
git clone https://github.com/volcengine/OpenViking
41-
cd OpenViking/bot
41+
cd OpenViking
4242

4343
# 创建 Python 3.11 或更高版本 虚拟环境
4444
uv venv --python 3.11
@@ -48,10 +48,10 @@ source .venv/bin/activate # macOS/Linux
4848
# .venv\Scripts\activate # Windows
4949

5050
# 安装依赖(最小化)
51-
uv pip install -e .
51+
uv pip install -e ".[bot]"
5252

5353
# 或安装包含可选功能
54-
uv pip install -e ".[langfuse,telegram,console]"
54+
uv pip install -e ".[bot,bot-langfuse,bot-telegram]"
5555
```
5656

5757
### 可选依赖
@@ -60,25 +60,25 @@ uv pip install -e ".[langfuse,telegram,console]"
6060

6161
| 功能组 | 安装命令 | 描述 |
6262
|---------------|-----------------|-------------|
63-
| **完整版** | `uv pip install -e ".[full]"` | 包含所有功能 |
64-
| **Langfuse** | `uv pip install -e ".[langfuse]"` | LLM 可观测性和追踪 |
65-
| **FUSE** | `uv pip install -e ".[fuse]"` | OpenViking 文件系统挂载 |
66-
| **沙箱** | `uv pip install -e ".[sandbox]"` | 代码执行沙箱 |
67-
| **OpenCode** | `uv pip install -e ".[opencode]"` | OpenCode AI 集成 |
63+
| **完整版** | `uv pip install -e ".[bot-full]"` | 包含所有功能 |
64+
| **Langfuse** | `uv pip install -e ".[bot-langfuse]"` | LLM 可观测性和追踪 |
65+
| **FUSE** | `uv pip install -e ".[bot-fuse]"` | OpenViking 文件系统挂载 |
66+
| **沙箱** | `uv pip install -e ".[bot-sandbox]"` | 代码执行沙箱 |
67+
| **OpenCode** | `uv pip install -e ".[bot-opencode]"` | OpenCode AI 集成 |
6868

6969
#### 聊天渠道
7070

7171
| 渠道 | 安装命令 |
7272
|---------|-----------------|
73-
| **Telegram** | `uv pip install -e ".[telegram]"` |
74-
| **飞书/Lark** | `uv pip install -e ".[feishu]"` |
75-
| **钉钉** | `uv pip install -e ".[dingtalk]"` |
76-
| **Slack** | `uv pip install -e ".[slack]"` |
77-
| **QQ** | `uv pip install -e ".[qq]"` |
73+
| **Telegram** | `uv pip install -e ".[bot-telegram]"` |
74+
| **飞书/Lark** | `uv pip install -e ".[bot-feishu]"` |
75+
| **钉钉** | `uv pip install -e ".[bot-dingtalk]"` |
76+
| **Slack** | `uv pip install -e ".[bot-slack]"` |
77+
| **QQ** | `uv pip install -e ".[bot-qq]"` |
7878

7979
可以组合多个功能:
8080
```bash
81-
uv pip install -e ".[langfuse,telegram,console]"
81+
uv pip install -e ".[bot,bot-langfuse,bot-telegram]"
8282
```
8383

8484
## 🚀 快速开始
@@ -430,7 +430,7 @@ cd deploy/docker
430430

431431
**安装 Langfuse 支持:**
432432
```bash
433-
uv pip install -e ".[langfuse]"
433+
uv pip install -e ".[bot-langfuse]"
434434
```
435435

436436
**重启 vikingbot:**

bot/pyproject.toml

Lines changed: 0 additions & 146 deletions
This file was deleted.

bot/scripts/restart_openviking_server.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77

88
# Default values
99
PORT="1933"
10-
BOT_URL="http://localhost:18791"
10+
BOT_URL="http://localhost:18790"
1111

1212
# Parse arguments
1313
while [[ $# -gt 0 ]]; do
@@ -31,7 +31,7 @@ done
3131
# Parse Bot URL to extract port
3232
BOT_PORT=$(echo "$BOT_URL" | sed -n 's/.*:\([0-9]*\).*/\1/p')
3333
if [ -z "$BOT_PORT" ]; then
34-
BOT_PORT="18791"
34+
BOT_PORT="18790"
3535
fi
3636

3737
echo "=========================================="

bot/tests/example.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import openviking as ov
2+
3+
# Initialize OpenViking client with data directory
4+
client = ov.SyncOpenViking(path="./data")
5+
6+
try:
7+
# Initialize the client
8+
client.initialize()
9+
10+
# Add resource (supports URL, file, or directory)
11+
add_result = client.add_resource(
12+
path="/Users/bytedance/Downloads/exp/experience_data_mini.json",
13+
resource_type="json", # 明确指定类型
14+
tags=["large_data", "agent_context", "structured"],
15+
)
16+
root_uri = add_result["root_uri"]
17+
18+
# Explore the resource tree structure
19+
ls_result = client.ls(root_uri)
20+
print(f"Directory structure:\n{ls_result}\n")
21+
22+
# Use glob to find markdown files
23+
glob_result = client.glob(pattern="**/*.md", uri=root_uri)
24+
if glob_result["matches"]:
25+
content = client.read(glob_result["matches"][0])
26+
print(f"Content preview: {content[:200]}...\n")
27+
28+
# Wait for semantic processing to complete
29+
print("Wait for semantic processing...")
30+
client.wait_processed()
31+
32+
# Get abstract and overview of the resource
33+
abstract = client.abstract(root_uri)
34+
overview = client.overview(root_uri)
35+
print(f"Abstract:\n{abstract}\n\nOverview:\n{overview}\n")
36+
37+
# Perform semantic search
38+
results = client.find("what is openviking", target_uri=root_uri)
39+
print("Search results:")
40+
for r in results.resources:
41+
print(f" {r.uri} (score: {r.score:.4f})")
42+
43+
# Close the client
44+
client.close()
45+
46+
except Exception as e:
47+
print(f"Error: {e}")

0 commit comments

Comments
 (0)