-
Notifications
You must be signed in to change notification settings - Fork 132
docs: restructure AI documentation into .agents and .claude directories #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kabir
wants to merge
1
commit into
a2aproject:main
Choose a base branch
from
kabir:claude-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # EventQueue Architecture - A2A Java SDK | ||
|
|
||
| > **Quick Reference** for event processing, queue management, and task lifecycle | ||
|
|
||
| ## Overview | ||
|
|
||
| The EventQueue architecture guarantees: | ||
| 1. **Events persist BEFORE clients see them** (no unpersisted events visible) | ||
| 2. **Serial processing** eliminates concurrent update race conditions | ||
| 3. **Task state drives queue lifecycle** (fire-and-forget support, late reconnections) | ||
|
|
||
| ## Architecture Diagram | ||
|
|
||
| ``` | ||
| AgentExecutor.execute() [YOUR CODE] | ||
| ↓ | ||
| AgentEmitter → MainQueue.enqueueEvent() | ||
| ↓ | ||
| MainEventBus.submit() [ALL events queue here FIRST] | ||
| ↓ | ||
| MainEventBusProcessor.take() [single background thread] | ||
| ↓ | ||
| 1. TaskStore.save() FIRST ← Persist before visibility | ||
| 2. PushNotificationSender.send() | ||
| 3. MainQueue.distributeToChildren() ← Clients see LAST | ||
| ↓ | ||
| ChildQueue → EventConsumer → ResultAggregator → Client | ||
| ``` | ||
|
|
||
| **Key Insight**: All events flow through a single-threaded processor that persists events BEFORE distributing to clients. | ||
|
|
||
| --- | ||
|
|
||
| ## Core Components | ||
|
|
||
| ### MainEventBus | ||
| **Location**: `server-common/.../events/MainEventBus.java` | ||
|
|
||
| - `@ApplicationScoped` CDI bean - single instance shared by all MainQueues | ||
| - `LinkedBlockingDeque<MainEventBusContext>` - thread-safe centralized queue | ||
| - `submit(taskId, eventQueue, item)` - enqueue events (called by MainQueue) | ||
| - `take()` - blocking consumption (called by MainEventBusProcessor) | ||
|
|
||
| **Guarantees**: Events persist BEFORE distribution, serial processing, push notifications AFTER persistence | ||
|
|
||
| ### MainEventBusProcessor | ||
| **Location**: `server-common/.../events/MainEventBusProcessor.java` | ||
|
|
||
| Single background thread "MainEventBusProcessor" that processes events in order: | ||
| 1. `TaskManager.process(event)` → persist to TaskStore | ||
| 2. `PushNotificationSender.send()` → notifications | ||
| 3. `mainQueue.distributeToChildren()` → clients receive | ||
|
|
||
| **Exception Handling**: Converts `TaskStoreException` to `InternalError` events, continues processing | ||
|
|
||
| ### EventQueue System | ||
| **Location**: `server-common/.../events/EventQueue.java` | ||
|
|
||
| **Queue Types**: | ||
| - **MainQueue**: No local queue - events submit directly to MainEventBus | ||
| - **ChildQueue**: Has local queue for client consumption | ||
|
|
||
| **Characteristics**: Bounded (1000 events), thread-safe, graceful shutdown, hook support | ||
|
|
||
| ### QueueManager | ||
| **Location**: `server-common/.../events/QueueManager.java` | ||
|
|
||
| - `createOrTap(taskId)` → Get existing MainQueue or create new | ||
| - `tap(taskId)` → Create ChildQueue for existing MainQueue | ||
| - **Default**: InMemoryQueueManager (thread-safe ConcurrentHashMap) | ||
| - **Replicated**: ReplicatedQueueManager (Kafka-based) | ||
|
|
||
| ### EventConsumer & ResultAggregator | ||
| **Locations**: `server-common/.../events/EventConsumer.java`, `server-common/.../tasks/ResultAggregator.java` | ||
|
|
||
| **EventConsumer**: Polls queue, returns `Flow.Publisher<Event>`, closes queue on final event | ||
|
|
||
| **ResultAggregator** bridges EventConsumer and DefaultRequestHandler: | ||
| - `consumeAndBreakOnInterrupt()` - Non-streaming (polls until terminal/AUTH_REQUIRED) | ||
| - `consumeAndEmit()` - Streaming (returns Flow.Publisher immediately) | ||
| - `consumeAll()` - Simple consumption | ||
|
|
||
| --- | ||
|
|
||
| ## Key Concepts | ||
|
|
||
| ### Queue Structure | ||
| - MainQueue has NO local queue (events → MainEventBus directly) | ||
| - Only ChildQueues have local queues | ||
| - `MainQueue.dequeueEventItem()` throws `UnsupportedOperationException` | ||
| - `MainQueue.size()` returns `mainEventBus.size()` | ||
| - `ChildQueue.size()` returns local queue size | ||
|
|
||
| ### Terminal Events | ||
| Events that cause polling loop exit: | ||
| - `TaskStatusUpdateEvent` with `isFinal() == true` | ||
| - `Message` (legacy) | ||
| - `Task` with state: COMPLETED, CANCELED, FAILED, REJECTED, UNKNOWN | ||
|
|
||
| ### AUTH_REQUIRED Special Case | ||
| - Returns task to client immediately | ||
| - Agent continues in background | ||
| - Queue stays open, async cleanup | ||
| - Future events update TaskStore | ||
|
|
||
| --- | ||
|
|
||
| ## Deep Dives | ||
|
|
||
| For detailed documentation on specific aspects: | ||
|
|
||
| - **[Queue Lifecycle & Two-Level Protection](eventqueue/LIFECYCLE.md)** | ||
| - THE BIG IDEA: fire-and-forget, late reconnections | ||
| - TaskStateProvider interface and state-driven cleanup | ||
| - Memory management and cleanup modes | ||
|
|
||
| - **[Request Flows](eventqueue/FLOWS.md)** | ||
| - Non-streaming vs streaming flows | ||
| - DefaultRequestHandler orchestration | ||
| - Background cleanup patterns | ||
|
|
||
| - **[Usage Scenarios & Pitfalls](eventqueue/SCENARIOS.md)** | ||
| - Fire-and-forget pattern (TCK) | ||
| - Late resubscription scenarios | ||
| - Tapping and multiple consumers | ||
| - Common mistakes to avoid | ||
|
|
||
| --- | ||
|
|
||
| ## Key Files Reference | ||
|
|
||
| | Component | Path | | ||
| |-----------|------| | ||
| | MainEventBus | `server-common/.../events/MainEventBus.java` | | ||
| | MainEventBusProcessor | `server-common/.../events/MainEventBusProcessor.java` | | ||
| | EventQueue | `server-common/.../events/EventQueue.java` | | ||
| | QueueManager | `server-common/.../events/QueueManager.java` | | ||
| | InMemoryQueueManager | `server-common/.../events/InMemoryQueueManager.java` | | ||
| | EventConsumer | `server-common/.../events/EventConsumer.java` | | ||
| | ResultAggregator | `server-common/.../tasks/ResultAggregator.java` | | ||
| | DefaultRequestHandler | `server-common/.../requesthandlers/DefaultRequestHandler.java` | | ||
| | TaskStateProvider | `server-common/.../tasks/TaskStateProvider.java` | | ||
| | AgentEmitter | `server-common/.../tasks/AgentEmitter.java` | | ||
|
|
||
| --- | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - **Main Architecture**: `AGENTS.md` - High-level system overview | ||
| - **Task Persistence**: See TaskStore exception handling in main docs | ||
| - **Replication**: `extras/queue-manager-replicated/README.md` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| # Request Flows - EventQueue Processing | ||
|
|
||
| > Deep-dive on streaming vs non-streaming request handling | ||
|
|
||
| ## Non-Streaming Flow (`onMessageSend()`) | ||
|
|
||
| **Location**: `DefaultRequestHandler.java` | ||
|
|
||
| ``` | ||
| 1. initMessageSend() | ||
| → Create TaskManager & RequestContext | ||
|
|
||
| 2. queueManager.createOrTap(taskId) | ||
| → Get/create EventQueue (MainQueue or ChildQueue) | ||
|
|
||
| 3. registerAndExecuteAgentAsync() | ||
| → Start AgentExecutor in background thread | ||
|
|
||
| 4. resultAggregator.consumeAndBreakOnInterrupt(consumer) | ||
| → Poll queue until terminal event or AUTH_REQUIRED | ||
| → Blocking wait for events | ||
|
|
||
| 5. cleanup(queue, task, async) | ||
| → Close queue immediately OR in background | ||
|
|
||
| 6. Return Task/Message to client | ||
| ``` | ||
|
|
||
| ### Terminal Events | ||
|
|
||
| Events that cause polling loop exit: | ||
| - `TaskStatusUpdateEvent` with `isFinal() == true` | ||
| - `Message` (legacy) | ||
| - `Task` with state: COMPLETED, CANCELED, FAILED, REJECTED, UNKNOWN | ||
|
|
||
| ### AUTH_REQUIRED Special Case | ||
|
|
||
| **Behavior**: | ||
| - Returns current task to client immediately | ||
| - Agent continues running in background | ||
| - Queue stays open, cleanup happens async | ||
| - Future events update TaskStore | ||
|
|
||
| **Why**: Allows client to handle authentication prompt while agent waits for credentials. | ||
|
|
||
| --- | ||
|
|
||
| ## Streaming Flow (`onMessageSendStream()`) | ||
|
|
||
| **Location**: `DefaultRequestHandler.java` | ||
|
|
||
| ``` | ||
| 1. initMessageSend() | ||
| → Same as non-streaming | ||
|
|
||
| 2. queueManager.createOrTap(taskId) | ||
| → Same | ||
|
|
||
| 3. registerAndExecuteAgentAsync() | ||
| → Same | ||
|
|
||
| 4. resultAggregator.consumeAndEmit(consumer) | ||
| → Returns Flow.Publisher<Event> immediately | ||
| → Non-blocking | ||
|
|
||
| 5. processor() wraps publisher: | ||
| - Validates task ID | ||
| - Adds task to QueueManager | ||
| - Stores push notification config | ||
| - Sends push notifications | ||
|
|
||
| 6. cleanup(queue, task, true) | ||
| → ALWAYS async for streaming | ||
|
|
||
| 7. Return Flow.Publisher<StreamingEventKind> | ||
| ``` | ||
|
|
||
| ### Key Difference | ||
|
|
||
| **Non-Streaming**: Blocks until terminal event, then returns Task/Message | ||
| **Streaming**: Returns Flow.Publisher immediately, client receives events as they arrive | ||
|
|
||
| **Cleanup**: Streaming ALWAYS uses async cleanup (background thread) | ||
|
|
||
| --- | ||
|
|
||
| ## EventConsumer Details | ||
|
|
||
| **Location**: `server-common/.../events/EventConsumer.java` | ||
|
|
||
| **Purpose**: Consumes events from EventQueue and exposes as reactive stream | ||
|
|
||
| **Key Methods**: | ||
| - `consume()` → Returns `Flow.Publisher<Event>` | ||
| - Polls queue with 500ms timeout | ||
| - Closes queue on final event | ||
| - Thread-safe concurrent consumption | ||
|
|
||
| **Usage**: | ||
| ```java | ||
| EventConsumer consumer = new EventConsumer(eventQueue); | ||
| Flow.Publisher<Event> publisher = consumer.consume(); | ||
| // Subscribe to receive events as they arrive | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## ResultAggregator Modes | ||
|
|
||
| **Location**: `server-common/.../tasks/ResultAggregator.java` | ||
|
|
||
| Bridges EventConsumer and DefaultRequestHandler with three consumption modes: | ||
|
|
||
| ### 1. consumeAndBreakOnInterrupt() | ||
|
|
||
| **Used by**: `onMessageSend()` (non-streaming) | ||
|
|
||
| **Behavior**: | ||
| - Polls queue until terminal event or AUTH_REQUIRED | ||
| - Returns `EventTypeAndInterrupt(event, interrupted)` | ||
| - Blocking operation | ||
| - Exits early on AUTH_REQUIRED (interrupted = true) | ||
|
|
||
| **Use Case**: Non-streaming requests that need single final response | ||
|
|
||
| ### 2. consumeAndEmit() | ||
|
|
||
| **Used by**: `onMessageSendStream()` (streaming) | ||
|
|
||
| **Behavior**: | ||
| - Returns all events as `Flow.Publisher<Event>` | ||
| - Non-blocking, immediate return | ||
| - Client subscribes to stream | ||
| - Events delivered as they arrive | ||
|
|
||
| **Use Case**: Streaming requests where client wants all events in real-time | ||
|
|
||
| ### 3. consumeAll() | ||
|
|
||
| **Used by**: `onCancelTask()` | ||
|
|
||
| **Behavior**: | ||
| - Consumes all events from queue | ||
| - Returns first `Message` or final `Task` found | ||
| - Simple consumption without streaming | ||
| - Blocks until queue exhausted | ||
|
|
||
| **Use Case**: Task cancellation where final state matters | ||
|
|
||
| --- | ||
|
|
||
| ## Flow Comparison Table | ||
|
|
||
| | Aspect | Non-Streaming | Streaming | | ||
| |--------|---------------|-----------| | ||
| | **ResultAggregator Mode** | consumeAndBreakOnInterrupt | consumeAndEmit | | ||
| | **Return Type** | Task/Message | Flow.Publisher | | ||
| | **Blocking** | Yes (until terminal event) | No (immediate return) | | ||
| | **Cleanup** | Immediate or async | Always async | | ||
| | **AUTH_REQUIRED** | Early exit, return task | Continue streaming | | ||
| | **Use Case** | Simple request/response | Real-time event updates | | ||
|
|
||
| --- | ||
|
|
||
| ## Cleanup Integration | ||
|
|
||
| ### Non-Streaming Cleanup Decision | ||
|
|
||
| ```java | ||
| if (event instanceof Message || isFinalEvent(event)) { | ||
| if (!interrupted) { | ||
| cleanup(queue, task, false); // Immediate: wait for agent, close queue | ||
| } else { | ||
| cleanup(queue, task, true); // Async: close in background (AUTH_REQUIRED case) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| **Logic**: | ||
| - Terminal event + not interrupted → Immediate cleanup (wait for agent, close queue) | ||
| - Terminal event + interrupted (AUTH_REQUIRED) → Async cleanup (agent still running) | ||
|
|
||
| ### Streaming Cleanup | ||
|
|
||
| ```java | ||
| cleanup(queue, task, true); // ALWAYS async for streaming | ||
| ``` | ||
|
|
||
| **Logic**: Streaming always uses async cleanup because: | ||
| - Publisher already returned to client | ||
| - Events may still be processing | ||
| - Queue cleanup happens in background | ||
|
|
||
| --- | ||
|
|
||
| ## Thread Model | ||
|
|
||
| ### Agent Execution Thread | ||
| - `CompletableFuture.runAsync(agentExecutor::execute, executor)` | ||
| - Agent runs in background thread pool | ||
| - Enqueues events to MainQueue | ||
|
|
||
| ### MainEventBusProcessor Thread | ||
| - Single background thread: "MainEventBusProcessor" | ||
| - Processes events from MainEventBus | ||
| - Persists to TaskStore, distributes to ChildQueues | ||
|
|
||
| ### Consumer Thread | ||
| - Non-streaming: Request handler thread (blocking) | ||
| - Streaming: Subscriber thread (reactive) | ||
| - Polls ChildQueue for events | ||
|
|
||
| ### Cleanup Thread | ||
| - Async cleanup: Background thread pool | ||
| - Immediate cleanup: Request handler thread | ||
|
|
||
| --- | ||
|
|
||
| ## Related Documentation | ||
|
|
||
| - **[Main Overview](../EVENTQUEUE.md)** - Architecture and components | ||
| - **[Lifecycle](LIFECYCLE.md)** - Queue lifecycle and cleanup | ||
| - **[Scenarios](SCENARIOS.md)** - Real-world usage patterns | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic presented in "Non-Streaming Cleanup Decision" for choosing between immediate and async cleanup doesn't directly map to the implementation in
DefaultRequestHandler.java. The actual cleanup is initiated viacleanupProducerin afinallyblock and is always asynchronous. The decision logic in the documentation could be confusing for developers trying to trace the code. It would be beneficial to clarify that this is a conceptual model or align it more closely with the implementation.