Using Classical ML to Empower AI Agents

Using Classical ML to Empower AI Agents

利用传统机器学习赋能 AI 智能体

On the value of building on existing foundations 论在现有基础之上构建的价值

When people ask me what I’m doing these days at work, I feel like they are sometimes surprised when I say “building CatBoost classifiers” or “fitting isolation forests”. But this is in fact what I spend a good chunk of my time doing. My company’s product is a sophisticated agentic AI platform, but I don’t do much prompt engineering in my day to day. 当人们问我最近在忙什么时,我发现当我回答“构建 CatBoost 分类器”或“拟合孤立森林(Isolation Forests)”时,他们有时会感到惊讶。但事实上,这正是我花费大量时间在做的事情。我所在公司的产品是一个复杂的智能体 AI 平台,但我日常工作中并不怎么做提示词工程(Prompt Engineering)。

If you had asked me a year or two ago, I would have been seriously concerned about the future of classical ML work in the machine learning field, because we were getting so deep in a paradigm of using LLMs to handle things, whether they did a good job or not. However, it turns out that agentic AI needs classical ML much more than we probably thought. 如果一两年前你问我,我会对机器学习领域中传统机器学习工作的未来感到非常担忧,因为我们当时正深陷于一种“无论效果如何,都要用大语言模型(LLM)来处理一切”的范式中。然而事实证明,智能体 AI 对传统机器学习的需求远比我们想象的要大得多。

For a quick recap in case readers are unfamiliar: An AI Agent means combining LLMs and other software tooling together to create workflows with minimal or no human intervention, orchestrating any number of models or tools. The LLM is usually the interface between human users and all the other software tools, including tasks like translating human prompts to computer language. The LLM also interprets tool outputs and chooses which tools to call at appropriate moments. 为了照顾不熟悉的读者,这里简单回顾一下:AI 智能体是指将大语言模型与其他软件工具相结合,在极少或无需人工干预的情况下创建工作流,并编排任意数量的模型或工具。大语言模型通常充当人类用户与其他所有软件工具之间的接口,包括将人类提示词翻译成计算机语言等任务。大语言模型还会解读工具的输出,并在适当的时机选择调用哪些工具。

This enables much more functionality than an LLM by itself, because as I’ve talked about here many times, an LLM is just a token generating model, predicting the next word or phrase in a passage based on its context. Aside from autonomous agents, combining an LLM interface with other tools is required to do a huge number of the things we think colloquially of LLM chatbots doing. ChatGPT, Gemini, and Claude do this kind of thing, chaining together the LLM interface with things like data retrieval, web search, mathematics calculators, etc. 这使得它比单纯的大语言模型具备更强大的功能,因为正如我在这里多次提到的,大语言模型本质上只是一个标记生成模型,根据上下文预测段落中的下一个词或短语。除了自主智能体之外,将大语言模型接口与其他工具结合,也是实现我们日常所认为的“大语言模型聊天机器人”所能完成的大量任务的必要条件。ChatGPT、Gemini 和 Claude 都在做这类事情,它们将大语言模型接口与数据检索、网络搜索、数学计算器等功能串联在一起。

As you can see, a key aspect of the whole agentic AI ecosystem is tooling — your agent needs to have access to tools in order to effectively complete tasks outside of the core LLM functions. These tools can take all kinds of forms- a lot of them today in the business setting are data retrieval and organizing tools, graph databases, RAG knowledge bases, query construction and validation, and so on. 正如你所见,整个智能体 AI 生态系统的一个关键方面就是工具化——你的智能体需要能够访问各种工具,以便有效地完成大语言模型核心功能之外的任务。这些工具可以有各种形式——在当今的商业环境中,很多是数据检索和组织工具、图数据库、RAG 知识库、查询构建与验证工具等等。

Why Classical ML

为什么选择传统机器学习

However, I want to remind you that classical ML models can also be really valuable tools for your agent. Take it a step further than just calling rudimentary tooling, and give your AI agent models to use! For example, consider an agent designed for real estate analysis. If you want to find out the appropriate market price for a property, give your agent the address. It can use one API retrieval tool to retrieve details about the property, then pass those formatted details to a regression model that generates a price estimate. 然而,我想提醒你,传统机器学习模型也可以成为你智能体非常有价值的工具。与其仅仅调用基础工具,不如更进一步,为你的人工智能智能体提供模型来使用!例如,考虑一个为房地产分析设计的智能体。如果你想了解某处房产的合适市场价格,只需给智能体提供地址。它可以利用一个 API 检索工具获取房产详情,然后将这些格式化后的细节传递给一个回归模型,从而生成价格估算。

Of course, you could theoretically ask the LLM to just estimate the values itself. However, this is questionable and even risky for a number of reasons. 当然,理论上你可以直接让大语言模型自己估算价格。然而,由于多种原因,这种做法值得怀疑,甚至存在风险。

  • Accuracy: An LLM is particularly bad for any task where you need to calculate a meaningful number — it’s guessing, not making an empirical evidence based calculation. A well trained classical ML model is going to be vastly more accurate and trustworthy. 准确性: 大语言模型在任何需要计算具体数值的任务上表现都特别差——它是在“猜测”,而不是基于实证证据进行计算。一个训练有素的传统机器学习模型会准确得多,也更值得信赖。
  • Interpretability: You have minimal interpretability and explainability from the LLM guessing. We know that LLMs tend to be a black box, and this severely restricts your ability to assess the path that it took to get to the estimate you received. With a classical ML model you can identify the decisions made to get to your inference, and validate these against your subject matter expertise. 可解释性: 大语言模型的猜测几乎没有可解释性。我们知道大语言模型往往是一个“黑盒”,这严重限制了你评估其得出估算结果路径的能力。而使用传统机器学习模型,你可以识别得出推论所依据的决策,并根据你的专业知识对这些决策进行验证。
  • Cost: Running an LLM gets expensive very fast. If you have a lot of cases to run on, the token prices will become meaningful quickly. Running a classifier or a regression model is incredibly lightweight and cheap, even at high volumes. Additionally, in an LLM you don’t control the cost of each call, and token usage and spend can increase — we’re seeing that across the tech industry already. 成本: 运行大语言模型的成本增长非常快。如果你有大量的案例需要处理,Token 的费用很快就会变得非常可观。而运行一个分类器或回归模型则极其轻量且廉价,即使在高并发量下也是如此。此外,在大语言模型中,你无法控制每次调用的成本,Token 的使用量和支出可能会增加——我们已经在整个科技行业中看到了这一点。
  • Precision: You don’t control the training or tuning of the LLM (unless you’re fine tuning a foundation model). You might trust the generic LLM to do the job, but you’re taking a big risk, and as mentioned above, validating the work is exceedingly difficult. On the other side, fine tuning a foundation model could be effective, but it requires much more data and more specialized skill than just training a regression or a classifier, while still leaving you with interpretability problems. 精度: 你无法控制大语言模型的训练或微调(除非你是在微调基础模型)。你可能信任通用的模型能完成工作,但这冒着巨大的风险,而且如上所述,验证其工作成果极其困难。另一方面,微调基础模型虽然有效,但它比仅仅训练一个回归模型或分类器需要更多的数据和更专业的技能,同时仍然会让你面临可解释性问题。
  • Control of your data: Your data may be leaving your controlled environment and being accessed by a third party LLM model provider, which can create risk. 数据控制: 你的数据可能会离开你受控的环境,被第三方大语言模型提供商访问,这会带来风险。
  • Control of infrastructure: With an LLM, you don’t have any authority over infrastructure management, so third party downtime creates risk to your business. 基础设施控制: 使用大语言模型时,你对基础设施管理没有任何权限,因此第三方的停机故障会给你的业务带来风险。

Of course, constructing a classical model does require different skills than just setting an LLM on a task. You need to understand your data well, be prepared to complete feature engineering with subject matter expertise, and you need to have sufficient compute and data to train the model. If you have no labeled data, you’ll be limited to unsupervised learning or perhaps bootstrapping your own labels. Fortunately, there’s a wealth of content out there about how to build these models, as well as how to evaluate them rigorously and monitor after deployment. 当然,构建传统模型确实需要与单纯让大语言模型执行任务不同的技能。你需要深入了解数据,准备好利用专业知识完成特征工程,并且需要有足够的计算资源和数据来训练模型。如果你没有标注数据,你将只能局限于无监督学习,或者尝试自己引导生成标签。幸运的是,市面上有大量关于如何构建这些模型,以及如何严格评估它们并在部署后进行监控的内容。

Hooking up your model to your agent

将模型接入你的智能体

You might be convinced to give this a try, but before you start, there are a few architectural choices to consider as well. How will your model and your agent interact? 你可能已经被说服去尝试一下,但在开始之前,还有一些架构选择需要考虑。你的模型和智能体将如何交互?

Direct Calls 直接调用

Perhaps the quickest way to get running is just by letting the agent have the model as a tool to call directly. This is the form of my real estate research tool example: the agent can hit a model for just in time inference based on a prompt. To set this up, your AI agent must be equipped to format its 也许最快的上手方式就是让智能体将模型作为一个可以直接调用的工具。这就是我前面提到的房地产研究工具示例的形式:智能体可以根据提示词调用模型进行即时推理。要实现这一点,你的 AI 智能体必须具备格式化其输出的能力。