> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Agents SDK

> W&B Weave를 OpenAI Agents SDK와 함께 사용해 에이전트 애플리케이션을 추적하고 모니터링하세요

W\&B Weave를 OpenAI Agents SDK와 함께 사용해 에이전트 애플리케이션의 트레이스를 수집하고 모니터링할 수 있습니다.

<Tabs>
  <Tab title="Python">
    [OpenAI Agents Python SDK](https://github.com/openai/openai-agents-python)는 멀티 에이전트 워크플로를 구축할 때 사용할 수 있는 가볍고 강력한 프레임워크입니다.

    ## 설치

    `pip`를 사용해 필요한 의존성을 설치합니다:

    ```bash theme={null}
    pip install weave openai-agents
    ```

    ## 시작하기

    OpenAI Agents SDK를 Weave와 함께 사용하려면 다음과 같이 합니다.

    * 프로젝트 이름으로 Weave를 초기화합니다.
    * 에이전트에 Weave 트레이싱 프로세서를 추가합니다.
    * 평소처럼 에이전트를 생성하고 실행합니다.

    다음 코드 예제는 OpenAI Agent를 생성하고, 트레이스를 추적할 수 있도록 Weave와 통합하는 방법을 보여줍니다. Weave 프로젝트를 초기화하고 실행 트레이스를 수집하도록 `WeaveTracingProcessor`를 설정합니다. `Weather` 데이터 모델은 날씨 정보를 나타냅니다. `get_weather` 함수는 에이전트가 사용할 수 있는 도구로 데코레이터가 적용되며, 예시 날씨 리포트를 반환합니다. `Hello world`라는 이름의 에이전트는 기본 지침과 날씨 도구를 사용할 수 있도록 구성됩니다. `main` 함수는 예시 입력(`What's the weather in Tokyo?`)으로 에이전트를 비동기적으로 실행하고 최종 응답을 출력합니다.

    ```python lines theme={null}
    from pydantic import BaseModel
    from agents import Agent, Runner, function_tool
    import agents
    import weave
    import asyncio

    weave.init("openai-agents")

    class Weather(BaseModel):
        city: str
        temperature_range: str
        conditions: str

    @function_tool
    def get_weather(city: str) -> Weather:
        return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")

    agent = Agent(
        name="Hello world",
        instructions="You are a helpful agent.",
        tools=[get_weather]
    )

    async def main():
        result = await Runner.run(agent, input="What's the weather in Tokyo?")    
        print(result.final_output)

    if __name__ == "__main__":
        asyncio.run(main())
    ```

    ## 트레이스 보기

    위 코드 샘플을 실행하면 Weave 대시보드 링크가 생성됩니다. 링크를 열어 에이전트 run의 트레이스를 확인하세요.
  </Tab>

  <Tab title="TypeScript">
    [OpenAI Agents Node SDK](https://github.com/openai/openai-node)는 멀티 에이전트 워크플로를 구축하기 위한 가볍고 강력한 프레임워크입니다.

    ## 설치

    `npm`을 사용해 필요한 의존성을 설치합니다. Weave의 TypeScript 인테그레이션을 사용하려면 `@openai/agents` 버전 `0.4.15` 이상이 필요합니다:

    ```bash theme={null}
    npm install weave @openai/agents zod
    ```

    ## 시작하기

    대부분의 Node.js 환경에서는 수동 계측이 필요하지 않습니다.
    Weave는 모듈이 로드되면 `@openai/agents`를 자동으로 계측합니다.

    자동 계측은 모듈 로더 훅을 등록하는 방식으로 동작합니다.

    * **CommonJS 프로젝트:** 추가 설정이 필요하지 않습니다.
    * **ESM 프로젝트:** 계측이 다른 모듈보다 먼저 로드되도록 Node를 `--import=weave/instrument` 플래그와 함께 시작해야 합니다.

    프로젝트 설정에 도움이 필요하거나 현재 사용 중인 유형을 확인해야 한다면, [TypeScript SDK: 서드파티 인테그레이션 가이드](/ko/weave/guides/integrations/js)를 참조하세요.

    다음 코드 예제는 OpenAI Agent를 생성하고 추적할 수 있도록 Weave와 통합합니다. Weave 프로젝트 초기화의 `your-team-name/your-project-name`을 자신의 entity와 프로젝트로 바꾸세요. 이 예제는 샘플 날씨 보고서를 반환하는 `get_weather` 도구를 정의한 다음, 기본 지침과 날씨 도구에 대한 액세스 권한이 있는 `Hello world`라는 이름의 에이전트를 설정합니다. `main` 함수는 샘플 입력(`What's the weather in Tokyo?`)으로 에이전트를 실행하고 최종 응답을 로그에 기록합니다.

    ```typescript lines theme={null}
    import * as weave from "weave";
    import { Agent, run, tool } from "@openai/agents";
    import { z } from "zod";

    const getWeather = tool({
      name: "get_weather",
      description: "Get the current weather for a given city.",
      parameters: z.object({
        city: z.string().describe("The name of the city"),
      }),
      async execute({ city }) {
        return `${city}: 14-20C, Sunny with wind.`;
      },
    });

    async function main() {
      // 프로젝트 정보로 업데이트하세요.
      await weave.init("your-team-name/your-project-name");

      const agent = new Agent({
        name: "Hello world",
        instructions: "You are a helpful agent.",
        tools: [getWeather],
      });

      const result = await run(agent, [
        { role: "user", content: "What's the weather in Tokyo?" },
      ]);
      console.log(result.finalOutput);
    }

    main();
    ```

    CommonJS에서는 자동 계측을 위해 `import * as weave from "weave"` 구문이 `import { Agent, run, tool } from "@openai/agents"`보다 **앞에** 와야 합니다. 코드가 이 순서를 따를 수 없다면, 아래의 수동 계측 방법을 사용하세요.

    ### 수동 계측

    수동 계측은 다음과 같이 모듈 로더 훅을 실행할 수 없는 경우에만 필요합니다.

    * 의존성을 단일 파일로 번들링하는 번들러.
    * Node CLI 플래그를 전달할 수 없는 환경.
    * 로더 훅을 우회하는 동적 모듈 로딩 패턴.

    이 경우 `instrumentOpenAIAgents()`를 사용해 계측을 명시적으로 등록할 수 있습니다.

    ```typescript lines theme={null}
    import * as weave from "weave";

    await weave.init("openai-agents");
    await weave.instrumentOpenAIAgents();
    ```

    맞춤형 프로세서 설정이나 조건부 등록처럼 트레이싱 프로세서를 완전히 제어해야 하는 경우에는, 수동으로 하나를 생성하고 등록하세요:

    ```typescript lines theme={null}
    import { addTraceProcessor } from "@openai/agents";
    import { createOpenAIAgentsTracingProcessor } from "weave";

    ...

    const processor = createOpenAIAgentsTracingProcessor();
    addTraceProcessor(processor);
    ```
  </Tab>
</Tabs>
