Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Spring Money AI Financial Agent Configuration

# Search & Retriever Configuration
RETRIEVER=tavily
TAVILY_API_KEY=tvly-xxxxxxxxxxxxxxxxxxxx

# LLM Provider Configuration (openai | ollama | google | azureopenai)
LLM_PROVIDER=ollama
FAST_LLM_MODEL=llama3:8b
SMART_LLM_MODEL=llama3:70b
LLM_BASE_URL=http://localhost:11434

# Embedding Configuration
EMBEDDING_PROVIDER=ollama
EMBEDDING_MODEL=nomic-embed-text

# Fallback Cloud Providers (optional)
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx
GEMINI_API_KEY=AIzaxxxxxxxxxxxxxxxxxxxx

# Agent Tuning Parameters
TEMPERATURE=0.55
FAST_TOKEN_LIMIT=2000
SMART_TOKEN_LIMIT=4000
SUMMARY_TOKEN_LIMIT=700
MAX_SEARCH_RESULTS_PER_QUERY=5
MAX_ITERATIONS=3
REPORT_FORMAT=APA

# LangSmith Observability (optional)
LANGCHAIN_TRACING_V2=false
LANGCHAIN_API_KEY=lsv2-xxxxxxxxxxxxxxxxxxxx
51 changes: 51 additions & 0 deletions backend/config_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Spring Money configuration validator and environment checker."""

import os
from typing import Dict, List, Optional
from pydantic import BaseModel, Field


class AgentRuntimeConfig(BaseModel):
retriever: str = Field(default="tavily", description="Default search retriever")
llm_provider: str = Field(default="ollama", description="LLM provider name")
fast_llm_model: str = Field(default="llama3:8b", description="Fast model identifier")
smart_llm_model: str = Field(default="llama3:70b", description="Reasoning model identifier")
llm_base_url: Optional[str] = Field(default=None, description="Local or private model endpoint")
temperature: float = Field(default=0.55, ge=0.0, le=2.0)
max_search_results: int = Field(default=5, ge=1, le=50)
report_format: str = Field(default="APA")


def validate_runtime_environment() -> Dict[str, any]:
"""Inspect environment variables and return validated configuration and warnings."""
warnings: List[str] = []

provider = os.getenv("LLM_PROVIDER", "ollama").lower()
if provider == "openai" and not os.getenv("OPENAI_API_KEY"):
warnings.append("OPENAI_API_KEY is not set while LLM_PROVIDER is configured to 'openai'")
elif provider == "google" and not os.getenv("GEMINI_API_KEY"):
warnings.append("GEMINI_API_KEY is not set while LLM_PROVIDER is configured to 'google'")
elif provider == "ollama" and not os.getenv("LLM_BASE_URL"):
# Default fallback to standard local Ollama port
os.environ["LLM_BASE_URL"] = "http://localhost:11434"

retriever = os.getenv("RETRIEVER", "tavily").lower()
if retriever == "tavily" and not os.getenv("TAVILY_API_KEY"):
warnings.append("TAVILY_API_KEY is unset; live search queries will require mock fallback")

config = AgentRuntimeConfig(
retriever=retriever,
llm_provider=provider,
fast_llm_model=os.getenv("FAST_LLM_MODEL", "llama3:8b"),
smart_llm_model=os.getenv("SMART_LLM_MODEL", "llama3:70b"),
llm_base_url=os.getenv("LLM_BASE_URL"),
temperature=float(os.getenv("TEMPERATURE", 0.55)),
max_search_results=int(os.getenv("MAX_SEARCH_RESULTS_PER_QUERY", 5)),
report_format=os.getenv("REPORT_FORMAT", "APA"),
)

return {
"valid": len(warnings) == 0,
"warnings": warnings,
"config": config.model_dump(),
}
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ lxml = { version = ">=4.9.2", extras = ["html_clean"] }
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = ["."]
testpaths = ["tests"]
17 changes: 17 additions & 0 deletions tests/test_config_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from backend.config_validator import validate_runtime_environment, AgentRuntimeConfig


def test_default_config_generation():
"""Ensure default configuration creates valid instance."""
result = validate_runtime_environment()
assert "config" in result
assert result["config"]["retriever"] in ["tavily", "google", "bing"]
assert result["config"]["temperature"] >= 0.0


def test_agent_runtime_config_bounds():
"""Verify pydantic bounds for configuration."""
cfg = AgentRuntimeConfig(temperature=0.8, max_search_results=10)
assert cfg.temperature == 0.8
assert cfg.max_search_results == 10
Loading