오케스트레이션과 핸드오프
오케스트레이션과 핸드오프 (Orchestration and handoffs)
전문가들이 작업의 다른 부분을 소유해야 할 때 다중 에이전트 워크플로우가 유용해요. 첫 번째 설계 선택은 워크플로우의 각 분기에서 최종 사용자 대면 답변을 누가 소유할지 결정하는 것이에요.
출처: 문서
본문
전문가들이 작업의 다른 부분을 소유해야 할 때 다중 에이전트 워크플로우가 유용해요. 첫 번째 설계 선택은 워크플로우의 각 분기에서 최종 사용자 대면 답변을 누가 소유할지 결정하는 것이에요.
오케스트레이션 패턴 선택하기
| 패턴 | 언제 사용할까 | 무슨 일이 일어나나 |
|---|---|---|
| 핸드오프 (Handoffs) | 전문가가 해당 작업 분기의 대화를 인수해야 할 때 | 제어가 전문가 에이전트로 이동 |
| 도구로서의 에이전트 (Agents as tools) | 매니저가 제어를 유지하고 전문가를 경계가 있는 능력으로 호출해야 할 때 | 매니저가 답변의 소유권을 유지 |
위임된 소유권에는 핸드오프 사용하기
핸드오프는 전문가가 단지 배후에서 돕는 것이 아니라 다음 응답을 소유해야 할 때 가장 명확하게 맞아요.
핸드오프로 위임하기
import { Agent, handoff } from "@openai/agents";
const billingAgent = new Agent({ name: "Billing agent" });
const refundAgent = new Agent({ name: "Refund agent" });
const triageAgent = Agent.create({
name: "Triage agent",
handoffs: [billingAgent, handoff(refundAgent)],
});
from agents import Agent, handoff
billing_agent = Agent(name="Billing agent")
refund_agent = Agent(name="Refund agent")
triage_agent = Agent(
name="Triage agent",
handoffs=[billing_agent, handoff(refund_agent)],
)
라우팅 표면을 읽기 쉽게 유지하세요:
- 각 전문가에게 좁은 작업을 주세요.
- TypeScript의
handoffDescription또는 Python의handoff_description을 짧고 구체적으로 유지하세요. - 다음 분기가 실제로 다른 지침, 도구 또는 정책을 필요로 할 때만 분할하세요.
고급 단계에서 핸드오프는 구조화된 메타데이터나 필터링된 히스토리를 함께 전달할 수도 있어요. 연결 방식이 언어에 따라 다르기 때문에 그 정확한 API는 SDK 문서에 남아 있어요.
매니저 스타일 워크플로우에는 도구로서의 에이전트 사용하기
메인 에이전트가 최종 답변에 대해 책임을 유지하고 전문가를 헬퍼로 호출해야 할 때 TypeScript의 agent.asTool() 또는 Python의 agent.as_tool()을 사용하세요.
전문가를 도구로 호출하기
import { Agent } from "@openai/agents";
const summarizer = new Agent({
name: "Summarizer",
instructions: "Generate a concise summary of the supplied text.",
});
const mainAgent = new Agent({
name: "Research assistant",
tools: [
summarizer.asTool({
toolName: "summarize_text",
toolDescription: "Generate a concise summary of the supplied text.",
}),
],
});
from agents import Agent
summarizer = Agent(
name="Summarizer",
instructions="Generate a concise summary of the supplied text.",
)
main_agent = Agent(
name="Research assistant",
tools=[
summarizer.as_tool(
tool_name="summarize_text",
tool_description="Generate a concise summary of the supplied text.",
)
],
)
이것은 보통 다음과 같을 때 더 나은 선택이에요:
- 매니저가 최종 답변을 종합해야 할 때
- 전문가가 요약이나 분류 같은 경계가 있는 작업을 수행할 때
- 소유권 이전 대신 중첩된 전문가 호출이 있는 안정적인 단일 외부 워크플로우를 원할 때
계약이 바뀔 때만 전문가 추가하기
가능하면 한 에이전트로 시작하세요. 전문가가 능력 격리, 정책 격리, 프롬프트 명확성, 트레이스 가독성을 실질적으로 개선할 때만 추가하세요.
너무 일찍 분할하면 워크플로우를 반드시 더 낫게 만들지 않으면서 프롬프트, 트레이스, 승인 표면이 더 많이 생겨요.
다음 단계
소유권 패턴이 명확해지면, 인접한 런타임 또는 상태 질문을 다루는 가이드로 계속 진행하세요.
[Agent definitions
Refine each specialist's instructions, tools, and output contract.](https://developers.openai.com/api/docs/guides/agents/define-agents)
[Running agents
Understand how handoffs and tools behave inside a run.](https://developers.openai.com/api/docs/guides/agents/running-agents)
[Results and state
See how
`lastAgent` in TypeScript or `last_agent` in Python
and resumable state affect the next turn.](https://developers.openai.com/api/docs/guides/agents/results)