Skip to content
Open
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
29 changes: 29 additions & 0 deletions agent-langgraph-basic/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copy to .env for local development: cp .env.example .env
#
# The only required setting for local dev is a Databricks auth profile (used to call the model).
# Everything else — Lakebase durability, MLflow tracing — is optional and off by default.

# Databricks auth profile (from `databricks auth profiles`). Used to call the model endpoint.
DATABRICKS_CONFIG_PROFILE=DEFAULT
# Or use explicit host/token instead of a profile:
# DATABRICKS_HOST=https://<your-workspace>.databricks.com
# DATABRICKS_TOKEN=dapi...

# --- Optional: MLflow tracing ---
# Leave UNSET to skip tracing (local dev). To enable, set both: an experiment to log to, and the
# tracking destination (your workspace).
# MLFLOW_EXPERIMENT_ID=
# MLFLOW_TRACKING_URI="databricks"

# --- Optional: durable conversation history (managed session store) ---
# Leave UNSET to keep the local SQLite session store. Set to a managed session store name to
# persist the transcript to its agents/v1 items API (durable, shared across replicas).
# AGENT_SESSION_STORE=my-agent-sessions

# --- Optional: long-running background mode + crash recovery (Lakebase) ---
# Leave UNSET to serve in-request. Set the Lakebase endpoint to enable durable background mode.
# LAKEBASE_AUTOSCALING_ENDPOINT=

# --- Optional: local SQLite session store path (when AGENT_SESSION_STORE is unset) ---
# Defaults to a file so history survives restarts. Set ":memory:" for ephemeral storage.
# LOCAL_SESSION_DB_PATH=local_agent_sessions.db
195 changes: 195 additions & 0 deletions agent-langgraph-basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VS Code
.vscode/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python

.DS_*

# Databricks / MLflow local artifacts
**/mlruns/
mlflow.db
**/.databricks
.claude/

# Environment files
**/.env
**/.env.local

# Local (Lakebase-free) SQLite session store
local_agent_sessions.db
local_agent_sessions.db-*
*.db-journal
69 changes: 69 additions & 0 deletions agent-langgraph-basic/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Agent Development Guide

A lean LangGraph agent backend for Databricks Apps. Local-first: runs with no database and no setup
beyond a Databricks auth profile. Lakebase durability and MLflow tracing are optional.

See `README.md` for the full run / deploy / client-contract docs. This file is the quick map for
making changes.

## Run it

```bash
cp .env.example .env # set DATABRICKS_CONFIG_PROFILE=<your-profile>
uv run start-server # http://localhost:8000
```

No database needed — conversation state uses an in-process LangGraph checkpointer by default.

## Where things live

| You want to… | Edit |
| --- | --- |
| Change model / instructions | `agent/agent.py` (`create_agent_graph`) |
| Add a function tool | new `*.py` in `agent/tools/` with a `@tool` function (auto-collected) |
| Add an MCP server | append a `DatabricksMCPServer` to `build_mcp_servers()` in `agent/mcps.py` |
| Change how a request maps to a run | `agent/agent.py` (`@invoke` / `@stream` handlers) |
| Change the session checkpointer | `agent/mason/session_store.py` |
| Server / durability wiring | `server/start_server.py` (rarely needed) |
| Add a test | `tests/` (hermetic; gate model calls on a workspace profile — see `test_agent.py`) |

`agent/mason/` holds plumbing (session checkpointer, tracing, MCP tool loading, wire translation)
slated to move into Databricks SDKs — grouped so that migration is localized. You rarely edit it;
build the agent in `agent/agent.py`, `agent/tools/`, and `agent/mcps.py`.

## How tools register

`agent/tools/all_tools()` auto-imports every module in the package and collects every
`@tool`-decorated `BaseTool` it finds. So a tool registers just by existing in a file there —
`create_agent_graph()` calls `all_tools()`. **Do not** edit `agent/agent.py` to add a tool — just
add a file to `agent/tools/`.

## Sessions & durability

- Default: `agent/mason/session_store.py`'s `checkpointer()` returns an in-process `InMemorySaver`,
keyed per request by `thread_config(session_id)` — no database, multi-turn works in-process.
- **Two independent durable stores:**
- Conversation history → swap the checkpointer for a `PostgresSaver` over Lakebase (durable,
shared across replicas).
- `LAKEBASE_AUTOSCALING_ENDPOINT` → `start_server.py` passes it into `LongRunningAgentServer` for
its durable server store (background mode + crash recovery).
- Enable either/both/neither.

## MLflow tracing

Optional. Set both `MLFLOW_EXPERIMENT_ID` and `MLFLOW_TRACKING_URI` to enable (`mlflow.langchain.autolog()`);
leave either unset to skip (the server boots with tracing disabled).

## Quick commands

| Task | Command |
| --- | --- |
| Run locally | `uv run start-server` |
| Run via CLI local App runner | `databricks apps run-local --prepare-environment -p <profile>` |
| Test | `uv run pytest` (hermetic; live model test runs only with a profile) |
| Deploy | `databricks apps deploy agent-langgraph-basic --source-code-path <path>` |

## Notes for maintainers

- `agent/mason/wire/` is LangGraph-specific (inbound request→session id; outbound `astream`
`updates`/`messages` events→Responses wire events).
1 change: 1 addition & 0 deletions agent-langgraph-basic/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
Loading