smolagents 예제를 따라해봤다.
내부적으로 태스크를 Python 코드로 작성해 실행하여 결과를 구하는 방식 같다.
아래 코드는

  • 로컬의 Ollama Phi4를 사용한다.
  • ollama 사용하는 부분은 이 아티클을 참고했다.
  • 원본 예제의 tool들이 사용되지 않은 채 남아있다.
# test.py
from smolagents import CodeAgent, DuckDuckGoSearchTool
from smolagents import LiteLLMModel
from smolagents import DuckDuckGoSearchTool
 
model = LiteLLMModel(
    # model_id="ollama_chat/deepseek-r1:14b",
    model_id="ollama_chat/phi4:latest"
)
 
agent = CodeAgent(
    model=model,
    tools=[DuckDuckGoSearchTool()],
    add_base_tools=True,
    additional_authorized_imports=['numpy', 'sys','wikipedia','scipy','requests', 'bs4']
)
 
agent.run(
    "How many seconds does it take for a typical Apple Silicon MacBook Pro's battery to go from 100% to 0% at its full load?"
)

아래 결과가 나왔다.

╭────────────────────────────────── New run ──────────────────────────────────╮
│                                                                             │
│ How many seconds does it take for a typical Apple Silicon MacBook Pro's     │
│ battery to go from 100% to 0% at its full load?                             │
│                                                                             │
╰─ LiteLLMModel - ollama_chat/phi4:latest ────────────────────────────────────╯
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error in code parsing:
Your code snippet is invalid, because the regex pattern ```(?:py|python)?\n(.*?)\n``` was not found in it.
Here is your code snippet:
The time it takes for an Apple Silicon MacBook Pro's battery to drain from 100% to 0% under full load can vary based on several factors, including the specific model, usage scenario, and power management settings. However, some general observations can be made:

1. **Battery Capacity**: The latest models typically have a battery capacity of around 58-100 watt-hours (Wh). For example, a high-end MacBook Pro with an M2 chip might have up to 100 Wh.

2. **Full Load Usage**: Under full load conditions—such as running intensive applications like video editing software, or having multiple resource-heavy tasks simultaneously—the power consumption can reach upwards of 50 watts or more in some scenarios.

3. **Estimated Drain Time**:
   - If the MacBook is consuming approximately 50 watts under full load, a battery with a capacity of around 100 Wh would theoretically last about 2 hours (120 minutes) before depleting.
   - Conversely, if the power consumption is closer to 25 watts on average (a bit more common for sustained high usage), you might expect around 4 hours (240 minutes).

To convert these estimates into seconds:
- At a full load of approximately 50 watts:  
  \( \text{Time} = \frac{100 \text{ Wh}}{50 \text{ W}} \times 3600 \, \text{seconds/hour} = 7200 \,
\text{seconds} \).

- At a full load of around 25 watts:
  \( \text{Time} = \frac{100 \text{ Wh}}{25 \text{ W}} \times 3600 \, \text{seconds/hour} = 14400 
\, \text{seconds} \).

These calculations provide a rough estimate. The actual time may differ based on the specific workload and how efficiently the operating system manages power under different conditions.
Make sure to include code with the correct pattern, for instance:
Thoughts: Your thoughts
Code:
```py
# Your python code here
```<end_code>
Make sure to provide correct code blobs.
[Step 0: Duration 29.28 seconds| Input tokens: 43 | Output tokens: 393]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Step 2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 ─ Executing parsed code: ──────────────────────────────────────────────────────────────────────── 
  # Thought: We need to calculate the drain times for both lower and higher power consumption scenarios.                                                     
  
  # Variables for battery capacity and power consumption scenarios.
  battery_capacity_wh = 100  # Wh, typical for a high-end model
  power_consumption_low_w = 25  # W
  power_consumption_high_w = 50  # W                                             
  
  # Calculate time to drain the battery in hours for each scenario.
  time_to_drain_hours_low = battery_capacity_wh / power_consumption_low_w
  time_to_drain_hours_high = battery_capacity_wh / power_consumption_high_w
  
  # Convert these times from hours to seconds.
  time_to_drain_seconds_low = time_to_drain_hours_low * 3600  # seconds
  time_to_drain_seconds_high = time_to_drain_hours_high * 3600  # seconds
  
  # Print results for clarity.
  print(f"Time to drain battery at {power_consumption_low_w} W: {time_to_drain_seconds_low:.2f} seconds")
  print(f"Time to drain battery at {power_consumption_high_w} W: {time_to_drain_seconds_high:.2f} seconds")
  
  # Final Answer
  final_answer_variable = {
	  "low_power_scenario": time_to_drain_seconds_low,
	  "high_power_scenario": time_to_drain_seconds_high
  }
  
  # Call the final answer tool to provide the solution.
  final_answer(final_answer_variable)
  ─────────────────────────────────────────────────────────────────────────────
Execution logs:
Time to drain battery at 25 W: 14400.0 seconds
Time to drain battery at 50 W: 7200.0 seconds