跳到主要内容

Local

CommandLineExecutionEngine 使用本地计算机环境执行给定的命令行代码。 已实现的工具有 CommandLineToolLocalScriptExecutionTool, 适用于 桌面自动化(Desktop Automation)Computer-Use Agent (例如文件管理、应用控制)。你可以用自然语言控制电脑,例如:

  • 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
  • ...
危险

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

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

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

Maven 依赖

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

API

  • CommandLineExecutionEngine
  • CommandLineTool
  • LocalScriptExecutionTool

示例

        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);