Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=1.1.0-SNAPSHOT
kestraVersion=1.0.4
kestraVersion=1.1.0-SNAPSHOT
36 changes: 34 additions & 2 deletions src/main/java/io/kestra/plugin/ai/agent/AIAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import dev.langchain4j.rag.query.router.QueryRouter;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.Result;
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Metric;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.executions.metrics.Counter;
import io.kestra.core.models.executions.TaskRun;
import io.kestra.core.models.hierarchies.*;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.OutputFilesInterface;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.models.tasks.Task;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.runners.FilesService;
import io.kestra.core.runners.RunContext;
import io.kestra.core.utils.GraphUtils;
import io.kestra.core.utils.ListUtils;
import io.kestra.plugin.ai.AIUtils;
import io.kestra.plugin.ai.domain.*;
Expand Down Expand Up @@ -351,7 +355,8 @@ public class AIAgent extends Task implements RunnableTask<AIOutput>, OutputFiles
title = "Content retrievers",
description = "Some content retrievers, like WebSearch, can also be used as tools. However, when configured as content retrievers, they will always be used, whereas tools are only invoked when the LLM decides to use them."
)
private Property<List<ContentRetrieverProvider>> contentRetrievers;
@PluginProperty
private List<ContentRetrieverProvider> contentRetrievers;

@Schema(
title = "Agent memory",
Expand All @@ -361,6 +366,31 @@ public class AIAgent extends Task implements RunnableTask<AIOutput>, OutputFiles

private Property<List<String>> outputFiles;

@Override
public AbstractGraph graph(TaskRun taskRun, List<String> values, RelationType relationType) {
GraphTask root = new GraphTask(this, taskRun, values, relationType);

List<CustomGraphNode> nodes = new ArrayList<>();
nodes.add(new CustomGraphNode("provider", provider.getType(), provider));
if (this.tools != null) {
int count = 0;
for (ToolProvider tool : this.tools) {
nodes.add(new CustomGraphNode("tool-" + count++, tool.getType(), tool));
}
}
if (this.contentRetrievers != null) {
int count = 0;
for (ContentRetrieverProvider contentRetriever : this.contentRetrievers) {
nodes.add(new CustomGraphNode("contentRetriever-" + count++, contentRetriever.getType(), contentRetriever));
}
}
if (this.memory != null) {
nodes.add(new CustomGraphNode("memory", memory.getType(), memory));
}

return new CustomGraphCluster(this.id, root, nodes);
}

@Override
public AIOutput run(RunContext runContext) throws Exception {
Map<String, Object> additionalVariables = outputFiles != null ? Map.of(ScriptService.VAR_WORKING_DIR, runContext.workingDir().path(true).toString()) : Collections.emptyMap();
Expand All @@ -385,7 +415,7 @@ public AIOutput run(RunContext runContext) throws Exception {
agent.chatMemory(memory.chatMemory(runContext));
}

List<ContentRetriever> toolContentRetrievers = runContext.render(contentRetrievers).asList(ContentRetrieverProvider.class).stream()
List<ContentRetriever> toolContentRetrievers = ListUtils.emptyOnNull(this.contentRetrievers).stream()
.map(throwFunction(provider -> provider.contentRetriever(runContext)))
.toList();
if (!toolContentRetrievers.isEmpty()) {
Expand Down Expand Up @@ -419,6 +449,8 @@ public AIOutput run(RunContext runContext) throws Exception {
}
}



// output files should all be inside the working directory
private Map<String, URI> gatherOutputFiles(RunContext runContext) throws Exception {
Map<String, URI> outputFiles = new HashMap<>();
Expand Down
Loading