Skip to main content

Using Behavior Latticing to infer user motivation from unstructured interactions

Project description

Behavior Latticing

Python 3.10+ arXiv PyPI Downloads License: MIT

Latticing is a Python library for transforming raw interaction traces into behavioral insights about the user's motivations.

Given a stream of user interactions — chat histories, screen activity logs, support tickets, behavior latticing induces user motivation through hierarchically grouping and interpreting user behavior.

Installation

pip install latticing

Set your LLM provider API key(s) in a .env file or your environment:

ANTHROPIC_API_KEY=sk-ant-...   # Anthropic (Claude)
OPENAI_API_KEY=sk-...          # OpenAI (GPT)
GOOGLE_API_KEY=...             # Google (Gemini)
TOGETHER_API_KEY=...           # Together AI

Requirements: Python 3.10+

Quick start

import os
import asyncio
from lattice import Lattice, AsyncLLM, SyncLLM
from dotenv import load_dotenv

load_dotenv()

# interaction_traces: list of sessions, each a dict with
# "interactions" (list of {interaction, metadata}) and "time"
l = Lattice(
    name="Alice",
    interactions=interaction_traces,
    description="the user's ChatGPT conversations",
    insight_model=AsyncLLM(name="claude-opus-4-6", api_key=os.getenv("ANTHROPIC_API_KEY")),
    observer_model=AsyncLLM(name="claude-sonnet-4-6", api_key=os.getenv("ANTHROPIC_API_KEY")),
    evidence_model=AsyncLLM(name="claude-sonnet-4-6", api_key=os.getenv("ANTHROPIC_API_KEY")),
    format_model=SyncLLM(name="claude-sonnet-4-6", api_key=os.getenv("ANTHROPIC_API_KEY")),
    params={"max_concurrent": 100, "min_insights": 3, "window_size": 100},
)

# Each config entry defines a layer: how to group inputs into insight clusters
config = {
    0: {"type": "session", "value": "5"},   # L1: synthesize observations across 5 chunks (i.e., chat conversations)
    1: {"type": "session", "value": "10"},  # L2: synthesize insights across 10 chunks from the layer below
}

asyncio.run(l.build(config))
l.save("lattice.json")

# Interactive Plotly figure
l.visualize().show()

How it works

  1. Observe — the Observer reads sliding windows of raw interactions and prompts an LLM to infer the user's behavior.
  2. Synthesize — observations are grouped by session and synthesized into titled, evidence-backed insights with context on when each pattern applies.
  3. Layer — insights from multiple sessions are merged into higher-order patterns, revealing cross-session behaviors invisible at the individual session level.
  4. Explore — navigate the resulting lattice interactively — hover any node to read its full text, trace it back to its supporting observations.

Lattice structure

Layer Contents
0 Raw observations — inferred emotional/cognitive states from interaction windows
1+ Insights — higher-order inferred motivations that are induced from the layer below

Edges link each insight back to the observations or lower-level insights that support it.

Supported providers

Pass different providers per role for cost/quality tradeoffs:

from lattice import AsyncLLM, SyncLLM

model = AsyncLLM(name="claude-opus-4-6", api_key=os.getenv("ANTHROPIC_API_KEY"))
format_model = SyncLLM(name="claude-haiku-4-5", api_key=os.getenv("ANTHROPIC_API_KEY"))

Examples

Explore examples of how behavior latticing can be applied to different types of interaction data:

Documentation

Full documentation is available at https://stanfordhci.github.io/lattice.

Citation

If you use Behavior Latticing in academic work, please cite:

@article{zhao2026behavior,
  title={Behavior Latticing: Inferring User Motivations from Unstructured Interactions},
  author={Zhao, Dora and Lam, Michelle S and Yang, Diyi and Bernstein, Michael S},
  journal={arXiv preprint arXiv:2604.07629},
  year={2026}
}

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latticing-0.1.3.1.tar.gz (149.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latticing-0.1.3.1-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file latticing-0.1.3.1.tar.gz.

File metadata

  • Download URL: latticing-0.1.3.1.tar.gz
  • Upload date:
  • Size: 149.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for latticing-0.1.3.1.tar.gz
Algorithm Hash digest
SHA256 77153ca341e6f9b5771767a4de261cf998477b74c36406ceab26dc420ac41bfd
MD5 e1419dddd30bf93f936897fb81bff0d9
BLAKE2b-256 5c5de095b6f65280bfd2c4f0355fe10f3e15eb145604d335e45a660e165f7850

See more details on using hashes here.

File details

Details for the file latticing-0.1.3.1-py3-none-any.whl.

File metadata

  • Download URL: latticing-0.1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for latticing-0.1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ffdbacddb3c7f6826fb6cc066e51be4d4c25ee7f0f2435f9894c446ccb484c
MD5 f0b5c1004ca463cdca59b321924f5ae4
BLAKE2b-256 081d169b0b31baba70f0c0c187f606b8dc4d26e3e3b62be622ddf221713b067d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page