Skip to content

Add AgentTaskFinishedEvent emitted when AgentProcess completes#333

Merged
jwijgerd merged 1 commit into
mainfrom
copilot/add-agent-task-finished-event
Apr 11, 2026
Merged

Add AgentTaskFinishedEvent emitted when AgentProcess completes#333
jwijgerd merged 1 commit into
mainfrom
copilot/add-agent-task-finished-event

Conversation

Copilot AI commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Agent tasks need lifecycle completion tracking. After each tick in the idle-poll cycle, the runtime now checks AgentProcess.getFinished() and emits an AgentTaskFinishedEvent carrying the AgentProcessStatusCode (COMPLETED, FAILED, TERMINATED, KILLED, STUCK). A built-in event-sourcing handler clears the task from TaskAwareState.

Changes

  • New AgentTaskFinishedEvent — record with agentProcessId, AgentProcessStatusCode status, finishedAt
  • AgenticAggregateRuntime — add AGENT_TASK_FINISHED_TYPE constant
  • KafkaAgenticAggregateRuntime
    • onAgentTaskFinished() handler calls TaskAwareState.withoutAssignedTask()
    • handleBuiltInEvent() dispatch updated for new event type
    • resumeNextAgentTask() checks agentProcess.getFinished() post-tick, appends finished event to stream
  • AgenticAggregateRuntimeFactory — registers AGENT_TASK_FINISHED_TYPE with built-in event-sourcing handler

Tick + finish detection in resumeNextAgentTask

Stream<DomainEvent> tickEvents =
        AgentProcessSingleTickRunner.tick(agentProcess, delegate.getAllDomainEventTypes());

if (agentProcess.getFinished()) {
    AgentTaskFinishedEvent finishedEvent = new AgentTaskFinishedEvent(
            state.getAggregateId(),
            task.agentProcessId(),
            agentProcess.getStatus(),
            Instant.now());
    tickEvents = Stream.concat(tickEvents, Stream.of(finishedEvent));
}

delegate.processDomainEvents(tickEvents, task.agentProcessId(), ...);

…inish-check logic

- Create AgentTaskFinishedEvent record with agentProcessId, AgentProcessStatusCode, and finishedAt
- Add AGENT_TASK_FINISHED_TYPE constant to AgenticAggregateRuntime interface
- Add onAgentTaskFinished handler that removes the task from TaskAwareState
- Update handleBuiltInEvent dispatch to route AgentTaskFinishedEvent
- Register AGENT_TASK_FINISHED_TYPE in AgenticAggregateRuntimeFactory
- Check agentProcess.getFinished() after each tick in resumeNextAgentTask
- Add comprehensive unit tests for event-sourcing and finish detection

Agent-Logs-Url: https://github.com/elasticsoftwarefoundation/akces-framework/sessions/e33a93e3-5553-4c53-a248-d6cf99a70840

Co-authored-by: jwijgerd <914840+jwijgerd@users.noreply.github.com>
@jwijgerd
jwijgerd marked this pull request as ready for review April 11, 2026 10:47
Copilot AI review requested due to automatic review settings April 11, 2026 10:47

Copilot AI left a comment

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.

Pull request overview

Adds agent-task lifecycle completion tracking to the agentic runtime by emitting a new built-in AgentTaskFinishedEvent when an AgentProcess finishes, and applying a built-in event-sourcing handler to remove the corresponding AssignedTask from TaskAwareState.

Changes:

  • Introduces AgentTaskFinishedEvent (includes process status + finish timestamp).
  • Updates KafkaAgenticAggregateRuntime to emit the finished event after a tick when AgentProcess.getFinished() is true, and to handle the event via built-in dispatch.
  • Registers the new domain event type + built-in event-sourcing handler in AgenticAggregateRuntimeFactory, and adds/updates unit tests around handler dispatch + resume behavior.

Reviewed changes

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

Show a summary per file
File Description
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/events/AgentTaskFinishedEvent.java Adds new built-in domain event for agent task completion.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/AgenticAggregateRuntime.java Adds AGENT_TASK_FINISHED_TYPE constant for runtime registration.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/runtime/KafkaAgenticAggregateRuntime.java Emits finished events post-tick and applies them via built-in event-sourcing handler.
main/agentic/src/main/java/org/elasticsoftware/akces/agentic/beans/AgenticAggregateRuntimeFactory.java Registers finished event type and handler with the runtime builder.
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/TaskEventSourcingTest.java Adds tests for applying/dispatching AgentTaskFinishedEvent and assign→finish reconstruction.
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/ResumeNextAgentTaskTest.java Adds tests ensuring resumeNextAgentTask emits (or doesn’t emit) AgentTaskFinishedEvent.
main/agentic/src/test/java/org/elasticsoftware/akces/agentic/runtime/AssignTaskTypeConstantsTest.java Verifies the new AGENT_TASK_FINISHED_TYPE constant configuration.

@jwijgerd
jwijgerd merged commit 56496ac into main Apr 11, 2026
11 checks passed
@jwijgerd
jwijgerd deleted the copilot/add-agent-task-finished-event branch April 11, 2026 10:56
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