Skip to content

Commit

Permalink
feat: add agent executor sample
Browse files Browse the repository at this point in the history
work on #9
  • Loading branch information
bsorrentino committed Jul 17, 2024
1 parent acf32a7 commit d7ddb58
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package org.bsc.langgraph4j;public class AgentExecutorStreamingServer {
}
54 changes: 54 additions & 0 deletions jetty/src/test/java/org/bsc/langgraph4j/DotEnvConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.langchain4j;


import java.io.FileReader;
import java.io.Reader;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

import static java.util.Optional.ofNullable;

public interface DotEnvConfig {

static void load() {

// Search for .env file
Path path = Paths.get(".").toAbsolutePath();

Path filePath = Paths.get( path.toString(), ".env");

for( int i=0; !filePath.toFile().exists(); ++i ) {
path = path.getParent();

filePath = Paths.get(path.toString(), ".env");

if (i == 3) {
throw new RuntimeException("no .env file found!");
}
}

// load .env contents in System.properties
try {
final java.util.Properties properties = new java.util.Properties();

try( Reader r = new FileReader(filePath.toFile())) {
properties.load(r);
}
System.getProperties().putAll(properties);
} catch (Exception e) {
throw new RuntimeException(e);
}
}


static Optional<String> valueOf(String key ) {
String value = System.getenv(key);
if (value == null) {
value = System.getProperty(key);
}
return ofNullable(value);
}


}
23 changes: 23 additions & 0 deletions jetty/src/test/java/org/bsc/langgraph4j/TestTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.langchain4j.agentexecutor;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;

import java.util.Optional;

import static java.lang.String.format;

public class TestTool {
private String lastResult;

Optional<String> lastResult() {
return Optional.ofNullable(lastResult);
}

@Tool("tool for test AI agent executor")
String execTest(@P("test message") String message) {

lastResult = format( "test tool executed: %s", message);
return lastResult;
}
}

0 comments on commit d7ddb58

Please sign in to comment.