Skip to content

Commit 7e0e216

Browse files
google-genai-botcopybara-github
authored andcommitted
test: run the Gemini integration test against Vertex AI
- The test now runs on Vertex AI, gated on GOOGLE_CLOUD_PROJECT and ADK_RUN_INTEGRATION_TESTS and using Application Default Credentials instead of GOOGLE_API_KEY. - The model defaults to gemini-3.8-flash and can be overridden with the GEMINI_MODEL environment variable. PiperOrigin-RevId: 1005520773
1 parent 84bae34 commit 7e0e216

2 files changed

Lines changed: 86 additions & 26 deletions

File tree

‎contrib/spring-ai/README.md‎

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ To use ADK Java with the Spring AI integration in your application, add the foll
4444
Add the Spring AI provider dependencies for the AI services you want to use:
4545

4646
**OpenAI:**
47+
4748
```xml
4849
<dependency>
4950
<groupId>org.springframework.ai</groupId>
@@ -52,6 +53,7 @@ Add the Spring AI provider dependencies for the AI services you want to use:
5253
```
5354

5455
**Anthropic (Claude):**
56+
5557
```xml
5658
<dependency>
5759
<groupId>org.springframework.ai</groupId>
@@ -60,6 +62,7 @@ Add the Spring AI provider dependencies for the AI services you want to use:
6062
```
6163

6264
**Google Gemini:**
65+
6366
```xml
6467
<dependency>
6568
<groupId>org.springframework.ai</groupId>
@@ -68,6 +71,7 @@ Add the Spring AI provider dependencies for the AI services you want to use:
6871
```
6972

7073
**Vertex AI:**
74+
7175
```xml
7276
<dependency>
7377
<groupId>org.springframework.ai</groupId>
@@ -76,6 +80,7 @@ Add the Spring AI provider dependencies for the AI services you want to use:
7680
```
7781

7882
**Azure OpenAI:**
83+
7984
```xml
8085
<dependency>
8186
<groupId>org.springframework.ai</groupId>
@@ -84,6 +89,7 @@ Add the Spring AI provider dependencies for the AI services you want to use:
8489
```
8590

8691
**Ollama (Local models):**
92+
8793
```xml
8894
<dependency>
8995
<groupId>org.springframework.ai</groupId>
@@ -356,13 +362,15 @@ adk-spring-ai/
356362
The main adapter class that implements `BaseLlm` and wraps Spring AI `ChatModel` and `StreamingChatModel` instances.
357363

358364
**Key Features:**
365+
359366
- Supports both blocking and streaming chat models
360367
- Reactive API using RxJava3 Flowable
361368
- Comprehensive error handling and observability
362369
- Token usage tracking
363370
- Multiple constructor overloads for different scenarios
364371

365372
**Usage:**
373+
366374
```java
367375
// With ChatModel only
368376
SpringAI springAI = new SpringAI(chatModel, "claude-sonnet-4-6");
@@ -379,6 +387,7 @@ SpringAI springAI = new SpringAI(chatModel, "claude-sonnet-4-6", observabilityCo
379387
Handles conversion between ADK's `Content`/`Part` format and Spring AI's `Message`/`ChatResponse` format.
380388

381389
**Key Features:**
390+
382391
- Converts ADK `LlmRequest` to Spring AI `Prompt`
383392
- Converts Spring AI `ChatResponse` to ADK `LlmResponse`
384393
- Supports system, user, and assistant messages
@@ -387,6 +396,7 @@ Handles conversion between ADK's `Content`/`Part` format and Spring AI's `Messag
387396
- Streaming response detection and partial response handling
388397

389398
**Message Type Mapping:**
399+
390400
- ADK `Content` with role "user" → Spring AI `UserMessage`
391401
- ADK `Content` with role "model"/"assistant" → Spring AI `AssistantMessage`
392402
- ADK `Content` with role "system" → Spring AI `SystemMessage`
@@ -397,13 +407,15 @@ Handles conversion between ADK's `Content`/`Part` format and Spring AI's `Messag
397407
Converts between ADK tools and Spring AI function calling format.
398408

399409
**Key Features:**
410+
400411
- Converts ADK `BaseTool` to Spring AI `ToolCallback`
401412
- Schema conversion from ADK format to Spring AI JSON schema
402413
- Intelligent argument processing for different provider formats
403414
- **Function Schema Registration:** Properly registers JSON schemas with Spring AI using `inputSchema()` method
404415
- Debug logging for troubleshooting function calling issues
405416

406417
**Function Calling Flow:**
418+
407419
1. ADK `FunctionDeclaration` → Spring AI `FunctionToolCallback`
408420
2. ADK schema → JSON schema string
409421
3. Runtime argument conversion and validation
@@ -414,6 +426,7 @@ Converts between ADK tools and Spring AI function calling format.
414426
Wrapper for Spring AI embedding models providing ADK-compatible embedding generation.
415427

416428
**Key Features:**
429+
417430
- Single text and batch text embedding
418431
- Reactive API using RxJava3 Single
419432
- Full EmbeddingRequest/EmbeddingResponse support
@@ -425,45 +438,53 @@ Wrapper for Spring AI embedding models providing ADK-compatible embedding genera
425438
Maps ADK `GenerateContentConfig` to Spring AI `ChatOptions`.
426439

427440
**Supported Configurations:**
441+
428442
- Temperature (Float → Double conversion)
429443
- Max output tokens
430444
- Top-P (Float → Double conversion)
431445
- Stop sequences
432446
- Configuration validation
433447

434448
**Unsupported/Provider-Specific:**
449+
435450
- Top-K (not directly supported by Spring AI)
436451
- Presence/frequency penalties (provider-specific)
437452
- Response schema and MIME type
438453

439454
## Modules
440455

441456
### Core Module
457+
442458
- **Package:** `com.google.adk.models.springai`
443459
- **Purpose:** Main integration classes
444460
- **Key Classes:** `SpringAI`, `MessageConverter`, `ToolConverter`, `ConfigMapper`
445461

446462
### Embedding Module
463+
447464
- **Package:** `com.google.adk.models.springai`
448465
- **Purpose:** Embedding model integration
449466
- **Key Classes:** `SpringAIEmbedding`, `EmbeddingConverter`
450467

451468
### Auto-Configuration Module
469+
452470
- **Package:** `com.google.adk.models.springai.autoconfigure`
453471
- **Purpose:** Spring Boot auto-configuration
454472
- **Key Classes:** `SpringAIAutoConfiguration`
455473

456474
### Observability Module
475+
457476
- **Package:** `com.google.adk.models.springai.observability`
458477
- **Purpose:** Metrics, logging, and monitoring
459478
- **Key Classes:** `SpringAIObservabilityHandler`
460479

461480
### Properties Module
481+
462482
- **Package:** `com.google.adk.models.springai.properties`
463483
- **Purpose:** Configuration properties
464484
- **Key Classes:** `SpringAIProperties`
465485

466486
### Error Handling Module
487+
467488
- **Package:** `com.google.adk.models.springai.error`
468489
- **Purpose:** Error mapping and handling
469490
- **Key Classes:** `SpringAIErrorMapper`
@@ -538,9 +559,9 @@ The library works with any Spring AI provider:
538559
- **Note:** Requires proper function schema registration
539560

540561
3. **Google Gemini** (`spring-ai-google-genai`)
541-
- Models: Gemini 2.0 Flash, Gemini 1.5 Pro
542-
- Features: Chat, streaming, function calling
543-
- **Note:** Requires single system message (automatically handled)
562+
- Models: Gemini 3.8 Flash
563+
- Features: Chat, streaming, function calling
564+
- **Note:** Requires single system message (automatically handled)
544565

545566
4. **Vertex AI** (`spring-ai-vertex-ai-gemini`)
546567
- Models: Vertex AI Gemini models
@@ -557,16 +578,22 @@ The library works with any Spring AI provider:
557578
### Provider-Specific Considerations
558579

559580
#### Gemini
581+
560582
- **System Messages:** Only one system message allowed - library automatically combines multiple system messages
561-
- **Model Names:** Use `gemini-2.0-flash`, `gemini-1.5-pro`
562-
- **API Key:** Requires `GOOGLE_API_KEY` environment variable
583+
- **Model Names:** Use `gemini-3.8-flash` or any other Gemini model name. See
584+
[Google Gemini models](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/model-versions)
585+
for more details.
586+
- **Vertex AI:** Requires `GOOGLE_CLOUD_PROJECT` environment variable
587+
- **Optional:** `GOOGLE_CLOUD_LOCATION` (defaults to `global`)
563588

564589
#### Anthropic
590+
565591
- **Function Calling:** Requires explicit schema registration using `inputSchema()` method
566592
- **Model Names:** Use full model names like `claude-sonnet-4-6`
567593
- **API Key:** Requires `ANTHROPIC_API_KEY` environment variable
568594

569595
#### OpenAI
596+
570597
- **Standard Support:** Full feature compatibility
571598
- **Model Names:** Use `gpt-4o-mini`, `gpt-4o`, etc.
572599
- **API Key:** Requires `OPENAI_API_KEY` environment variable
@@ -641,9 +668,14 @@ The library includes comprehensive integration tests for different providers:
641668
### Running Integration Tests
642669

643670
```bash
671+
# Opt in to integration tests (gates the Gemini and Ollama tests)
672+
export ADK_RUN_INTEGRATION_TESTS=true
673+
# Set Gemini model name for integration tests
674+
export GEMINi_MODEL=gemini-3.8-flash
675+
644676
# Set required environment variables
645677
export OPENAI_API_KEY=your_key
646-
export GOOGLE_API_KEY=your_key
678+
export GOOGLE_CLOUD_PROJECT=your_project_id
647679
export ANTHROPIC_API_KEY=your_key
648680

649681
# Run specific integration test
@@ -658,11 +690,13 @@ mvn test
658690
The library provides comprehensive error handling through `SpringAIErrorMapper`:
659691

660692
### Error Mapping
693+
661694
- Spring AI exceptions → ADK-compatible errors
662695
- Provider-specific error normalization
663696
- Detailed error context preservation
664697

665698
### Observability
699+
666700
- Request/response logging
667701
- Token usage tracking
668702
- Error metrics collection
@@ -671,24 +705,28 @@ The library provides comprehensive error handling through `SpringAIErrorMapper`:
671705
## Best Practices
672706

673707
### Model Configuration
708+
674709
1. Always specify explicit model names rather than relying on defaults
675710
2. Use environment variables for API keys
676711
3. Configure appropriate timeouts for your use case
677712
4. Enable observability for production monitoring
678713

679714
### Function Calling
715+
680716
1. Ensure function schemas are properly defined in ADK tools
681717
2. Test function calling with each provider separately
682718
3. Handle provider-specific argument format differences
683719
4. Use debug logging to troubleshoot function calling issues
684720

685721
### Performance
722+
686723
1. Use streaming for long responses
687724
2. Implement proper backpressure handling
688725
3. Configure connection pooling for high-throughput scenarios
689726
4. Monitor token usage and costs
690727

691728
### Error Handling
729+
692730
1. Implement retry logic for transient failures
693731
2. Handle provider-specific error conditions
694732
3. Use circuit breakers for external API calls
@@ -697,13 +735,15 @@ The library provides comprehensive error handling through `SpringAIErrorMapper`:
697735
## Dependencies
698736

699737
### Core Dependencies
738+
700739
- Spring AI Model (`spring-ai-model`)
701740
- ADK Core (`google-adk`)
702741
- Google GenAI Types (`google-genai`)
703742
- RxJava3 for reactive programming
704743
- Jackson for JSON processing
705744

706745
### Provider Dependencies (Test Scope)
746+
707747
- `spring-ai-openai`
708748
- `spring-ai-anthropic`
709749
- `spring-ai-google-genai`
@@ -712,20 +752,23 @@ The library provides comprehensive error handling through `SpringAIErrorMapper`:
712752
- `spring-ai-ollama`
713753

714754
### Spring Boot Integration
755+
715756
- `spring-boot-autoconfigure` (optional)
716757
- `spring-boot-configuration-processor` (optional)
717758
- `jakarta.validation-api` (optional)
718759

719760
## Future Enhancements
720761

721762
### Planned Features
763+
722764
1. Enhanced provider-specific optimizations
723765
2. Advanced streaming aggregation
724766
3. Multi-modal content support
725767
4. Enhanced observability and metrics
726768
5. Performance optimization for high-throughput scenarios
727769

728770
### Known Limitations
771+
729772
1. Live connection mode not supported (returns `UnsupportedOperationException`)
730773
2. Some provider-specific features may not be fully supported
731774
3. Response schema and MIME type configuration limited
@@ -734,12 +777,14 @@ The library provides comprehensive error handling through `SpringAIErrorMapper`:
734777
## Migration Guide
735778

736779
### From Direct Spring AI Usage
780+
737781
1. Replace Spring AI `ChatModel.call()` with `SpringAI.generateContent()`
738782
2. Update message formats from Spring AI to ADK format
739783
3. Configure auto-configuration properties
740784
4. Update dependency management to include ADK Spring AI
741785

742786
### Version Compatibility
787+
743788
- Spring AI: 1.1.0-M3+
744789
- Spring Boot: 3.0+
745790
- Java: 17+

0 commit comments

Comments
 (0)