配置交接

JoshuaShepherd2026-10-26查看 293复制 1970

配置代理切换 - 当要求设置多代理路由、在专家代理之间委托对话、配置切换规则或通过代理注册表将代理连接在一起时使用。

Download (.md)

📘如何使用这个技能

  1. 1
    复制技能内容·点击上方「Copy SKILL.md」复制全部内容,或 Download 下载到本地
  2. 2
    打开你的 AI 客户端·支持 Claude Code、Trae、Cursor、ChatGPT、DeepSeek、Kimi 等任意 AI 助手
  3. 3
    粘贴为系统提示/知识文件·Claude Code:放入 .claude/skills/ 目录;普通对话:作为首条消息发送并说「请严格按这份技能文档执行」
  4. 4
    直接提出你的需求·AI 会按技能定义的工作流、格式和约束来处理,无需再解释背景

💡 提示:技能生效后,每次对话只需一句需求,AI 会按 SKILL.md 的流程执行。

SKILL.md4863 chars
---
name: configure-handoff
description: Configure agent handoffs — use when asked to set up multi-agent routing, delegate conversations between specialist agents, configure handoff rules, or wire agents together via an agent registry.
---

Configure agent handoffs: $ARGUMENTS

## Before Starting

1. Search OpenAI docs for handoff patterns:
   - Use `mcp__openai-docs__search_openai_docs` with query "Agents SDK handoffs" for SDK-native handoff/transfer support
   - Use `mcp__openai-docs__search_openai_docs` with query "Agents SDK multi-agent" for orchestration patterns
2. Read the existing handoff infrastructure:
   - `{{AGENTS_DIR}}/shared/handoffs.ts` — `AgentRegistry`, `HandoffDecision`, `HandoffHandler`
   - `{{AGENTS_DIR}}/shared/enhanced-agent-bridge.ts` — search for `enableHandoffs` and handoff event handling
   - `{{AGENTS_DIR}}/shared/agent-tracer.ts` — handoff event tracing
3. Read the database schema:
   - `{{SCHEMA_PATH}}` — search for `agent_handoffs` table (from_agent_id, to_agent_id, trigger_rules, priority)

## Agent Registry

The `AgentRegistry` is a singleton that maps agent names to agent instances:

```typescript
import { agentRegistry } from '@/agents/shared/handoffs';
import { myAgent } from '@/agents/my-agent';
import { expertAgent } from '@/agents/expert';

// Register agents that can participate in handoffs
agentRegistry.register('my-agent', myAgent);
agentRegistry.register('expert', expertAgent);
```

## Handoff Decision Logic

A `HandoffHandler` evaluates whether the current agent should delegate to another:

```typescript
import type { HandoffHandler, HandoffDecision } from '@/agents/shared/handoffs';

export const myHandoffHandler: HandoffHandler = async (
  message: string,
  context: Record<string, unknown>,
  currentAgent: string
): Promise<HandoffDecision> => {
  // Example: route SEO questions to the SEO expert
  const seoKeywords = /\b(seo|search engine|meta tags|keywords|ranking)\b/i;
  if (seoKeywords.test(message) && currentAgent !== 'seo-expert') {
    return {
      shouldHandoff: true,
      targetAgent: 'seo-expert',
      reason: 'User is asking about SEO — delegating to specialist',
    };
  }

  // Example: route writing tasks to writing assistant
  const writingKeywords = /\b(write|draft|edit|rewrite|article|blog post)\b/i;
  if (writingKeywords.test(message) && currentAgent !== 'writing-assistant') {
    return {
      shouldHandoff: true,
      targetAgent: 'writing-assistant',
      reason: 'User needs writing assistance — delegating to specialist',
    };
  }

  return { shouldHandoff: false };
};
```

## Wiring Handoffs

Enable handoffs in the agent's API route:

```typescript
const bridge = createEnhancedAgentBridge(myAgent, {
  agentId: 'my-agent',
  enableHandoffs: true,  // enables the handoff pipeline
  // ... other config
});
```

The bridge will:
1. After receiving the user message, evaluate handoff handlers
2. If a handoff is triggered, switch to the target agent from the registry
3. Record a `handoff` event in the tracer (target agent, reason)
4. Continue execution with the target agent

## Database-Backed Handoffs

For handoff rules managed via admin UI:

```sql
-- agent_handoffs table
INSERT INTO agent_handoffs (from_agent_id, to_agent_id, trigger_rules, priority, enabled)
VALUES (
  '<source-agent-uuid>',
  '<target-agent-uuid>',
  '{"keywords": ["seo", "meta tags"], "confidence_threshold": 0.8}',
  1,
  true
);
```

Load and evaluate at runtime:
1. Query `agent_handoffs` for the current agent's outbound rules (ordered by priority)
2. Evaluate `trigger_rules` against the user message
3. First matching rule wins

## Circular Dependency Prevention

- The registry tracks the current handoff chain
- If agent A → B → A is detected, the second handoff is blocked
- Maximum handoff depth: 3 (configurable)
- Always include `currentAgent` in the handoff decision context

## OpenAI SDK-Native Handoffs

The OpenAI Agents SDK may support native handoffs via the `handoffs` agent property. Check the docs MCP:

```typescript
// If SDK supports native handoffs:
const agent = new Agent({
  name: 'triage',
  handoffs: [expertAgent, writerAgent],  // SDK routes automatically
});
```

If available, prefer SDK-native handoffs over custom `HandoffHandler` logic.

## Rules

- Always register agents in the singleton `agentRegistry` before enabling handoffs
- Handoff decisions must be fast — use keyword matching or lightweight classifiers, not LLM calls
- Log every handoff with reason for observability (tracer does this automatically)
- Prevent circular handoffs — track the chain and enforce max depth
- The user should not notice handoffs — the experience should be seamless
- Preserve conversation context across handoffs (session ID, message history)
- Check OpenAI docs MCP for SDK-native handoff support before implementing custom logic
来源:skillsdirectory

评论0

登录后参与评论

还没有评论,来抢沙发吧