client-finder/ASYNC.md

85 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Client Finder Async Skill
> 异步执行 client-finder 查询,不阻塞主 session
## 触发方式
### 方式 1: 通过 sessions_spawn 调用
```typescript
sessions_spawn({
runtime: "subagent",
mode: "run",
task: "client-finder-async",
label: "client-finder: farm equipment Dallas",
agentId: "main",
cleanup: "keep"
})
```
### 方式 2: 直接调用脚本
```bash
cd ~/clawd/skills/client-finder
CLIENT_KEY=sk_xxx.yyy bun run scripts/run.ts "farm equipment Dallas" "us"
```
## 输入参数
通过 task 传递 JSON
```json
{
"query": "farm equipment parts Dallas",
"country": "us",
"client_key": "sk_ae28fc4e.2e0b218cf22ff1a27d52ab4601e1be5e1436f6932bd6282f"
}
```
## 输出
- **立即返回**: workflow ID 和状态
- **异步推送**: 完整结果通过 webhook 推送
## 并发优势
| 方式 | 阻塞主 session | 并发能力 | 结果推送 |
|------|--------------|---------|---------|
| 直接调用 | ✅ 是 | ❌ 单线程 | ✅ webhook |
| sub-agent | ❌ 否 | ✅ 多线程 | ✅ webhook |
## 批量查询示例
```typescript
// 并发执行多个查询
const queries = [
"farm equipment Dallas",
"tractor parts Texas",
"agricultural machinery DFW"
];
for (const query of queries) {
sessions_spawn({
runtime: "subagent",
mode: "run",
task: `client-finder: ${query}`,
label: `client-finder: ${query}`,
cleanup: "keep"
});
}
// 主 session 立即空闲,可以处理其他请求
```
## 监控子任务
```bash
# 查看活跃的子 agent
/subagents list
# 查看特定子任务的日志
/subagents log <id>
# 停止子任务
/subagents stop <id>
```