Skip to content

Commit 31c2234

Browse files
authored
Merge pull request #139 from redbus-labs/a2a-reintroduce
A2a comprehensive implementation for adk-core
2 parents 6b6e70c + 52c09ae commit 31c2234

40 files changed

Lines changed: 3732 additions & 20 deletions

A2A_SERVICE_ENHANCEMENTS.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# A2A Service Enhancements
2+
3+
## Overview
4+
5+
This PR enhances the A2A service with console output, session state initialization, and proper unary RPC response handling. These changes enable better observability and fix issues with session state management.
6+
7+
## Key Changes
8+
9+
### 1. Console Output for Observability
10+
11+
Added console output to track A2A requests and responses:
12+
- `🔵 A2A REQUEST RECEIVED` - Shows session ID, agent name, and query
13+
- `🟢 A2A RESPONSE SENT` - Shows session ID, agent name, response length, and preview
14+
15+
### 2. Session State Initialization
16+
17+
Fixed "Context variable not found" errors by initializing required state variables:
18+
- `currentDate` - Current date
19+
- `sourceCityName`, `destinationCityName`, `dateOfJourney` - Empty strings (populated by agent)
20+
- `mriSessionId` - Session ID
21+
- `userMsg` - User query
22+
- `_temp_a2aCallCount`, `_temp_a2aCalls` - A2A tracking variables
23+
24+
### 3. Response Aggregation
25+
26+
Changed from streaming multiple responses to aggregating all events into a single response:
27+
- Required because `sendMessage` is unary RPC, not streaming
28+
- Uses `toList().blockingGet()` to collect all events before sending
29+
- Ensures single `onNext()` call followed by `onCompleted()`
30+
31+
### 4. Session Management
32+
33+
Changed from `InvocationContext` to explicit `Session` object management:
34+
- Get or create session before agent execution
35+
- Ensures session state is properly initialized
36+
- Prevents state-related errors
37+
38+
### 5. Constructor Fix
39+
40+
Fixed `A2aServer` constructor to accept port parameter directly:
41+
- Avoids `IllegalStateException` when calling `server.getPort()` before server starts
42+
- Updated `A2aServerBuilder` to pass port to constructor
43+
- Updated tests accordingly
44+
45+
## Files Modified
46+
47+
1. **A2aService.java** (+169/-38 lines)
48+
- Added console output
49+
- Added session state initialization
50+
- Changed response handling (streaming → unary)
51+
- Changed session management
52+
53+
2. **A2aServer.java** (+1/-1 lines)
54+
- Added port parameter to constructor
55+
56+
3. **A2aServerBuilder.java** (+1/-1 lines)
57+
- Updated to pass port to constructor
58+
59+
4. **A2aServerTest.java** (+2/-2 lines)
60+
- Updated test constructors to pass port
61+
62+
## Testing
63+
64+
✅ All existing tests pass
65+
✅ Console output validated
66+
✅ Session state initialization prevents errors
67+
✅ Unary RPC response handling works correctly
68+
69+
## Impact
70+
71+
- **Observability**: Console output enables easy debugging and validation
72+
- **Reliability**: Session state initialization prevents runtime errors
73+
- **Compatibility**: Proper unary RPC handling ensures client-server compatibility
74+
- **Backward Compatible**: No breaking changes
75+
76+
## Related Changes
77+
78+
This PR works in conjunction with changes in `rae` repository (`a2a_main` branch):
79+
- Client updated to use correct proto package (`com.google.adk.a2a.grpc`)
80+
- Client changed from streaming to unary RPC
81+
- Agents updated with A2A handover tracking
82+
83+
---
84+
85+
**Author**: Sandeep Belgavi
86+
**Date**: January 18, 2026
87+
**Branch**: `a2a`

a2a/pom.xml

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,31 @@
2626
<errorprone.version>2.38.0</errorprone.version>
2727
<truth.version>1.4.4</truth.version>
2828
<junit4.version>4.13.2</junit4.version>
29+
<grpc.version>1.62.2</grpc.version>
2930
</properties>
3031

3132
<dependencies>
33+
<dependency>
34+
<groupId>io.grpc</groupId>
35+
<artifactId>grpc-netty-shaded</artifactId>
36+
<version>${grpc.version}</version>
37+
<scope>runtime</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.grpc</groupId>
41+
<artifactId>grpc-protobuf</artifactId>
42+
<version>${grpc.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.grpc</groupId>
46+
<artifactId>grpc-stub</artifactId>
47+
<version>${grpc.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.google.code.gson</groupId>
51+
<artifactId>gson</artifactId>
52+
<version>2.10.1</version>
53+
</dependency>
3254
<dependency>
3355
<groupId>com.google.adk</groupId>
3456
<artifactId>google-adk</artifactId>
@@ -106,16 +128,95 @@
106128
<version>${truth.version}</version>
107129
<scope>test</scope>
108130
</dependency>
131+
<dependency>
132+
<groupId>org.junit.jupiter</groupId>
133+
<artifactId>junit-jupiter-api</artifactId>
134+
<scope>test</scope>
135+
</dependency>
136+
<dependency>
137+
<groupId>org.mockito</groupId>
138+
<artifactId>mockito-core</artifactId>
139+
<scope>test</scope>
140+
</dependency>
141+
<dependency>
142+
<groupId>org.mockito</groupId>
143+
<artifactId>mockito-junit-jupiter</artifactId>
144+
<scope>test</scope>
145+
</dependency>
146+
<dependency>
147+
<groupId>org.junit.jupiter</groupId>
148+
<artifactId>junit-jupiter-engine</artifactId>
149+
<scope>test</scope>
150+
</dependency>
109151
</dependencies>
152+
110153
<build>
154+
<extensions>
155+
<extension>
156+
<groupId>kr.motd.maven</groupId>
157+
<artifactId>os-maven-plugin</artifactId>
158+
<version>1.7.0</version>
159+
</extension>
160+
</extensions>
111161
<plugins>
112162
<plugin>
113163
<groupId>org.apache.maven.plugins</groupId>
114-
<artifactId>maven-compiler-plugin</artifactId>
115-
<version>3.13.0</version>
164+
<artifactId>maven-surefire-plugin</artifactId>
165+
<version>3.2.5</version>
166+
</plugin>
167+
<plugin>
168+
<groupId>org.apache.maven.plugins</groupId>
169+
<artifactId>maven-failsafe-plugin</artifactId>
170+
<version>3.2.5</version>
171+
<executions>
172+
<execution>
173+
<goals>
174+
<goal>integration-test</goal>
175+
<goal>verify</goal>
176+
</goals>
177+
</execution>
178+
</executions>
179+
</plugin>
180+
<plugin>
181+
<groupId>org.xolstice.maven.plugins</groupId>
182+
<artifactId>protobuf-maven-plugin</artifactId>
183+
<version>0.6.1</version>
116184
<configuration>
117-
<release>${java.version}</release>
185+
<protocArtifact>
186+
com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}
187+
</protocArtifact>
188+
<pluginId>grpc-java</pluginId>
189+
<pluginArtifact>
190+
io.grpc:protoc-gen-grpc-java:1.48.1:exe:${os.detected.classifier}
191+
</pluginArtifact>
118192
</configuration>
193+
<executions>
194+
<execution>
195+
<goals>
196+
<goal>compile</goal>
197+
<goal>compile-custom</goal>
198+
</goals>
199+
</execution>
200+
</executions>
201+
</plugin>
202+
<plugin>
203+
<groupId>org.codehaus.mojo</groupId>
204+
<artifactId>build-helper-maven-plugin</artifactId>
205+
<version>3.2.0</version>
206+
<executions>
207+
<execution>
208+
<phase>generate-sources</phase>
209+
<goals>
210+
<goal>add-source</goal>
211+
</goals>
212+
<configuration>
213+
<sources>
214+
<source>target/generated-sources/protobuf/java</source>
215+
<source>target/generated-sources/protobuf/grpc-java</source>
216+
</sources>
217+
</configuration>
218+
</execution>
219+
</executions>
119220
</plugin>
120221
</plugins>
121222
</build>

0 commit comments

Comments
 (0)