Skip to content

Commit

Permalink
community: add Valthera integration (#30105)
Browse files Browse the repository at this point in the history
```markdown
**Description:**  
This PR integrates Valthera into LangChain, introducing an framework designed to send highly personalized nudges by an LLM agent. This is modeled after Dr. BJ Fogg's Behavior Model. This integration includes:

- Custom data connectors for HubSpot, PostHog, and Snowflake.
- A unified data aggregator that consolidates user data.
- Scoring configurations to compute motivation and ability scores.
- A reasoning engine that determines the appropriate user action.
- A trigger generator to create personalized messages for user engagement.

**Issue:**  
N/A

**Dependencies:**  
N/A

**Twitter handle:**  
- `@vselvarajijay`

**Tests and Docs:**  
- `docs/docs/integrations/tools/valthera` 
- `https://github.com/valthera/langchain-valthera/tree/main/tests`

```

---------

Co-authored-by: Chester Curme <[email protected]>
  • Loading branch information
vselvarajijay and ccurme authored Mar 9, 2025
1 parent 3823daa commit df459d0
Show file tree
Hide file tree
Showing 3 changed files with 506 additions and 0 deletions.
63 changes: 63 additions & 0 deletions docs/docs/integrations/providers/valthera.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Valthera

> [Valthera](https://github.com/valthera/valthera) is an open-source framework that empowers LLM Agents to drive meaningful, context-aware user engagement. It evaluates user motivation and ability in real time, ensuring that notifications and actions are triggered only when users are most receptive.
>
> **langchain-valthera** integrates Valthera with LangChain, enabling developers to build smarter, behavior-driven engagement systems that deliver personalized interactions.
## Installation and Setup

### Install langchain-valthera

Install the LangChain Valthera package via pip:

```bash
pip install -U langchain-valthera
```

Import the ValtheraTool:

```python
from langchain_valthera.tools import ValtheraTool
```

### Example: Initializing the ValtheraTool for LangChain

This example shows how to initialize the ValtheraTool using a `DataAggregator` and configuration for motivation and ability scoring.

```python
import os
from langchain_openai import ChatOpenAI
from valthera.aggregator import DataAggregator
from mocks import hubspot, posthog, snowflake # Replace these with your actual connector implementations
from langchain_valthera.tools import ValtheraTool

# Initialize the DataAggregator with your data connectors
data_aggregator = DataAggregator(
connectors={
"hubspot": hubspot(),
"posthog": posthog(),
"app_db": snowflake()
}
)

# Initialize the ValtheraTool with your scoring configurations
valthera_tool = ValtheraTool(
data_aggregator=data_aggregator,
motivation_config=[
{"key": "hubspot_lead_score", "weight": 0.30, "transform": lambda x: min(x, 100) / 100.0},
{"key": "posthog_events_count_past_30days", "weight": 0.30, "transform": lambda x: min(x, 50) / 50.0},
{"key": "hubspot_marketing_emails_opened", "weight": 0.20, "transform": lambda x: min(x / 10.0, 1.0)},
{"key": "posthog_session_count", "weight": 0.20, "transform": lambda x: min(x / 5.0, 1.0)}
],
ability_config=[
{"key": "posthog_onboarding_steps_completed", "weight": 0.30, "transform": lambda x: min(x / 5.0, 1.0)},
{"key": "posthog_session_count", "weight": 0.30, "transform": lambda x: min(x / 10.0, 1.0)},
{"key": "behavior_complexity", "weight": 0.40, "transform": lambda x: 1 - (min(x, 5) / 5.0)}
]
)

print("✅ ValtheraTool successfully initialized for LangChain integration!")
```


The langchain-valthera integration allows you to assess user behavior and decide on the best course of action for engagement, ensuring that interactions are both timely and relevant within your LangChain applications.
Loading

0 comments on commit df459d0

Please sign in to comment.