멀티 에이전트와 핸드오프 — 일을 여러 에이전트에 나누기

멀티 에이전트와 핸드오프 — 일을 여러 에이전트에 나누기

문제가 커지면 한 에이전트로 모든 걸 감당하기 어려워져요. 이럴 때 기능별로 에이전트를 나누고 작업을 넘기는 핸드오프(handoff) 패턴이 빛을 발해요. 서브에이전트(handoffs)와 워커 같은 멀티 에이전트 패턴을 만들어볼게요.

출처: https://openai.github.io/openai-agents-python/multi_agent/

from agents import Agent, Runner

support_agent = Agent(name="Support", instructions="You are a support agent.")
sales_agent = Agent(name="Sales", instructions="You are a sales agent.")
triage_agent = Agent(
    name="Triage",
    instructions="Route the user to the right agent.",
    handoffs=[support_agent, sales_agent],
)

result = Runner.run_sync(triage_agent, "My order is late, where is it?")
print(result.final_output)

포인트를 정리하면요.

  • 에이전트에 handoffs=[...]를 주면 라우팅 에이전트가 상황에 맞는 에이전트로 작업을 넘겨요.
  • 각 에이전트는 자기 전용 instructions와 도구를 가질 수 있어요.
  • 핸드오프는 add_handoff()로 동적 추가할 수도 있고, 스트리밍 실행(Runner.run_streamed)과도 자연스럽게 조합돼요.

이렇게 하면 복잡한 대화도 '누가 할 일인지'를 에이전트끼리 결정하게 만들 수 있어요.

더 알아보기