用两行代码启动一个具有沙盒执行的自主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进行演示,需要适当的网络配置。该流水线简化了代理的创建和执行,能够自动化各种工作流程。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 用两行代码启动一个具有沙盒执行的自主AI代理 (amaiya.github.io) 6点 由 wiseprobe 49分钟前 | 隐藏 | 过去 | 收藏 | 讨论 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

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