Вводные данные количество токенов было аномально высоким, несмотря на то, что в системной подсказке агента ничего не было передано.
Вот код, который я запустил:
Код: Выделить всё
from smolagents import ToolCallingAgent, HfApiModel, tool
from dotenv import load_dotenv
from smolagents.prompts import TOOL_CALLING_SYSTEM_PROMPT
import os
load_dotenv()
# select model
model_id = "meta-llama/Llama-3.3-70B-Instruct"
model = HfApiModel(model_id=model_id)
# creating a few tools
@tool
def add_numbers(a: float, b: float) -> float:
"""
Add two floating point numbers together.
Args:
a: first number
b: second number
"""
return a + b
@tool
def subtract_numbers(a: float, b: float) -> float:
"""
Subtract second number from the first number.
Args:
a: number to subtract from
b: number to subtract
"""
return a - b
@tool
def multiply_numbers(a: float, b: float) -> float:
"""
Multiply two floating point numbers.
Args:
a: first number
b: second number
"""
return a * b
@tool
def divide_numbers(a: float, b: float) -> float:
"""
Divide first number by the second number.
Args:
a: dividend (number to be divided)
b: divisor (number to divide by)
"""
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
# create custom prompt.
custom_prompt = """You are a math expert. You will only use the tools available to you.
Here are the tools available to you:
{{tool_descriptions}}
{{managed_agents_descriptions}}
IMPORTANT NOTE: You will ALWAYS evaluate the user's query and perfom query classification and print three things:
answer, tool_used, reasoning
like this:
Answer: answer
Tool Used: tool_name
Reasoning: reasoning for using the tool
An example:
Answer: 21.0
Tool Used: multiply
Reasoning: The tool was used to calculate the product of two numbers.
Solve the queries STEP by STEP and feel free to use the tools available to you and do not hallucinate or make assumptions."""
new_prompt = """{{managed_agents_descriptions}}"""
# create agent out of the model, and furnish tools to it.
agent = ToolCallingAgent(tools=[add_numbers, subtract_numbers, multiply_numbers, divide_numbers], model=model, add_base_tools=True, system_prompt=new_prompt)
# print(agent.initialize_system_prompt())
# agent.run("What's 2 + 8 - 3?")
if __name__ == "__main__":
print("new prompt is: ", agent.system_prompt)
print(agent.run("What's 2 + 8 - 3?"))

Что вызывает такое большое количество входных токенов? Я что-то упустил?
Подробнее здесь: https://stackoverflow.com/questions/793 ... smolagents
Мобильная версия