Skip to content

Commit 918c252

Browse files
committed
Merge branch 'master' of https://github.com/RC-CHN/AstrBot
2 parents 48a34e6 + 418f05f commit 918c252

6 files changed

Lines changed: 104 additions & 75 deletions

File tree

astrbot/core/astr_main_agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,8 @@ def _apply_sandbox_tools(
846846
) -> None:
847847
if req.func_tool is None:
848848
req.func_tool = ToolSet()
849+
if req.system_prompt is None:
850+
req.system_prompt = ""
849851
booter = config.sandbox_cfg.get("booter", "shipyard_neo")
850852
if booter == "shipyard":
851853
ep = config.sandbox_cfg.get("shipyard_endpoint", "")

astrbot/core/computer/computer_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import shutil
34
import uuid
45
from pathlib import Path
@@ -41,8 +42,6 @@ def _discover_bay_credentials(endpoint: str) -> str:
4142
Returns:
4243
API key string, or empty string if not found.
4344
"""
44-
import os
45-
4645
candidates: list[Path] = []
4746

4847
# 1. BAY_DATA_DIR env var

tests/agent/test_truncator.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ def test_fix_messages_normal_messages(self):
5252
assert len(result) == 3
5353
assert result == messages
5454

55-
def test_fix_messages_tool_with_valid_context(self):
56-
"""Test fix_messages with tool message after user+assistant."""
57-
truncator = ContextTruncator()
58-
messages = [
59-
self.create_message("user", "Run tool"),
60-
self.create_message("assistant", "Running..."),
61-
self.create_message("tool", "Tool result"),
62-
]
63-
result = truncator.fix_messages(messages)
64-
assert len(result) == 3
65-
assert result == messages
66-
6755
def test_fix_messages_tool_without_context(self):
6856
"""Test fix_messages with tool message without enough context."""
6957
truncator = ContextTruncator()
@@ -74,43 +62,6 @@ def test_fix_messages_tool_without_context(self):
7462
# Tool message without context should be removed
7563
assert len(result) == 0
7664

77-
def test_fix_messages_tool_with_only_one_message(self):
78-
"""Test fix_messages with tool message after only one message."""
79-
truncator = ContextTruncator()
80-
messages = [
81-
self.create_message("user", "Hello"),
82-
self.create_message("tool", "Tool result"),
83-
]
84-
result = truncator.fix_messages(messages)
85-
# Tool message without enough context should be removed
86-
assert len(result) == 0
87-
88-
def test_fix_messages_multiple_tools(self):
89-
"""Test fix_messages with multiple tool messages."""
90-
truncator = ContextTruncator()
91-
messages = [
92-
self.create_message("user", "Run tool"),
93-
self.create_message("assistant", "Running..."),
94-
self.create_message("tool", "Tool 1 result"),
95-
self.create_message("tool", "Tool 2 result"),
96-
]
97-
result = truncator.fix_messages(messages)
98-
assert len(result) == 4
99-
assert result == messages
100-
101-
def test_fix_messages_mixed_system_tool(self):
102-
"""Test fix_messages with system message and tool messages."""
103-
truncator = ContextTruncator()
104-
messages = [
105-
self.create_message("system", "System prompt"),
106-
self.create_message("user", "Run tool"),
107-
self.create_message("assistant", "Running..."),
108-
self.create_message("tool", "Tool result"),
109-
]
110-
result = truncator.fix_messages(messages)
111-
assert len(result) == 4
112-
assert result == messages
113-
11465
# ==================== truncate_by_turns Tests ====================
11566

11667
def test_truncate_by_turns_no_limit(self):

tests/test_kook/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!data
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"type": "card",
3+
"theme": "info",
4+
"size": "lg",
5+
"modules": [
6+
{
7+
"text": {
8+
"content": "test1",
9+
"type": "plain-text",
10+
"emoji": true
11+
},
12+
"type": "header"
13+
},
14+
{
15+
"text": {
16+
"content": "test2",
17+
"type": "kmarkdown"
18+
},
19+
"type": "section",
20+
"mode": "left"
21+
},
22+
{
23+
"type": "divider"
24+
},
25+
{
26+
"text": {
27+
"fields": [
28+
{
29+
"content": "test3",
30+
"type": "kmarkdown"
31+
},
32+
{
33+
"content": "**test4**",
34+
"type": "kmarkdown"
35+
}
36+
],
37+
"type": "paragraph",
38+
"cols": 2
39+
},
40+
"type": "section",
41+
"mode": "left"
42+
},
43+
{
44+
"elements": [
45+
{
46+
"src": "https://img.kookapp.cn/attachments/2023-01/05/63b645851ff19.svg",
47+
"type": "image",
48+
"alt": "",
49+
"size": "lg",
50+
"circle": false
51+
}
52+
],
53+
"type": "image-group"
54+
},
55+
{
56+
"src": "https://img.kookapp.cn/attachments/2023-01/05/63b645851ff19.svg",
57+
"title": "test5",
58+
"type": "file"
59+
},
60+
{
61+
"endTime": 1772343427360,
62+
"type": "countdown",
63+
"startTime": 1772343378259,
64+
"mode": "second"
65+
},
66+
{
67+
"elements": [
68+
{
69+
"text": "点我测试回调",
70+
"type": "button",
71+
"theme": "primary",
72+
"value": "btn_clicked",
73+
"click": "return-val"
74+
},
75+
{
76+
"text": "访问官网",
77+
"type": "button",
78+
"theme": "danger",
79+
"value": "https://www.kookapp.cn",
80+
"click": "link"
81+
}
82+
],
83+
"type": "action-group"
84+
},
85+
{
86+
"elements": [
87+
{
88+
"content": "test6",
89+
"type": "plain-text",
90+
"emoji": true
91+
}
92+
],
93+
"type": "context"
94+
},
95+
{
96+
"code": "test7",
97+
"type": "invite"
98+
}
99+
]
100+
}

tests/unit/test_astr_main_agent.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -516,30 +516,6 @@ async def test_ensure_persona_none_explicit(self, mock_event, mock_context):
516516

517517
assert "Persona Instructions" not in req.system_prompt
518518

519-
@pytest.mark.asyncio
520-
async def test_ensure_skills(self, mock_event, mock_context):
521-
"""Test applying skills to request."""
522-
module = ama
523-
mock_skill = MagicMock()
524-
mock_skill.name = "test_skill"
525-
mock_skill.to_prompt.return_value = "Skill description"
526-
mock_context.persona_manager.personas_v3 = []
527-
mock_context.persona_manager.resolve_selected_persona = AsyncMock(
528-
return_value=(None, None, None, False)
529-
)
530-
531-
with patch("astrbot.core.astr_main_agent.SkillManager") as mock_skill_mgr_cls:
532-
mock_skill_mgr = MagicMock()
533-
mock_skill_mgr.list_skills.return_value = [mock_skill]
534-
mock_skill_mgr_cls.return_value = mock_skill_mgr
535-
536-
req = ProviderRequest()
537-
req.conversation = MagicMock(persona_id=None)
538-
539-
await module._ensure_persona_and_skills(req, {}, mock_context, mock_event)
540-
541-
assert "test_skill" in req.system_prompt
542-
543519
@pytest.mark.asyncio
544520
async def test_ensure_tools_from_persona(self, mock_event, mock_context):
545521
"""Test applying tools from persona."""

0 commit comments

Comments
 (0)