Skip to content

feat(embabel): Phase 1 + Annotation Extensions — AgentPlatform Injection & Metadata Foundation#317

Merged
jwijgerd merged 8 commits intomainfrom
copilot/feat-agentplatform-injection-metadata
Apr 9, 2026
Merged

feat(embabel): Phase 1 + Annotation Extensions — AgentPlatform Injection & Metadata Foundation#317
jwijgerd merged 8 commits intomainfrom
copilot/feat-agentplatform-injection-metadata

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

  • Explore codebase and understand existing structure
  • Extend @AgenticAggregateInfo with agentHandledCommands, agentHandledEvents, agentProducedErrors
  • Add getAgentPlatform() to AgenticAggregateRuntime interface
  • Update KafkaAgenticAggregateRuntime to store and expose AgentPlatform
  • Create AgentProcessResultTranslator utility class
  • Create AgenticCommandHandlerFunctionAdapter (implements CommandHandlerFunction)
  • Create AgenticEventHandlerFunctionAdapter (implements EventHandlerFunction)
  • Update AgenticAggregateRuntimeFactory to wire AgentPlatform, resolve Agent, register adapters
  • Address review: Objects.requireNonNull for all 4 KafkaAgenticAggregateRuntime constructor params
  • Address review: AgentProcessResultTranslator filters unknown ErrorEvents (warning + exclude) to prevent NPE in processDomainEvent()
  • Address review: adapters use instanceof MemoryAwareState guard instead of hard S extends MemoryAwareState bound
  • Fix agentProducedErrors Javadoc to accurately describe exclusion behavior
  • Address review: AgenticCommandHandlerFunctionAdapter.apply() now uses the same defensive tick limit (10,000 ticks / 30s deadline) as AgenticEventHandlerFunctionAdapter; throws IllegalStateException on timeout with a structured error log
  • AgentProcessResultTranslatorTest — 8 tests for event draining and unknown-error filtering
  • 4 null-check constructor tests in KafkaAgenticAggregateRuntimeTest
  • All 44 agentic tests pass

Copilot AI and others added 2 commits April 8, 2026 17:06
…adata foundation

- Extend @AgenticAggregateInfo with agentHandledCommands, agentHandledEvents, agentProducedErrors
- Add AgentPlatform getAgentPlatform() to AgenticAggregateRuntime interface
- Store/expose AgentPlatform in KafkaAgenticAggregateRuntime (new constructor param)
- Create AgentProcessResultTranslator utility (drain DomainEvents from Blackboard)
- Create AgenticCommandHandlerFunctionAdapter (CommandHandlerFunction via Embabel Agent)
- Create AgenticEventHandlerFunctionAdapter (EventHandlerFunction via Embabel Agent)
- Update AgenticAggregateRuntimeFactory: resolve AgentPlatform (fail-fast), resolve Agent
  by '{aggregateName}Agent' bean convention, register adapters for agentHandledCommands/Events,
  register DomainEventType(error=true) for agentProducedErrors
- Update KafkaAgenticAggregateRuntimeTest for new constructor + add getAgentPlatform test
- Add 9 new annotation tests for the 3 new @AgenticAggregateInfo properties

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/88dfa45b-d88a-42e2-9027-be4b23fea52d

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
…ervicesSupplier, clarify tick loop intent

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/88dfa45b-d88a-42e2-9027-be4b23fea52d

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add AgentPlatform injection and metadata foundation for phase 1 feat(embabel): Phase 1 + Annotation Extensions — AgentPlatform Injection & Metadata Foundation Apr 8, 2026
Copilot AI requested a review from jwijgerd April 8, 2026 17:11
@jwijgerd jwijgerd marked this pull request as ready for review April 8, 2026 19:39
Copilot AI review requested due to automatic review settings April 8, 2026 19:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces Phase 1 Embabel integration for agentic aggregates by injecting AgentPlatform into the agentic runtime and adding adapter infrastructure to route selected commands/events through Embabel agent processes.

Changes:

  • Extend @AgenticAggregateInfo with metadata for agent-handled commands/events and agent-produced errors, plus tests for default/configured values.
  • Inject and expose AgentPlatform via AgenticAggregateRuntime / KafkaAgenticAggregateRuntime, and resolve it in AgenticAggregateRuntimeFactory.
  • Add Embabel adapter implementations (AgenticCommandHandlerFunctionAdapter, AgenticEventHandlerFunctionAdapter) and a result translator (AgentProcessResultTranslator) to run agent processes and collect emitted DomainEvents.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
main/api/src/test/java/org/elasticsoftware/akces/aggregate/AgenticAggregateInfoTest.java Adds test fixtures/assertions for the new @AgenticAggregateInfo array properties.
main/api/src/main/java/org/elasticsoftware/akces/annotations/AgenticAggregateInfo.java Extends the annotation with agentHandledCommands, agentHandledEvents, agentProducedErrors metadata + Javadoc.
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/KafkaAgenticAggregateRuntimeTest.java Updates unit tests for new constructor arg and getAgentPlatform() exposure.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/KafkaAgenticAggregateRuntime.java Stores/exposes AgentPlatform on the runtime wrapper.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/AgentProcessResultTranslator.java New utility to drain DomainEvents from Embabel blackboard and hide them.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/AgenticEventHandlerFunctionAdapter.java New adapter to run Embabel agent process for external event handling.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/AgenticCommandHandlerFunctionAdapter.java New adapter to run Embabel agent process for command handling.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/beans/AgenticAggregateRuntimeFactory.java Registers agent-handled command/event adapters and resolves AgentPlatform/Agent beans.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/AgenticAggregateRuntime.java Extends the runtime interface with getAgentPlatform().

Comment on lines +38 to +40
* <p>Undeclared {@link ErrorEvent} instances are accepted at runtime. A warning is
* logged so operators can detect unexpected error types without causing the transaction
* to abort.
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class-level Javadoc says undeclared ErrorEvent instances are accepted without aborting the transaction, but the Akces runtime requires emitted events to have a registered DomainEventType (otherwise processing will fail with null dereferences). If the intent is to accept unknown error types, the runtime/registration logic needs to handle that; otherwise this Javadoc should be corrected to avoid promising behavior that isn't supported.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure that the runtime handles the case of unknown ErrorEvent types

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 68f371b. AgentProcessResultTranslator.collectEvents() now accepts the set of registered DomainEventTypes and excludes any ErrorEvent whose class isn't registered — logging a WARN and hiding the event from the blackboard so it won't be collected again. This prevents the NPE in KafkaAggregateRuntime.processDomainEvent() that would occur when getDomainEventType() returns null. Eight new tests in AgentProcessResultTranslatorTest cover both the inclusion and exclusion paths.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines +38 to +40
* <p>Undeclared {@link ErrorEvent} instances are accepted at runtime. A warning is
* logged so operators can detect unexpected error types without causing the transaction
* to abort.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure that the runtime handles the case of unknown ErrorEvent types

…rorEvent handling, MemoryAwareState guard

- KafkaAgenticAggregateRuntime: add Objects.requireNonNull for all 4 constructor params
- AgentProcessResultTranslator: accept registeredEventTypes param; exclude unknown ErrorEvents
  with WARN log instead of passing them to processDomainEvent() where they would NPE
- Both adapter apply() methods: use instanceof MemoryAwareState guard instead of requiring
  S extends MemoryAwareState bound; pass getAllRegisteredEventTypes() to translator
- Fix @AgenticAggregateInfo.agentProducedErrors() Javadoc to accurately describe exclusion
- Add AgentProcessResultTranslatorTest (8 tests) covering all event/error scenarios
- Add 4 constructor null-check tests to KafkaAgenticAggregateRuntimeTest

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/d56d40b0-ba4b-4381-8b08-568d5b4098e2

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
// Timeout configuration and incremental tick support are deferred to a later phase
// (see plans/agenttasks.md). The transaction timeout is controlled externally via
// the 'akces.agentic.transaction-timeout-ms' property on the producer factory.
while (!agentProcess.getFinished()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implement the same defensice limit as in the AgenticEventHandlerFunctionAdapter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 77c35e5. AgenticCommandHandlerFunctionAdapter.apply() now uses the same 10,000-tick / 30-second deadline loop as the event handler adapter, and throws IllegalStateException with a structured error log if the process doesn't finish within those limits.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment on lines +157 to +162
// Tick to completion. Phase 1 runs the full agent process synchronously.
// Timeout configuration and incremental tick support are deferred to a later phase
// (see plans/agenttasks.md). The transaction timeout is controlled externally via
// the 'akces.agentic.transaction-timeout-ms' property on the producer factory.
while (!agentProcess.getFinished()) {
agentProcess.tick();
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while (!agentProcess.getFinished()) { agentProcess.tick(); } has no timeout / max-tick guard, so a stuck agent can block command handling indefinitely (tying up Kafka consumer/transaction threads). Please add the same kind of safety limits used in AgenticEventHandlerFunctionAdapter (max ticks + wall-clock timeout and/or interruption handling), and surface a deterministic error outcome when limits are exceeded.

Suggested change
// Tick to completion. Phase 1 runs the full agent process synchronously.
// Timeout configuration and incremental tick support are deferred to a later phase
// (see plans/agenttasks.md). The transaction timeout is controlled externally via
// the 'akces.agentic.transaction-timeout-ms' property on the producer factory.
while (!agentProcess.getFinished()) {
agentProcess.tick();
final int maxTicks = 10_000;
final long timeoutNanos = 30_000_000_000L;
final long startNanos = System.nanoTime();
int ticks = 0;
while (!agentProcess.getFinished()) {
if (Thread.currentThread().isInterrupted()) {
String message = "Agent process interrupted while handling command %s for aggregate %s"
.formatted(commandType.typeName(), aggregate.getClass().getSimpleName());
logger.warn(message);
throw new IllegalStateException(message);
}
if (ticks >= maxTicks) {
String message = "Agent process exceeded max ticks (%d) while handling command %s for aggregate %s"
.formatted(maxTicks, commandType.typeName(), aggregate.getClass().getSimpleName());
logger.warn(message);
throw new IllegalStateException(message);
}
if (System.nanoTime() - startNanos >= timeoutNanos) {
String message = "Agent process exceeded timeout (%d ms) while handling command %s for aggregate %s"
.formatted(timeoutNanos / 1_000_000L, commandType.typeName(), aggregate.getClass().getSimpleName());
logger.warn(message);
throw new IllegalStateException(message);
}
agentProcess.tick();
ticks++;

Copilot uses AI. Check for mistakes.
… matching EventHandlerFunctionAdapter

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/2d9121bb-7262-4cfc-b4fd-a41735f4aa01

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI requested a review from jwijgerd April 9, 2026 05:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jwijgerd jwijgerd merged commit f5e20af into main Apr 9, 2026
5 checks passed
@jwijgerd jwijgerd deleted the copilot/feat-agentplatform-injection-metadata branch April 9, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(embabel): Phase 1 + Annotation Extensions — AgentPlatform Injection & Metadata Foundation

3 participants