chore: Bump version to 1.6.10 and enhance AgentContext and AgentExecutorService with optional agent list handling

This commit is contained in:
extio-de
2025-09-14 11:29:48 +02:00
parent 5c3c89b580
commit 47b63dcb40
4 changed files with 33 additions and 7 deletions

View File

@@ -167,6 +167,8 @@ The agentic flow is started with an AgentContext and an initial agent.
Example:
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().setStringValues("key2", List.of("All context keys", "support collections", "for aggregation purposes"));
context.getContext().setValue("key3", new RandomDatatype());

View File

@@ -4,7 +4,7 @@
<artifactId>lm-lib</artifactId>
<groupId>de.extio</groupId>
<name>lm-lib</name>
<version>1.6.9</version>
<version>1.6.10</version>
<properties>
<java.version>21</java.version>

View File

@@ -3,6 +3,7 @@ package de.extio.lmlib.agent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -41,6 +42,12 @@ public final class AgentContext {
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) {
this.agents = agents.stream().collect(Collectors.toMap(BaseAgent::name, agent -> agent));
this.context = new ConcurrentHashMap<>();

View File

@@ -3,6 +3,7 @@ package de.extio.lmlib.agent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -30,6 +31,9 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
@Autowired
private ClientService clientService;
@Autowired(required = false)
private List<BaseAgent> allAgents;
private ExecutorService branchExecutorService;
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) {
this.discoverAgents(context);
final var agent = context.getAgents().get(firstAgent);
if (agent == null) {
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) {
LOGGER.debug("Agent: {}", agent.name());
this.discoverAgents(context);
Client client = null;
if (agent.agentType(context) != AgentType.PROCESSING_ONLY) {
client = this.clientService.getClient(agent.modelCategory(context));
@@ -108,4 +115,14 @@ public class AgentExecutorService implements InitializingBean, DisposableBean {
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);
}
}
}
}