跳到主要内容

跟踪 Smolagents

Smolagents tracing via autolog

MLflow 跟踪在您使用 Smolagents 时提供自动跟踪功能。当通过调用 mlflow.smolagents.autolog() 函数启用 Smolagents 自动跟踪时,Smolagents SDK 的使用将自动记录交互式开发期间生成的跟踪。

请注意,仅支持同步调用,异步 API 和流式方法不受跟踪。

示例用法

from smolagents import CodeAgent, LiteLLMModel
import mlflow

# Turn on auto tracing for Smolagents by calling mlflow.smolagents.autolog()
mlflow.smolagents.autolog()

model = LiteLLMModel(model_id="openai/gpt-4o-mini", api_key=API_KEY)
agent = CodeAgent(tools=[], model=model, add_base_tools=True)

result = agent.run(
"Could you give me the 118th number in the Fibonacci sequence?",
)

禁用自动跟踪

可以通过调用 mlflow.smolagents.autolog(disable=True)mlflow.autolog(disable=True) 来全局禁用 Smolagents 的自动跟踪。