PolicyPulse Development-2
AI-powered synthetic population simulator with clean architecture, Python type safety, and professional dashboard design patterns
- License 许可
- Apache-2.0
- 最近更新
- 2026-07-12
- Stars
- ★ 82
- Forks
- 18
01 前言 Front Matter
- name
- PolicyPulse Development-2
- description
- AI-powered synthetic population simulator with clean architecture, Python type safety, and professional dashboard design patterns
02 资源文件 48
- 其他.gitignore661 B
- 其他.streamlit/config.toml353 B
- 参考文档data/README.md488 B
- 其他data/rl_feedback.jsonl2.5 KB
- 参考文档LLM_POLICY_ANALYSIS.md9.5 KB
- 参考文档models/README.md496 B
- 参考文档MODERN_UI_FEATURES.md6.0 KB
- 参考文档MODERN_UI_GUIDE.md3.2 KB
- 参考文档NEW_FEATURES.md8.6 KB
- 参考文档NN_IMPLEMENTATION.md14.2 KB
- 其他pyproject.toml787 B
- 参考文档README.md4.5 KB
- 参考文档requirements.txt401 B
- 参考文档RUN_APP.md—
- 脚本run_enhanced.sh—
- 脚本run.sh755 B
- 脚本src/__init__.py130 B
- 脚本src/app_tabs_extension.py7.9 KB
- 脚本src/app.py72.3 KB
- 脚本src/config.py4.9 KB
- 脚本src/data_models.py7.0 KB
- 脚本src/llm_client.py26.6 KB
- 脚本src/logging_config.py4.2 KB
- 脚本src/ml_data.py3.0 KB
- 脚本src/nn_model.py9.6 KB
- 脚本src/policy_analyzer.py10.8 KB
- 脚本src/population.py10.7 KB
- 脚本src/rl_agent.py18.6 KB
- 脚本src/rl_environment.py—
- 脚本src/rl_trainer.py10.5 KB
- 脚本src/simulation.py28.8 KB
- 脚本src/stats.py8.1 KB
- 脚本src/utils.py3.3 KB
- 参考文档STATUS.md—
- 脚本streamlit_app.py496 B
- 参考文档SUMMARY.md—
- 参考文档TECH_STACK.md19.1 KB
- 脚本test.sh—
- 脚本tests/__init__.py35 B
- 脚本tests/test_data_models.py2.1 KB
- 脚本tests/test_llm_client.py14.6 KB
- 脚本tests/test_nn_model.py1.1 KB
- 脚本tests/test_population.py5.4 KB
- 脚本tests/test_simulation.py17.9 KB
- 脚本tests/test_stats.py4.9 KB
- 脚本tests/test_utils.py3.6 KB
- 参考文档UNIFIED_APP_MIGRATION.md—
- 脚本verify_enhancements.py—
03 SKILL.md 正文
PolicyPulse Development
This skill guides AI agents in developing PolicyPulse, a professional analytical tool for stress-testing policies against synthetic populations using hybrid AI (LLM + Neural Network).
When to use
Activate this skill when:
- Building or modifying PolicyPulse application code
- Creating modular Python components following clean architecture
- Designing dashboard UI components for Streamlit
- Implementing type-safe Python code with proper annotations
- Writing tests for PolicyPulse functionality
Core Principles
1. Document-Driven Development
- Source of Truth: PRD.md, DESIGN_DOC.md, and TECH_STACK.md are authoritative
- No Feature Invention: Only implement features explicitly defined in documents
- Incremental Progress: Small, safe steps that keep the project runnable
- No Summary Documents: Don't create documentation unless explicitly requested
2. Clean Architecture (Modular Monolith)
Follow the defined module structure:
app.py # Entry point, session management
ui_sections.py # UI component rendering
simulation.py # Simulation orchestration
llm_client.py # Gemini API wrapper
nn_model.py # Neural network training/inference
population.py # Synthetic citizen generation
stats.py # Aggregation and statistics
data_models.py # Dataclass definitions
utils.py # Helper functions
config.py # Environment loading
ml_data.py # Training dataset management
Module Dependency Rules:
data_models.pyhas no dependencies (stdlib only)config.pyis imported by app.py only- UI layers depend on business logic, not vice versa
- External dependencies (genai, sklearn) isolated in specific modules
3. Python Type Safety
- Always use type hints: Function signatures, variables, return types
- Leverage Python 3.10+ features:
- Dataclasses for data models
- Union types with
|syntax (e.g.,str | None) - Type aliases for complex types
- Example Pattern:
from dataclasses import dataclass
from typing import Literal
@dataclass
class Citizen:
id: int
age: int
income_level: Literal["Low", "Middle", "High"]
happiness: float
def calculate_average(citizens: list[Citizen]) -> float:
return sum(c.happiness for c in citizens) / len(citizens)
4. Professional Dashboard Design
- Data Density without Overwhelm: Show comprehensive info in digestible chunks
- Progressive Disclosure: Start simple, reveal complexity on demand
- Sidebar + Main Content: Sidebar for config (300-320px fixed), main area for results
- Muted Professional Palette:
- Primary: Deep Purple (#667EEA)
- Semantic: Teal (positive), Coral (negative)
- Neutrals: Charcoal text, Pearl backgrounds
- Tabbed Analysis: Overview, Demographics, Individuals, Experts, AI Insights, Compare
- Metric Cards: Large bold values, small change indicators with colored arrows
- Responsible AI: Prominent disclaimer that this is synthetic simulation, not prediction
5. Streamlit-Specific Patterns
- Session State: Use
st.session_statefor simulation results, populations, models - File Persistence: Save models to
models/, training data todata/as CSV/Joblib - Component Organization: Separate UI rendering from business logic
- Layout Structure:
# Sidebar config
with st.sidebar:
# Population, steps, mode, policy config
pass
# Main content with tabs
tab1, tab2, tab3 = st.tabs(["Overview", "Demographics", "Individuals"])
with tab1:
# Metrics cards, time-series charts
pass
Implementation Guidelines
Data Models First
- Define dataclasses in
data_models.pywith full type annotations - Include docstrings explaining purpose and constraints
- Use
frozen=Truefor immutable data
Business Logic Isolation
- Keep simulation logic in
simulation.py,population.py,nn_model.py - No Streamlit imports in business logic modules
- Return structured data (dataclasses, DataFrames), not UI components
UI Components
- UI rendering functions in
ui_sections.py - Accept typed data structures as parameters
- Use Plotly for charts (
st.plotly_chart(fig, use_container_width=True)) - Follow design system: spacing (8px base), typography (Inter font), colors
Error Handling
- Graceful degradation: LLM → NN → Rule-based fallback
- User-friendly error messages in UI
- Log technical details for debugging
- Never crash the app; show error state and recovery options
Testing Patterns
- Unit tests for business logic (population generation, stats calculations)
- Integration tests for simulation workflow
- Mock external dependencies (Gemini API)
- Validate type contracts with pytest
File Organization
policypulse/
├── .streamlit/
│ └── config.toml # Streamlit configuration
├── data/
│ └── llm_training_samples.csv # Persistent training data
├── models/
│ ├── citizen_reaction_model.joblib # Trained NN
│ └── feature_scaler.joblib # Feature normalization
├── src/ # Source code modules
│ ├── app.py
│ ├── ui_sections.py
│ ├── simulation.py
│ ├── llm_client.py
│ ├── nn_model.py
│ ├── population.py
│ ├── stats.py
│ ├── data_models.py
│ ├── utils.py
│ ├── config.py
│ └── ml_data.py
├── tests/ # Test files
├── requirements.txt # Python dependencies
├── .env.example # Template for API keys
├── .gitignore
└── README.md
Technology Stack Constraints
- Python: 3.10+ only (for dataclasses, type hints, pattern matching)
- Web Framework: Streamlit (no React, Flask, or alternatives)
- LLM: Google Gemini (free tier: 15 req/min, 200/day)
- ML: Scikit-learn MLPRegressor (no PyTorch, TensorFlow)
- Data: Pandas + NumPy (no Spark, Dask)
- Charts: Plotly (no Matplotlib, Altair)
- Persistence: File-based CSV/Joblib (no databases)
Anti-Patterns to Avoid
❌ Don't:
- Invent features not in PRD
- Create React/JavaScript frontends
- Use databases (PostgreSQL, MongoDB, etc.)
- Add user authentication/accounts
- Create pixel-perfect custom CSS (accept Streamlit's design)
- Parallelize with threading (Python GIL limitations)
- Make predictive accuracy claims in UI
✅ Do:
- Follow the three source documents strictly
- Use Streamlit's built-in components
- Implement file-based persistence
- Maintain session-based architecture
- Show prominent "synthetic simulation" disclaimers
- Implement graceful LLM fallbacks
Quick Reference
Adding a New Feature
- Verify it's in PRD.md
- Check DESIGN_DOC.md for UI specs
- Review TECH_STACK.md for implementation patterns
- Create/update data models if needed
- Implement business logic (pure Python)
- Add UI rendering (Streamlit components)
- Write tests
- Keep project runnable at each step
Code Review Checklist
- [ ] Type hints on all functions and class attributes
- [ ] Dataclasses used for structured data
- [ ] No Streamlit imports in business logic modules
- [ ] Error handling with graceful degradation
- [ ] Follows design system (colors, spacing, typography)
- [ ] Matches PRD feature specifications exactly
- [ ] No invented functionality outside documents
04 同仓库更多 Skills
로인장 (Roinjiang)
Activates when the user needs legal advice, contract review, insurance law consultation, startup legal support, or any legal/regulatory matter. She is a top-tier in-house lawyer with absolute loyalty to the CEO, specializing in insurance law, financial consumer protection, privacy, contracts, labor law, family law, civil and criminal matters.
zocdoc-doctor-finder
Use when a user needs to find a doctor, dentist, specialist, therapist, or healthcare provider — especially when they mention insurance, in-network, availability, location, appointments, or booking. Also use for browsing provider reviews, comparing doctors by specialty, or checking if a provider takes their insurance.
zenmux-context
Answers any question about ZenMux by reading the latest official documentation. Use this skill whenever the user asks about ZenMux product features, API usage, configuration, integration, pricing, models, providers, routing, fallback, streaming, multimodal, structured output, tool calling, reasoning, prompt caching, image generation, video generation, web search, long context, observability, logs, cost tracking, usage analytics, insurance, subscription, pay-as-you-go, invoices, best practices for tools like Claude Code, Cursor, Cline, CodeX, Gemini CLI, opencode, Cherry Studio, Obsidian, Sider, Open-WebUI, Dify, Neovate, GitHub Copilot, OpenClaw, CC-Switch, Immersive Translate, Studio Chat, architecture, benchmarks, FAQ, contact, privacy, terms of service, compliance, or any other ZenMux-related topic. Also trigger when the user writes in Chinese about ZenMux: 文档, 使用指南, 快速开始, API 参考, 最佳实践, 模型路由, 供应商路由, 订阅, 按量计费, 可观测性, 帮助, 常见问题, 接入指南, 配置. Trigger on phrases like "how to use ZenMux", "ZenMux docs", "ZenMux API", "ZenMux integration", "ZenMux 怎么用", "ZenMux 接入", "ZenMux 配置". Even if the user doesn't say "ZenMux" explicitly but asks about LLM API aggregation, model routing, provider fallback in a context where ZenMux is the project being worked on, this skill should activate.
workers-comp-guide
Guide workers compensation compliance and claims management. TRIGGERS - Use when user needs help with workers-comp-guide related tasks.
weekly-kpi-report
Generate McKinsey-style board presentation PPTs from weekly auto insurance data. Automatically calculates 16+ KPIs, creates executive-level slides with actionable insights, and supports week-over-week comparisons. Use when user uploads insurance cost data (Excel/CSV) and requests board report, weekly presentation, executive briefing, or mentions keywords like 董事会汇报, 周报PPT, 经营分析演示, McKinsey-style reports.
wealth-advisory
Wealth management and financial planning for HNW and UHNW clients. Activate when the user mentions wealth management, financial planning, retirement, estate planning, tax planning, GRAT, IDGT, trust, asset allocation, withdrawal rate, Monte Carlo simulation, goals-based investing, tax-loss harvesting, Roth conversion, insurance, annuity, mortgage strategy, concentrated stock, family office, direct indexing, 529 plan, charitable giving, donor-advised fund, private foundation, or asks about personal finance strategy, inheritance, long-term financial planning, or UHNW advisory.