From 659f4f40a367fa13cac938669a445bd6218a47b7 Mon Sep 17 00:00:00 2001 From: Fu Cheng Date: Thu, 10 Oct 2024 20:03:56 +1300 Subject: [PATCH] update cli --- .github/workflows/publish.yaml | 4 +- bootstrap/src/main/resources/agent.yaml | 49 ------------------- cli/pom.xml | 21 +++----- cli/sample-config/sample-agent.yaml | 28 +++++++++++ cli/src/assembly/cli.xml | 22 --------- .../llmagentbuilder/cli/CliApplication.kt | 10 +--- .../cli/command/BuildCommand.kt | 20 +++++--- .../llmagentbuilder/cli/command/RunCommand.kt | 21 +++++--- 8 files changed, 64 insertions(+), 111 deletions(-) delete mode 100644 bootstrap/src/main/resources/agent.yaml create mode 100644 cli/sample-config/sample-agent.yaml delete mode 100644 cli/src/assembly/cli.xml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 6223beb..0d43161 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -32,7 +32,7 @@ jobs: with: name: cli path: | - cli/target/cli-jar-with-dependencies.jar + cli/target/cli.jar retention-days: 1 - uses: actions/download-artifact@v4 with: @@ -41,7 +41,7 @@ jobs: - name: Rename files run: | mkdir release-files - mv cli-jar-with-dependencies.jar release-files/llm-agent-builder-cli.jar + mv cli.jar release-files/llm-agent-builder-cli.jar - name: Create a Github Release uses: ncipollo/release-action@v1 diff --git a/bootstrap/src/main/resources/agent.yaml b/bootstrap/src/main/resources/agent.yaml deleted file mode 100644 index 889fa1d..0000000 --- a/bootstrap/src/main/resources/agent.yaml +++ /dev/null @@ -1,49 +0,0 @@ -metadata: - name: TestAgent -llm: - openai: - enabled: true -profile: - system: You are a helpful assistant. -memory: - inMemory: - enabled: true -planner: - reActJson: - enabled: true -observation: - enabled: true - tracing: - enabled: true - exporter: - endpoint: "https://api.honeycomb.io/v1/traces" - headers: - "x-honeycomb-team": "{{env.HONEYCOMB_API_KEY}}" - metrics: - enabled: true - exporter: - endpoint: "https://api.honeycomb.io/v1/metrics" - headers: - "x-honeycomb-team": "{{env.HONEYCOMB_API_KEY}}" -tools: - - id: writeLocalFile - config: - basePath: "E:\\file-output" - dependency: - groupId: "io.github.llmagentbuilder" - artifactId: "tool-write-local-file" - version: "0.1.1" - - id: readLocalFile - config: - basePath: "E:\\file-output" - dependency: - groupId: "io.github.llmagentbuilder" - artifactId: "tool-read-local-file" - version: "0.1.1" - - id: extractWebPageContent - config: - sizeLimit: 500 - dependency: - groupId: "io.github.llmagentbuilder" - artifactId: "tool-extract-web-page-content" - version: "0.1.2" \ No newline at end of file diff --git a/cli/pom.xml b/cli/pom.xml index 1595c8e..96fa663 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -76,28 +76,19 @@ + ${project.artifactId} - maven-assembly-plugin - 3.7.1 + org.springframework.boot + spring-boot-maven-plugin + 3.3.4 - cli - - src/assembly/cli.xml - - - - io.github.llmagentbuilder.cli.CliApplicationKt - - - + io.github.llmagentbuilder.cli.CliApplicationKt - make-assembly - package - single + repackage diff --git a/cli/sample-config/sample-agent.yaml b/cli/sample-config/sample-agent.yaml new file mode 100644 index 0000000..4a9f9a5 --- /dev/null +++ b/cli/sample-config/sample-agent.yaml @@ -0,0 +1,28 @@ +metadata: + name: TestAgent +llm: + openai: + enabled: true +profile: + system: You are a helpful assistant. +memory: + inMemory: + enabled: true +planner: + reActJson: + enabled: true +tools: + - id: writeLocalFile + config: + basePath: "file-output" + dependency: + groupId: "io.github.llmagentbuilder" + artifactId: "tool-write-local-file" + version: "0.2.2" + - id: readLocalFile + config: + basePath: "file-input" + dependency: + groupId: "io.github.llmagentbuilder" + artifactId: "tool-read-local-file" + version: "0.2.2" \ No newline at end of file diff --git a/cli/src/assembly/cli.xml b/cli/src/assembly/cli.xml deleted file mode 100644 index 4d80363..0000000 --- a/cli/src/assembly/cli.xml +++ /dev/null @@ -1,22 +0,0 @@ - - jar-with-dependencies - - jar - - false - - - / - true - true - runtime - - - - - metaInf-services - - - \ No newline at end of file diff --git a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/CliApplication.kt b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/CliApplication.kt index e81f3c2..109a72e 100644 --- a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/CliApplication.kt +++ b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/CliApplication.kt @@ -3,7 +3,6 @@ package io.github.llmagentbuilder.cli import io.github.llmagentbuilder.cli.command.BuildCommand import io.github.llmagentbuilder.cli.command.RunCommand import picocli.CommandLine -import java.io.File import kotlin.system.exitProcess @CommandLine.Command( @@ -13,14 +12,7 @@ import kotlin.system.exitProcess description = ["Build LLM agents"], subcommands = [RunCommand::class, BuildCommand::class], ) -class CliApplication { - @CommandLine.Option( - names = ["-c", "--config"], - description = ["agent config file"], - required = true, - ) - lateinit var configFile: File -} +class CliApplication fun main(args: Array): Unit = exitProcess(CommandLine(CliApplication()).execute(*args)) \ No newline at end of file diff --git a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/BuildCommand.kt b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/BuildCommand.kt index c9ae26b..47269af 100644 --- a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/BuildCommand.kt +++ b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/BuildCommand.kt @@ -1,6 +1,5 @@ package io.github.llmagentbuilder.cli.command -import io.github.llmagentbuilder.cli.CliApplication import org.slf4j.LoggerFactory import picocli.CommandLine import java.io.File @@ -13,8 +12,12 @@ enum class BuildOutputType { jar } @CommandLine.Command(name = "build", description = ["Build an agent"]) class BuildCommand : Callable { - @CommandLine.ParentCommand - private val parent: CliApplication? = null + @CommandLine.Option( + names = ["-c", "--config"], + description = ["agent config file"], + required = true, + ) + lateinit var configFile: File @CommandLine.Option( names = ["-type", "--output-type"], @@ -30,14 +33,17 @@ class BuildCommand : Callable { private val logger = LoggerFactory.getLogger(javaClass) - override fun call(): Int? { - val file = parent?.configFile ?: return null - val projectDir = CommandHelper.setupMavenProject(file) + override fun call(): Int { + logger.info( + "Build an agent from config file: {}", + configFile.toPath().normalize().toAbsolutePath() + ) + val projectDir = CommandHelper.setupMavenProject(configFile) val resourcesDir = projectDir.resolve("src").resolve("main").resolve("resources") Files.createDirectories(resourcesDir) Files.copy( - file.toPath(), + configFile.toPath(), resourcesDir.resolve("agent.yaml") ) val args = arrayOf("package") diff --git a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/RunCommand.kt b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/RunCommand.kt index baf5c42..632cb95 100644 --- a/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/RunCommand.kt +++ b/cli/src/main/kotlin/io/github/llmagentbuilder/cli/command/RunCommand.kt @@ -1,22 +1,29 @@ package io.github.llmagentbuilder.cli.command -import io.github.llmagentbuilder.cli.CliApplication import org.slf4j.LoggerFactory import picocli.CommandLine +import java.io.File import java.util.concurrent.Callable @CommandLine.Command(name = "run", description = ["Run an agent"]) class RunCommand : Callable { - @CommandLine.ParentCommand - private val parent: CliApplication? = null + @CommandLine.Option( + names = ["-c", "--config"], + description = ["agent config file"], + required = true, + ) + lateinit var configFile: File private val logger = LoggerFactory.getLogger(javaClass) - override fun call(): Int? { - val file = parent?.configFile ?: return null - val projectDir = CommandHelper.setupMavenProject(file) + override fun call(): Int { + logger.info( + "Run an agent from config file: {}", + configFile.toPath().normalize().toAbsolutePath() + ) + val projectDir = CommandHelper.setupMavenProject(configFile) val configFileArg = - file.toPath().normalize().toAbsolutePath().toString() + configFile.toPath().normalize().toAbsolutePath().toString() val args = arrayOf( "exec:java", "-Dexec.args=\"${configFileArg}\""