Skip to content

Commit 33f8177

Browse files
committed
fix openclaw session problem
1 parent f906d2e commit 33f8177

4 files changed

Lines changed: 120 additions & 12 deletions

File tree

‎ajet/task_rollout/async_llm_bridge.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ async def llm_chat_verl(
146146
"completion_tokens": len(token_array), # type: ignore
147147
"total_tokens": len(prompt_token_ids) + len(token_array), # type: ignore
148148
}
149-
print("====----====usage", usage)
150-
print("====----====finish_reason", finish_reason)
151149
return {
152150
"role": "assistant",
153151
"request_id": request_id,

‎ajet/utils/swarm_overwatch.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ def display_latest_llm_call(self):
455455
while True:
456456
response = httpx.post(f"{self.server_url}/replay_latest_llm_call", timeout=30.0)
457457
structured_response = response.json()
458+
self.console.clear()
458459
if "input" not in structured_response or "output" not in structured_response:
459460
self.console.print(f"[bold red]{structured_response}[/bold red]")
460461
time.sleep(5)
@@ -464,6 +465,33 @@ def display_latest_llm_call(self):
464465
output = structured_response["output"]
465466
self.console.print(f"\n[bold green]Input:[/bold green]\n{input}")
466467
self.console.print(f"\n[bold green]Output:[/bold green]\n{output}")
468+
hide_when_more_than_n_line_break = 4
469+
try:
470+
input_items = ""
471+
output_items = ""
472+
for item in input['messages']:
473+
role = item['role']
474+
content = item['content']
475+
if isinstance(content, list):
476+
content = content[0].get('text', '')
477+
if content.count('\n') >= hide_when_more_than_n_line_break:
478+
content = content.replace('\n',' ')[:200] + " ....."
479+
else:
480+
content = content.replace('\n',' ')
481+
input_items += f"[bold blue]@{role}:[/bold blue] {content}\n"
482+
for item in output['choices']:
483+
role = item['message']['role']
484+
content = item['message']['content']
485+
if content.count('\n') >= hide_when_more_than_n_line_break:
486+
content = content.replace('\n',' ')[:200] + " ....."
487+
else:
488+
content = content.replace('\n',' ')
489+
output_items += f"[bold red]@{role}:[/bold red] {content}\n"
490+
self.console.print(f"\n-------------------------------------------------------------")
491+
self.console.print(f"\n[bold green]Input Simlified:[/bold green]\n{input_items}")
492+
self.console.print(f"\n[bold green]Output Simlified:[/bold green]\n{output_items}")
493+
except:
494+
pass
467495
time.sleep(5)
468496

469497
def choose_run(self) -> str:

‎docs/en/swarm_intro_blog_zh.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ AgentJet具备全分布式蜂群训练(Swarm Training)能力,
8888

8989
接下来,用简单的几个case展示 AgentJet 蜂群模式的优势。
9090

91+
## 蜂群 Agentic RL 框架核心优势
92+
93+
| 特性 | 经典训练框架 | AgentJet 蜂群框架 |
94+
|------|-------------|------------------|
95+
| **多模型异构训练** | ❌ 所有智能体共享同一模型 | ✅ 支持多个不同规模模型同时训练 |
96+
| **训练推理解耦** | ❌ 采样与训练紧耦合 | ✅ Server 训练,Client 采样,完全解耦 |
97+
| **运行环境限制** | ❌ 受训练服务器环境限制 | ✅ Client 可在任意设备运行(笔记本/服务器) |
98+
| **动态节点管理** | ❌ 无法动态添加/移除节点 | ✅ 训练中随时添加/移除 Client 节点 |
99+
| **调试迭代速度** | ❌ 修改代码需重启训练(每次15分钟+) | ✅ 仅重启 Client(秒级),无需重载模型 |
100+
| **容错能力** | ❌ 外部依赖故障导致训练中断 | ✅ Client 崩溃不影响训练,自动恢复 |
101+
| **多任务混合训练** | ❌ 所有任务共享同一运行环境 | ✅ 不同 Client 运行不同任务环境 |
102+
| **Agent 框架兼容** | ❌ 需适配特定训练框架 | ✅ 兼容任何 OpenAI API 协议框架 |
103+
| **本地开发体验** | ❌ 必须在训练服务器上调试 | ✅ 本地 IDE 调试,连接远程训练 |
104+
91105
## 灵活的蜂群训练模式
92106

93107
### 用笔记本电脑全参训练Agentic LLM模型

‎tutorial/opencode_build_openclaw_agent/mock_user_request.py‎

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,60 @@ def load_dataset(filepath: str = "extraversion_questions.json") -> List[Dict]:
1515
with open(filepath, 'r', encoding='utf-8') as f:
1616
return json.load(f)
1717

18-
def send_openclaw_message(question: str) -> str:
19-
"""Send message via OpenClaw CLI."""
18+
19+
def generate_agent_name() -> str:
20+
"""Generate a random agent name."""
21+
adjectives = ["happy", "quick", "bright", "clever", "bold", "calm", "eager", "gentle"]
22+
nouns = ["fox", "wolf", "bear", "eagle", "hawk", "lion", "tiger", "owl"]
23+
return f"{random.choice(adjectives)}_{random.choice(nouns)}_{random.randint(1000, 9999)}"
24+
25+
26+
def create_agent(agent_name: str) -> bool:
27+
"""Create a new agent using OpenClaw CLI."""
28+
try:
29+
workspace = f"/root/.openclaw/workspace-{agent_name}"
30+
result = subprocess.run(
31+
["openclaw", "agents", "add", agent_name, "--workspace", workspace, "--non-interactive"],
32+
capture_output=True,
33+
text=True,
34+
timeout=60
35+
)
36+
if result.returncode == 0:
37+
print(f"Created agent: {agent_name}")
38+
return True
39+
else:
40+
print(f"Error creating agent {agent_name}: {result.stderr}")
41+
return False
42+
except Exception as e:
43+
print(f"Error creating agent: {str(e)}")
44+
return False
45+
46+
47+
def delete_agent(agent_name: str) -> bool:
48+
"""Delete an agent using OpenClaw CLI."""
49+
try:
50+
result = subprocess.run(
51+
["openclaw", "agents", "delete", agent_name, "--force"],
52+
capture_output=True,
53+
text=True,
54+
timeout=60
55+
)
56+
if result.returncode == 0:
57+
print(f"Deleted agent: {agent_name}")
58+
return True
59+
else:
60+
print(f"Error deleting agent {agent_name}: {result.stderr}")
61+
return False
62+
except Exception as e:
63+
print(f"Error deleting agent: {str(e)}")
64+
return False
65+
66+
67+
def send_openclaw_message(agent_name: str, message: str) -> str:
68+
"""Send message via OpenClaw CLI to specific agent."""
2069
try:
2170
result = subprocess.run(
22-
["openclaw", "agent", "--agent", "main", "--message", question],
71+
["openclaw", "agent", "--agent", agent_name, "--message", message],
2372
capture_output=True,
2473
text=True,
2574
timeout=300
@@ -28,6 +77,7 @@ def send_openclaw_message(question: str) -> str:
2877
except Exception as e:
2978
return f"Error: {str(e)}"
3079

80+
3181
def main():
3282
"""Main loop to send requests from dataset."""
3383
print("Starting OpenClaw mock user requests")
@@ -37,15 +87,33 @@ def main():
3787
random.shuffle(dataset)
3888
print(f"Loaded {len(dataset)} questions from dataset\n")
3989

40-
# Send requests via OpenClaw CLI
41-
for i, item in enumerate(dataset):
42-
question = item.get("Question", "")
43-
print(f"[{i+1}/{len(dataset)}] Sending: {question[:80]}...")
90+
# Process dataset in chunks of 5
91+
for chunk_start in range(0, len(dataset), 5):
92+
chunk = dataset[chunk_start:chunk_start + 5]
93+
94+
# Generate random agent name
95+
agent_name = generate_agent_name()
96+
print(f"\n=== Creating agent: {agent_name} ===\n")
97+
98+
# Create agent
99+
if not create_agent(agent_name):
100+
print(f"Failed to create agent, skipping chunk")
101+
continue
102+
103+
# Send 5 messages
104+
for i, item in enumerate(chunk):
105+
question = item.get("Question", "")
106+
print(f"[{agent_name}/{i+1}/5] Sending: {question[:80]}...")
107+
response = send_openclaw_message(agent_name, question)
108+
print(f"Response: {response[:200]}...\n")
109+
time.sleep(2)
110+
111+
# Delete agent
112+
delete_agent(agent_name)
113+
print(f"\n=== Deleted agent: {agent_name} ===\n")
44114

45-
response = send_openclaw_message(question)
46-
print(f"Response: {response[:200]}...\n")
115+
print("\nAll agents processed successfully")
47116

48-
time.sleep(2)
49117

50118
if __name__ == "__main__":
51119
main()

0 commit comments

Comments
 (0)