用两行代码启动一个具有沙盒执行的自主AI代理。
Launch an autonomous AI agent with sandboxed execution in 2 lines of code

原始链接: https://amaiya.github.io/onprem/examples_agent.html

## 本地LLM Agent流水线总结 此笔记本演示了使用本地LLM Agent流水线构建自主代理,能够使用各种工具执行复杂任务。该流水线支持基于云(例如OpenAI、Anthropic、Gemini)和本地LLM(例如Ollama、vLLM、llama.cpp),这些LLM支持工具调用。 核心组件`AgentExecutor`启动具有访问9个内置工具(文件操作、shell访问、网络搜索)的代理,这些工具可以被定制或通过用户定义的工具进行扩展。可以通过Docker/Podman进行沙箱化以增强安全性。 示例展示了代理执行诸如构建计算器模块和进行财务分析等任务。财务分析示例重点介绍了定义自定义工具(股票价格获取、波动率计算、收益分析)并使用它们生成综合报告。本地模型的使用通过Ollama进行演示,需要适当的网络配置。该流水线简化了代理的创建和执行,能够自动化各种工作流程。

## Amaiya:使用 Docker 启动 AI 代理 - 批判性分析 一个名为 Amaiya 的新项目声称只需两行代码即可启动具有沙盒执行的自主 AI 代理。然而,Hacker News 社区的初步反应持怀疑态度。虽然这个概念很有趣,但其实现严重依赖于执行 `docker run` 并反复在容器内运行 `pip install`——这种做法被批评为效率低下,并且可以通过预构建的镜像来避免。 讨论强调了便利性和性能之间的权衡,一些人认为构建和维护优化的 Docker 镜像即使付出额外的努力也是值得的。另一些人指出,使用 CI/CD 管道(如 GitHub Actions)可以自动化镜像创建和托管。 核心问题在于,沙盒机制并没有特别的创新,并且依赖于运行时包安装会引入显著的开销。对话还涉及在复杂的企业环境中运行 AI 代理的更广泛挑战,以及对超越简单测试通过的强大验证信号的需求。 几位用户分享了提供类似功能的替代项目。
相关文章

原文

This notebook demonstrates how to use the Agent pipeline from OnPrem.LLM to create autonomous agents that can execute complex tasks using a variety of tools.

The pipeline works with any LiteLLM-supported model that supports tool-calling:

  • Cloud: openai/gpt-5.2-codex, anthropic/claude-sonnet-4-5, gemini/gemini-1.5-pro
  • Local: Ollama (ollama/llama3.1), vLLM (hosted_vllm/), llama.cpp (use OpenAI interface)

For llama.cpp: Use openai/<model_name> (e.g., gpt-oss-120b) as model parameter and then set env variable OPENAI_API_BASE=http://localhost:<port>/v1

The AgentExecutor

The AgentExecutor allows you to launch AI agents to solve various tasks using both cloud and local models. We will use anthropic/claude-sonnet-4-5 (cloud) and glm-4.7-flash (local) for these examples.

By default, the AgentExecutor has access to 9 built-in tools. You remove access to built-in-tools as necessary. You can optionally give the agent access to custom tools, as we’ll illustrate below.

The AgentExecutor is implemented using our coding agent, PatchPal, which you’ll need to install: pip install patchpal.

AgentExecutor supports local models. By default, it will assume the local model supports native function-calling (e.g., gpt-oss-120b). If you use a local model that does not have good native support for function-calling (a.k.a. tool-calling), you can change the agent_type to react. In this example, we will use llama3.1:8b.

Note: The default context window length in Ollama is typically too small for agentic workflows. Depending on the model and task, we recommend inreasing to at least 8192. Reasoning models like gpt-oss:120b may require 32K or 64K.

Custom Tools

You can give the agent custom tools by simply defining them as Python functions or callables.

In this example, we’ll build a financial analysis agent with custom tools.

Let’s first definte the tools, which are based on yfinance.

pip install yfinance

Step 1: Define the custom tools as Python functions