Skip to content
LangChain4j 文档版本 1.22.0 源快照 a1accdc7 更新于 2026-10-14

本地(Local)

CommandLineExecutionEngine 使用本地计算机环境来执行给定的命令行代码。 它提供了 CommandLineTool 和 LocalScriptExecutionTool 两种已实现工具, 对桌面自动化或Computer-Use 智能体很有用 (如文件管理、应用控制)。你可以用自然语言控制计算机,例如:

  • set my mac output volume 50
  • list all running applications in my mac
  • tell a story and then read it out loud
  • tell a story about moon and save it into a text file
  • ...

DANGER

⚠️ 安全警告:高风险代码执行

注意!在生产在线服务环境中执行代码可能是危险的。 若用于在线服务,必须在安全沙箱环境中执行。

❗ 请勿在生产环境中使用!

Maven 依赖

xml
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-community-code-execution-engine-local</artifactId>
    <version>${latest version here}</version>
</dependency>

API

  • CommandLineExecutionEngine
  • CommandLineTool
  • LocalScriptExecutionTool

示例

java
        LocalScriptExecutionTool tool = new LocalScriptExecutionTool();

        Assistant assistant = AiServices.builder(Assistant.class)
                .chatModel(model)
                .tools(tool)
                .chatMemory(MessageWindowChatMemory.withMaxMessages(10))
                .build();

        String answer = assistant.chat("list all running applications in my mac");
        System.out.println(answer);

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。