File size: 1,028 Bytes
dbb3f80
 
 
 
2139cb3
dbb3f80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
from langchain_core.tools import tool

@tool
def scenario_simulator(params: dict) -> str:
    """Simulates product adoption scenarios using Monte Carlo. Params: initial_users, growth_rate, time_months, uncertainty."""
    try:
        initial_users = params.get("initial_users", 1000)
        growth_rate = params.get("growth_rate", 0.05)  # 5%/month default
        time_months = params.get("time_months", 12)
        uncertainty = params.get("uncertainty", 0.1)  # 10% variance
        runs = 1000
        final_users = []
        for _ in range(runs):
            users = initial_users
            for _ in range(time_months):
                users *= (1 + np.random.normal(growth_rate, uncertainty))
            final_users.append(users)
        mean = np.mean(final_users)
        std = np.std(final_users)
        return f"Predicted users after {time_months} months: {mean:.0f} ± {std:.0f} (mean ± std, {runs} runs)."
    except Exception as e:
        return f"Sim error: {e}. Check params: {params}"