chore: Bump version to 1.6.10 and enhance AgentContext and AgentExecutorService with optional agent list handling
This commit is contained in:
@@ -167,6 +167,8 @@ The agentic flow is started with an AgentContext and an initial agent.
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
final var context = new AgentContext(List.of(new Agent1(), new Agent2()));
|
final var context = new AgentContext(List.of(new Agent1(), new Agent2()));
|
||||||
|
// Passing an explicit agent list is optional. If you omit the list, the framework will autowire all Agent beans from the Spring context:
|
||||||
|
// final var context = new AgentContext();
|
||||||
context.getContext().setStringValue("key", "Payload here");
|
context.getContext().setStringValue("key", "Payload here");
|
||||||
context.getContext().setStringValues("key2", List.of("All context keys", "support collections", "for aggregation purposes"));
|
context.getContext().setStringValues("key2", List.of("All context keys", "support collections", "for aggregation purposes"));
|
||||||
context.getContext().setValue("key3", new RandomDatatype());
|
context.getContext().setValue("key3", new RandomDatatype());
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<artifactId>lm-lib</artifactId>
|
<artifactId>lm-lib</artifactId>
|
||||||
<groupId>de.extio</groupId>
|
<groupId>de.extio</groupId>
|
||||||
<name>lm-lib</name>
|
<name>lm-lib</name>
|
||||||
<version>1.6.9</version>
|
<version>1.6.10</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.extio.lmlib.agent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -41,6 +42,12 @@ public final class AgentContext {
|
|||||||
|
|
||||||
private Consumer<AgentContext> agentContextUpdateConsumer;
|
private Consumer<AgentContext> agentContextUpdateConsumer;
|
||||||
|
|
||||||
|
public AgentContext() {
|
||||||
|
this.agents = new HashMap<>();
|
||||||
|
this.context = new ConcurrentHashMap<>();
|
||||||
|
this.requestStatistic = new AgentRequestStatistic();
|
||||||
|
}
|
||||||
|
|
||||||
public AgentContext(final Collection<? extends BaseAgent> agents) {
|
public AgentContext(final Collection<? extends BaseAgent> agents) {
|
||||||
this.agents = agents.stream().collect(Collectors.toMap(BaseAgent::name, agent -> agent));
|
this.agents = agents.stream().collect(Collectors.toMap(BaseAgent::name, agent -> agent));
|
||||||
this.context = new ConcurrentHashMap<>();
|
this.context = new ConcurrentHashMap<>();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.extio.lmlib.agent;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -30,6 +31,9 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ClientService clientService;
|
private ClientService clientService;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private List<BaseAgent> allAgents;
|
||||||
|
|
||||||
private ExecutorService branchExecutorService;
|
private ExecutorService branchExecutorService;
|
||||||
|
|
||||||
private ExecutorService agentExecutorService;
|
private ExecutorService agentExecutorService;
|
||||||
@@ -51,6 +55,7 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<AgentContext> walk(final String firstAgent, final AgentContext context, final Consumer<AgentContext> agentContextUpdateConsumer) {
|
public List<AgentContext> walk(final String firstAgent, final AgentContext context, final Consumer<AgentContext> agentContextUpdateConsumer) {
|
||||||
|
this.discoverAgents(context);
|
||||||
final var agent = context.getAgents().get(firstAgent);
|
final var agent = context.getAgents().get(firstAgent);
|
||||||
if (agent == null) {
|
if (agent == null) {
|
||||||
throw new IllegalArgumentException("Agent not found: " + firstAgent);
|
throw new IllegalArgumentException("Agent not found: " + firstAgent);
|
||||||
@@ -66,6 +71,8 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
|
|||||||
public List<AgentContext> walk(final BaseAgent agent, final AgentContext context, final Consumer<AgentContext> agentContextUpdateConsumer) {
|
public List<AgentContext> walk(final BaseAgent agent, final AgentContext context, final Consumer<AgentContext> agentContextUpdateConsumer) {
|
||||||
LOGGER.debug("Agent: {}", agent.name());
|
LOGGER.debug("Agent: {}", agent.name());
|
||||||
|
|
||||||
|
this.discoverAgents(context);
|
||||||
|
|
||||||
Client client = null;
|
Client client = null;
|
||||||
if (agent.agentType(context) != AgentType.PROCESSING_ONLY) {
|
if (agent.agentType(context) != AgentType.PROCESSING_ONLY) {
|
||||||
client = this.clientService.getClient(agent.modelCategory(context));
|
client = this.clientService.getClient(agent.modelCategory(context));
|
||||||
@@ -108,4 +115,14 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
|
|||||||
return responses;
|
return responses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void discoverAgents(final AgentContext context) {
|
||||||
|
if (context.getAgents().isEmpty() && this.allAgents != null) {
|
||||||
|
for (final var agent : this.allAgents) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final var agentsMap = (Map<String, BaseAgent>) context.getAgents();
|
||||||
|
agentsMap.put(agent.name(), agent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user