> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Smolagents

> Weave의 자동 트레이싱으로 Smolagents 애플리케이션을 추적하세요. 도구 Call, 모델 추론, 다단계 에이전트 워크플로를 캡처합니다.

<Warning>
  이 페이지에 표시된 모든 코드 샘플은 Python으로 작성되었습니다.
</Warning>

이 페이지는 [Smolagents](https://huggingface.co/docs/smolagents/en/index)를 W\&B Weave와 통합하는 방법을 설명합니다. 이를 통해 에이전트형 애플리케이션을 추적하고 분석할 수 있습니다. 에이전트형 워크플로를 구축하는 개발자를 대상으로 하며, 모델 및 도구 Call에 대한 가시성을 원하는 분들에게 적합합니다. Weave의 트레이싱 및 버전 관리 기능을 사용하여 모델 추론을 로깅하고, 함수 Call을 모니터링하며, 실험을 구성하는 방법을 배울 수 있습니다. 제공된 예시를 따라가면 Weave 웹 인터페이스 내에서 유용한 인사이트를 캡처하고, 애플리케이션을 효율적으로 디버그하며, 다양한 모델 설정을 비교할 수 있습니다.

<h2 id="overview">
  개요
</h2>

Smolagents는 에이전트형 애플리케이션을 구축하기 위한 최소한의 추상화를 제공하는 프레임워크입니다. OpenAI, Hugging Face Transformers, Anthropic과 같은 여러 LLM 공급자를 지원합니다.

Weave는 [Smolagents](https://huggingface.co/docs/smolagents/en/index)에 대한 트레이스를 자동으로 캡처합니다. 추적을 시작하려면 `weave.init()`을 호출하고 평소처럼 라이브러리를 사용하세요.

<h2 id="prerequisites">
  사전 요구 사항
</h2>

시작하기 전에 필요한 라이브러리를 설치하고 선택한 LLM 공급자에 대한 액세스를 설정해야 합니다.

1. Smolagents를 Weave로 사용하기 전에 필요한 라이브러리를 설치하거나 최신 버전으로 업그레이드해야 합니다. 다음 명령은 `smolagents`, `openai`, `weave`를 설치하거나 업그레이드하고 출력을 숨깁니다:

   ```bash theme={"system"}
   pip install -U smolagents openai weave -qqq
   ```

2. Smolagents는 OpenAI, Hugging Face Transformers, Anthropic과 같은 여러 LLM 공급자를 지원합니다. 선택한 공급자의 API 키를 설정하여 Smolagents가 모델을 호출할 때 인증할 수 있도록 하세요. 해당 환경 변수를 설정하세요:

   ```python lines theme={"system"}
   import os
   import getpass

   os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API key: ")
   ```

<h2 id="basic-tracing">
  기본 트레이싱
</h2>

이 섹션에서는 Weave가 기본 Smolagents 워크플로에 대한 트레이스를 자동으로 캡처하는 방법을 보여줍니다.

언어 모델 애플리케이션의 트레이스를 중앙 위치에 저장하는 것은 개발 및 프로덕션에서 필수적입니다. 이러한 트레이스는 디버깅에 도움이 되며 애플리케이션을 개선하기 위한 데이터셋으로 사용됩니다.

Weave는 [Smolagents](https://huggingface.co/docs/smolagents/en/index)에 대한 트레이스를 자동으로 캡처합니다. 추적을 시작하려면 `weave.init()`을 호출하여 Weave를 초기화한 다음, 평소처럼 라이브러리를 사용하세요.

다음 예시는 Weave를 사용하여 도구를 사용하는 LLM 에이전트에 대한 추론 Call을 로깅하는 방법을 보여줍니다. 이 시나리오에서는:

* Smolagents의 `OpenAIServerModel`을 사용하여 언어 모델(OpenAI의 `gpt-4o`)을 정의합니다.
* 에이전트가 필요할 때 호출할 수 있는 검색 도구(`DuckDuckGoSearchTool`)를 설정합니다.
* 도구와 모델을 전달하여 `ToolCallingAgent`를 구성합니다.
* 검색 도구를 트리거하는 쿼리를 에이전트를 통해 실행합니다.
* Weave는 각 함수 및 모델 호출을 로깅하여 웹 인터페이스에서 검사할 수 있도록 합니다.

```python lines theme={"system"}
import weave
from smolagents import DuckDuckGoSearchTool, OpenAIServerModel, ToolCallingAgent

# Weave 초기화
weave.init(project_name="smolagents")

# Smolagents에서 지원하는 LLM 공급자 정의
model = OpenAIServerModel(model_id="gpt-4o")

# 쿼리에 기반한 DuckDuckGo web search 도구 정의
search_tool = DuckDuckGoSearchTool()

# tool-calling 에이전트 정의
agent = ToolCallingAgent(tools=[search_tool], model=model)
answer = agent.run(
    "Get me just the title of the page at url 'https://forge.coreweave.com/wandb/geekyrakshit/story-illustration/reports/Building-a-GenAI-assisted-automatic-story-illustrator--Vmlldzo5MTYxNTkw'?"
)
```

코드 샘플을 실행한 후, Weave 프로젝트 대시보드로 이동하여 트레이스를 확인하세요.

<Frame>
  <img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/smolagents-trace.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=1c3d1f1d2c7f65e64ab91816093f555f" alt="Weave는 각 추론 Call을 로깅하여 입력, 출력 및 메타데이터에 대한 세부 정보를 제공합니다." width="3342" height="1864" data-path="products/wandb/weave/_media/smolagents-trace.png" />
</Frame>

<h2 id="tracing-custom-tools">
  맞춤형 도구 트레이싱
</h2>

기본 제공 도구 외에도 맞춤형 도구로 에이전트를 확장할 수 있으며, 이러한 Call도 Weave로 트레이스할 수 있습니다.

`smolagents`의 `@tool`로 함수를 데코레이트하거나 `smolagents.Tool` 클래스를 상속하면 에이전트형 워크플로에 사용할 맞춤형 도구를 선언할 수 있습니다.

Weave는 Smolagents 워크플로의 맞춤형 도구 Call을 자동으로 추적합니다. 다음 예시는 Weave로 맞춤형 Smolagents 도구 Call을 로깅하는 방법을 보여 줍니다.

* 맞춤형 `get_weather` 함수를 정의하고 Smolagents의 `@tool`로 데코레이트하여, 에이전트가 추론 과정에서 이 함수를 호출할 수 있도록 합니다.
* 이 함수는 위치와 섭씨 출력 여부를 지정하는 선택 플래그를 받습니다.
* `OpenAIServerModel`을 사용하여 언어 모델을 인스턴스화합니다.
* 맞춤형 도구와 모델을 사용하여 `ToolCallingAgent`를 생성합니다.
* 에이전트가 쿼리를 실행하면 `get_weather` 도구를 선택하여 호출합니다.
* Weave는 모델 추론과 맞춤형 도구 호출을 인수 및 반환 값과 함께 모두 로깅합니다.

```python lines theme={"system"}
from typing import Optional

import weave
from smolagents import OpenAIServerModel, ToolCallingAgent, tool

weave.init(project_name="smolagents")

@tool
def get_weather(location: str, celsius: Optional[bool] = False) -> str:
    """
    Get the weather in the next few days for a given location.
    Args:
        location: The location.
        celsius: Whether to use Celsius for temperature.
    """
    return f"The weather in {location} is sunny with temperatures around 7°C."

model = OpenAIServerModel(model_id="gpt-4o")
agent = ToolCallingAgent(tools=[get_weather], model=model)
answer = agent.run("What is the weather in Tokyo?")
```

코드 샘플을 실행한 후 Weave 프로젝트 대시보드로 이동하여 트레이스를 확인하세요.

<Frame>
  <img src="https://mintcdn.com/coreweave-dbfa0e8d/3Dv_sw2eg8feUJlx/products/wandb/weave/_media/smolagents-custom-tool.png?fit=max&auto=format&n=3Dv_sw2eg8feUJlx&q=85&s=8db13e892f9c1ee196a872e56f5c8354" alt="Weave는 각 맞춤형 도구 Call을 로깅합니다." width="3342" height="1864" data-path="products/wandb/weave/_media/smolagents-custom-tool.png" />
</Frame>


## Related topics

- [인테그레이션 개요](/ko/products/wandb/weave/guides/integrations.md)
