主题
本地(Local)
CommandLineExecutionEngine 使用本地计算机环境来执行给定的命令行代码。 它提供了 CommandLineTool 和 LocalScriptExecutionTool 两种已实现工具, 对桌面自动化或Computer-Use 智能体很有用 (如文件管理、应用控制)。你可以用自然语言控制计算机,例如:
set my mac output volume 50list all running applications in my mactell a story and then read it out loudtell 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
CommandLineExecutionEngineCommandLineToolLocalScriptExecutionTool
示例
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);