Skip to main content

The Problem

You want to run the same agent task with different providers without changing your Java code.

Solution: Maven Profiles

Define one Maven profile per provider. Each profile puts a different starter on the classpath. Your Java code uses only the portable AgentClient API.

1. Define Profiles in pom.xml

2. Add Per-Provider Configuration

Create profile-specific YAML files alongside your main application.yml:
Activate the matching Spring profile in your main application.yml:

3. Run with a Specific Provider

Use -P'!claude' to deactivate the default Claude profile when switching to another provider. Only one provider starter should be on the classpath.

Your Java Code Stays the Same

The key design principle: your Java code never imports provider-specific classes. It only uses:
  • AgentClient / AgentClient.Builder
  • AgentClientResponse
  • AgentOptions (for portable options)
Provider selection happens entirely through Maven profiles and Spring configuration.

Working Example

See samples/create-file-multi-provider for a complete working example, or the agent-client-tutorial for progressive examples.