Skip to content

Add built-in AssignTask command and AgentTaskAssigned event for AgenticAggregate#329

Merged
jwijgerd merged 6 commits intomainfrom
copilot/add-assign-task-command
Apr 10, 2026
Merged

Add built-in AssignTask command and AgentTaskAssigned event for AgenticAggregate#329
jwijgerd merged 6 commits intomainfrom
copilot/add-assign-task-command

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

Adds framework-level task assignment to agentic aggregates. An AssignTask command creates an Embabel AgentProcess and emits an AgentTaskAssigned event carrying the process ID and requesting party info.

api module — core types

  • RequestingParty — sealed interface with AgentRequestingParty and HumanRequestingParty record permits. Jackson @JsonTypeInfo/@JsonSubTypes for polymorphic serde. Each variant carries a String role.
  • HumanRequestingParty — carries only userId and role (no display name, for GDPR compliance)
  • TaskAwareState — mirrors MemoryAwareState pattern: withAssignedTask() / withoutAssignedTask() immutable updates
  • AssignedTask — record holding agentProcessId, taskDescription, requestingParty, taskMetadata, assignedAt

agentic module — command, event, handler

  • AssignTaskCommand — first framework-owned Command. Fields: agenticAggregateId, taskDescription, requestingParty, taskMetadata
  • AgentTaskAssignedEvent — includes agentProcessId from AgentProcess.getId(), linking Akces domain to Embabel runtime
  • KafkaAgenticAggregateRuntime.builtInCommandHandler() — static factory method returning a CommandHandlerFunction that resolves the agent from the platform, creates an AgentProcess, and emits the event (follows the same single-dispatch pattern as the built-in event handlers)

Registration (follows existing memory event pattern)

  • AgenticAggregateRuntimeASSIGN_TASK_COMMAND_TYPE and AGENT_TASK_ASSIGNED_TYPE constants
  • AgenticAggregateRuntimeFactory — wires builtInCommandHandler() + unified event-sourcing handler for all built-in events
  • AkcesAgenticAggregateControllerBUILTIN_COMMAND_TYPES list added; registerBuiltinSchemas() registers command schemas with forceRegisterOnIncompatible flag support (read from akces.aggregate.schemas.forceRegister environment property, matching AkcesAggregateController behaviour)
  • KafkaAgenticAggregateRuntimehandleBuiltInEvent() unified static single-dispatch handler for MemoryStoredEvent, MemoryRevokedEvent, and AgentTaskAssignedEvent (renamed from handleMemoryEvent)

Usage sketch

// State implements TaskAwareState
record MyAgentState(String id, List<AssignedTask> assignedTasks, ...)
        implements AggregateState, TaskAwareState, MemoryAwareState { ... }

// Send from client
var cmd = new AssignTaskCommand("agg-1", "Analyze quarterly data",
        new HumanRequestingParty("user-42", "analyst"),
        Map.of("priority", "high"));
client.send("DEFAULT_TENANT", cmd);

// Framework handles: creates AgentProcess → emits AgentTaskAssignedEvent → updates state

Tests

  • api: RequestingPartySerializationTest (sealed type, annotations, pattern matching), TaskAwareStateTest
  • agentic: AssignTaskCommandHandlerTest (mocked AgentPlatform/AgentProcess via builtInCommandHandler), TaskEventSourcingTest, AssignTaskTypeConstantsTest

Copilot AI and others added 3 commits April 10, 2026 11:06
Created plans/assign-task/assign-task-plan.md with 5-phase design:
- Phase 1: RequestingParty sealed interface (api module)
- Phase 2: AssignTaskCommand and AgentTaskAssignedEvent (agentic module)
- Phase 3: Built-in handlers and registration (agentic module)
- Phase 4: TaskAwareState interface and AssignedTask record (api module)
- Phase 5: Integration tests

GitHub Issues: #322-#327 (tracking issue: #327)

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/2c3e5400-d2cc-4fed-a03e-b7478d7dcc71

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
…icAggregate

Phase 1: RequestingParty sealed interface with AgentRequestingParty and HumanRequestingParty (api module)
Phase 2: AssignTaskCommand and AgentTaskAssignedEvent with type constants (agentic module)
Phase 3: AssignTaskCommandHandler, event-sourcing handler, factory registration, controller schema registration
Phase 4: AssignedTask record and TaskAwareState interface (api module)

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/b6306087-e325-41fe-9b0f-63e42ac8bd4b

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
API module tests:
- RequestingPartySerializationTest: sealed interface, annotations, equality, pattern matching
- TaskAwareStateTest: AssignedTask record, TaskAwareState interface contract

Agentic module tests:
- AssignTaskCommandHandlerTest: handler creates AgentProcess, emits event, error cases
- TaskEventSourcingTest: event-sourcing handler updates TaskAwareState, dispatch, sequences
- AssignTaskTypeConstantsTest: type registration constant verification

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/b6306087-e325-41fe-9b0f-63e42ac8bd4b

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
@jwijgerd jwijgerd marked this pull request as ready for review April 10, 2026 12:02
Copilot AI review requested due to automatic review settings April 10, 2026 12:02
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

Adds framework-level task assignment for AgenticAggregate by introducing a built-in AssignTask command that creates an Embabel AgentProcess and emits an AgentTaskAssigned event, plus API-level types for tracking requesting party and assigned tasks in state.

Changes:

  • Introduces RequestingParty (sealed) + AssignedTask + TaskAwareState in api with accompanying unit tests.
  • Adds built-in AssignTaskCommand / AgentTaskAssignedEvent, registers their types/schemas, and wires built-in command + event-sourcing handlers in the agentic runtime.
  • Adds agentic unit tests for type constants, command handler behavior, and task event-sourcing.

Reviewed changes

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

Show a summary per file
File Description
plans/assign-task/assign-task-plan.md Design/implementation plan for built-in task assignment support
main/api/src/main/java/org/elasticsoftware/akces/aggregate/RequestingParty.java Sealed requesting-party abstraction with Jackson polymorphic annotations
main/api/src/main/java/org/elasticsoftware/akces/aggregate/AgentRequestingParty.java Agent requesting-party record
main/api/src/main/java/org/elasticsoftware/akces/aggregate/HumanRequestingParty.java Human requesting-party record
main/api/src/main/java/org/elasticsoftware/akces/aggregate/AssignedTask.java Record to persist assigned task info in aggregate state
main/api/src/main/java/org/elasticsoftware/akces/aggregate/TaskAwareState.java State contract for tracking assigned tasks
main/api/src/test/java/org/elasticsoftware/akces/aggregate/RequestingPartySerializationTest.java Tests for sealed type shape + Jackson annotation presence
main/api/src/test/java/org/elasticsoftware/akces/aggregate/TaskAwareStateTest.java Tests for TaskAwareState contract + AssignedTask usage
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/commands/AssignTaskCommand.java Built-in command definition + schema metadata
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/events/AgentTaskAssignedEvent.java Built-in event definition + schema metadata
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/AgenticAggregateRuntime.java Registers built-in command/event type constants
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/AssignTaskCommandHandler.java Built-in handler creating AgentProcess and emitting assignment event
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/KafkaAgenticAggregateRuntime.java Built-in event-sourcing handler to update TaskAwareState
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/beans/AgenticAggregateRuntimeFactory.java Wires built-in command handler + event-sourcing handler into runtime
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/AkcesAgenticAggregateController.java Registers built-in command schemas in addition to event schemas
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/AssignTaskTypeConstantsTest.java Verifies built-in type constants
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/AssignTaskCommandHandlerTest.java Verifies handler creates AgentProcess and emits correct event
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/TaskEventSourcingTest.java Verifies task event-sourcing handler updates TaskAwareState

import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.ArrayList;
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

java.util.ArrayList is imported but never used in this file. This will fail compilation (unused import). Remove the import or use it if it was intended for new logic.

Suggested change
import java.util.ArrayList;

Copilot uses AI. Check for mistakes.
Comment on lines +285 to +287
@SuppressWarnings({"unchecked", "rawtypes"})
AssignTaskCommandHandler assignTaskHandler = new AssignTaskCommandHandler<>(
(AgenticAggregate) aggregate, agentPlatform, agenticInfo.value());
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

The built-in AssignTask handler is registered using raw types and an unchecked cast (@SuppressWarnings({"unchecked", "rawtypes"}) and (AgenticAggregate) aggregate). This reduces type safety and can hide wiring errors at compile time. Prefer keeping the generic type parameter (e.g., AssignTaskCommandHandler<S> or AssignTaskCommandHandler<? extends AggregateState>) and avoid raw casts where possible.

Suggested change
@SuppressWarnings({"unchecked", "rawtypes"})
AssignTaskCommandHandler assignTaskHandler = new AssignTaskCommandHandler<>(
(AgenticAggregate) aggregate, agentPlatform, agenticInfo.value());
if (!(aggregate instanceof AgenticAggregate<?> agenticAggregate)) {
throw new IllegalStateException("Agentic aggregate runtime requires an AgenticAggregate: "
+ aggregate.getClass().getName());
}
@SuppressWarnings("unchecked")
AgenticAggregate<S> typedAgenticAggregate = (AgenticAggregate<S>) agenticAggregate;
AssignTaskCommandHandler<S> assignTaskHandler = new AssignTaskCommandHandler<>(
typedAgenticAggregate, agentPlatform, agenticInfo.value());

Copilot uses AI. Check for mistakes.
Copilot AI and others added 3 commits April 10, 2026 12:52
- Remove displayName from HumanRequestingParty for GDPR (comment #3064274600)
- Replace AssignTaskCommandHandler class with static builtInCommandHandler()
  factory method on KafkaAgenticAggregateRuntime (comment #3064259933)
- Rename handleMemoryEvent to handleBuiltInEvent, merge AgentTaskAssignedEvent
  support into it, remove handleTaskEvent (comment #3064268880)
- Use forceRegisterOnIncompatible flag from environment property instead of
  automatic force-register in registerBuiltinSchemas (comment #3064241901)
- Remove unused ArrayList import from KafkaAgenticAggregateRuntime
- Update all tests for new method signatures and 2-arg HumanRequestingParty

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/83c4f48e-f510-429f-8c85-0f14c17d75d4

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
Copilot AI requested a review from jwijgerd April 10, 2026 12:58
@jwijgerd jwijgerd merged commit 164a8bb into main Apr 10, 2026
7 checks passed
@jwijgerd jwijgerd deleted the copilot/add-assign-task-command branch April 10, 2026 13:09
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.

3 participants