Financial Advisor (Java)
A team of AI agents that helps a human financial advisor. A coordinator agent walks the user through four steps and calls a specialist agent for each one:
Content
Financial Advisor (Java)
A team of AI agents that helps a human financial advisor. A coordinator agent walks the user through four steps and calls a specialist agent for each one:
- Data analyst builds a current market analysis report for a stock ticker, using the built-in Google Search tool.
- Trading analyst proposes at least five trading strategies that fit the market analysis, the user's risk attitude, and their investment period.
- Execution analyst writes a detailed plan for entering, holding, scaling, and exiting the chosen strategies.
- Risk analyst evaluates the risk of the whole plan against the user's risk attitude and investment period.
This is the ADK for Java port of [contrib/python/financial-advisor](../../python/financial-advisor). The agent graph is the same, and so are the prompts apart from small fixes: typos, the subagent names the coordinator calls, and one shared copy of the legal disclaimer.
How it works
Each specialist is an LlmAgent wrapped in an AgentTool, so the coordinator calls it like any other tool and gets its answer back as the tool result. Each agent also sets an outputKey, which saves its final answer in session state (for example market_data_analysis_output).
| File | What it holds | | --- | --- | | FinancialAdvisorAgent.java | The coordinator and ROOT_AGENT, which the dev server discovers | | DataAnalystAgent.java | The data analyst, the only agent with a tool (GoogleSearchTool) | | TradingAnalystAgent.java, ExecutionAnalystAgent.java, RiskAnalystAgent.java | The other three specialists | | LegalDisclaimer.java | The disclaimer those three specialists include in their output | | Models.java | Reads the model settings from the environment or .env |
Legal disclaimer. The information and trading strategy outlines provided by this tool are generated by an AI model and are for educational and informational purposes only. They do not constitute financial advice, investment recommendations, endorsements, or offers to buy or sell any securities. You should conduct your own research and consult a qualified independent financial advisor before making any investment decision.
Prerequisites
- JDK 17 or later
- Maven 3.9 or later
- Either a Google Cloud project with the Vertex AI API enabled, or a Gemini API key
Configuration
Copy the example file and fill it in:
cp .env.example .env
To use Vertex AI, set GOOGLE_CLOUD_PROJECT and authenticate:
gcloud auth application-default login
To use the Gemini API instead, set GOOGLE_GENAI_USE_VERTEXAI=False and GOOGLE_API_KEY. Real environment variables take precedence over .env.
Running the agent
Start the ADK dev server and open http://localhost:8080 in a browser:
mvn compile exec:java
Select financial_coordinator in the top-left menu and start with hi. The coordinator introduces itself, shows the disclaimer, and asks for a ticker. Send show me the detailed result as markdown at any step to see a specialist's full output.
Testing
mvn test
RunnabilityTest checks that ROOT_AGENT loads and that the ADK dev server, started the way the Dockerfile starts it, lists financial_coordinator at /list-apps. FinancialAdvisorAgentTest checks that the coordinator has the four specialist tools. Neither calls the model, so they need no credentials.
Deployment
The Dockerfile builds the agent and serves the ADK dev server on port 8080. To deploy it to Cloud Run:
gcloud run deploy financial-advisor \
--source . \
--region us-central1 \
--set-env-vars GOOGLE_GENAI_USE_VERTEXAI=True,GOOGLE_CLOUD_PROJECT=<your-project-id>,GOOGLE_CLOUD_LOCATION=global
The Cloud Run service account needs the Vertex AI User role (roles/aiplatform.user).
Source and license
- Source
- Google ADK Samples
- Original
- google/adk-samples/contrib/java/financial-advisor
- License
- Apache-2.0