Financial Advisor (Kotlin)
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 (Kotlin)
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 Kotlin 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.kt | The coordinator, exposed as FinancialAdvisorAgent.rootAgent | | DataAnalystAgent.kt | The data analyst, the only agent with a tool (GoogleSearchTool) | | TradingAnalystAgent.kt, ExecutionAnalystAgent.kt, RiskAnalystAgent.kt | The other three specialists | | LegalDisclaimer.kt | The disclaimer those three specialists include in their output | | Models.kt | Reads the model settings from the environment or .env | | Main.kt, WebMain.kt | Terminal chat and the ADK dev server |
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
- Gradle (tested with 9.5.1)
- 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
Chat with the agent in the terminal:
gradle run -q
Or start the ADK dev UI and open http://127.0.0.1:8080 in a browser:
gradle run -PmainClass=com.google.adk.samples.agents.financialadvisor.WebMainKt
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
gradle test
RunnabilityTest checks that rootAgent builds with the four specialist tools, and starts the dev server from WebMain's config to check that it lists financial_coordinator at /list-apps. Neither calls the model, so they need no credentials.
Deployment
The Dockerfile builds the agent and serves the ADK dev UI and REST API 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=$(gcloud config get-value project),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/kotlin/financial-advisor
- License
- Apache-2.0