|
15 | 15 | */
|
16 | 16 | package io.serverlessworkflow.fluent.agentic;
|
17 | 17 |
|
18 |
| -import static dev.langchain4j.agentic.internal.AgentExecutor.agentsToExecutors; |
| 18 | +import static dev.langchain4j.agentic.internal.AgentUtil.agentsToExecutors; |
19 | 19 |
|
20 |
| -import dev.langchain4j.agentic.Cognisphere; |
| 20 | +import dev.langchain4j.agentic.cognisphere.Cognisphere; |
21 | 21 | import dev.langchain4j.agentic.internal.AgentExecutor;
|
22 | 22 | import dev.langchain4j.agentic.internal.AgentInstance;
|
23 | 23 | import io.serverlessworkflow.impl.expressions.LoopPredicateIndex;
|
24 | 24 | import java.util.List;
|
| 25 | +import java.util.Map; |
25 | 26 | import java.util.function.Function;
|
26 | 27 | import java.util.function.Predicate;
|
27 | 28 | import java.util.stream.Stream;
|
28 | 29 |
|
29 | 30 | public final class AgentAdapters {
|
| 31 | + |
| 32 | + private static final Cognisphere cognisphere = |
| 33 | + Cognisphere.registry().createEphemeralCognisphere(); |
| 34 | + |
30 | 35 | private AgentAdapters() {}
|
31 | 36 |
|
32 | 37 | public static List<AgentExecutor> toExecutors(Object... agents) {
|
33 |
| - return agentsToExecutors(Stream.of(agents).map(AgentInstance.class::cast).toList()); |
| 38 | + return agentsToExecutors(Stream.of(agents).map(AgentInstance.class::cast).toArray()); |
34 | 39 | }
|
35 | 40 |
|
36 |
| - public static Function<Cognisphere, Object> toFunction(AgentExecutor exec) { |
37 |
| - return exec::invoke; |
| 41 | + public static Function<Object, Object> toFunction(AgentExecutor exec) { |
| 42 | + return o -> { |
| 43 | + if (!(o instanceof Map)) { |
| 44 | + throw new IllegalArgumentException( |
| 45 | + "Expected input to be a Map, but got: " + o.getClass().getCanonicalName()); |
| 46 | + } |
| 47 | + |
| 48 | + Map<String, Object> input = (Map<String, Object>) o; |
| 49 | + String outputName = exec.agentSpecification().outputName(); |
| 50 | + cognisphere.writeStates(input); |
| 51 | + |
| 52 | + Object result = exec.invoke(cognisphere); |
| 53 | + input.put(outputName, result); |
| 54 | + |
| 55 | + return input; |
| 56 | + }; |
38 | 57 | }
|
39 | 58 |
|
40 | 59 | public static LoopPredicateIndex<Object, Object> toWhile(Predicate<Cognisphere> exit) {
|
|
0 commit comments