Skip to content

Commit 5169066

Browse files
committed
Update
1 parent dcd8a6b commit 5169066

File tree

16 files changed

+352
-196
lines changed

16 files changed

+352
-196
lines changed

Makefile

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.PHONY: all format lint test tests test_watch integration_tests docker_tests help extended_tests
2+
3+
# Default target executed when no arguments are given to make.
4+
all: help
5+
6+
# Define a variable for the test file path.
7+
TEST_FILE ?= tests/unit_tests/
8+
9+
test:
10+
python -m pytest $(TEST_FILE)
11+
12+
test_watch:
13+
python -m ptw --snapshot-update --now . -- -vv tests/unit_tests
14+
15+
test_profile:
16+
python -m pytest -vv tests/unit_tests/ --profile-svg
17+
18+
extended_tests:
19+
python -m pytest --only-extended $(TEST_FILE)
20+
21+
22+
######################
23+
# LINTING AND FORMATTING
24+
######################
25+
26+
# Define a variable for Python and notebook files.
27+
PYTHON_FILES=src/
28+
MYPY_CACHE=.mypy_cache
29+
lint format: PYTHON_FILES=.
30+
lint_diff format_diff: PYTHON_FILES=$(shell git diff --name-only --diff-filter=d main | grep -E '\.py$$|\.ipynb$$')
31+
lint_package: PYTHON_FILES=src
32+
lint_tests: PYTHON_FILES=tests
33+
lint_tests: MYPY_CACHE=.mypy_cache_test
34+
35+
lint lint_diff lint_package lint_tests:
36+
python -m ruff check .
37+
[ "$(PYTHON_FILES)" = "" ] || python -m ruff format $(PYTHON_FILES) --diff
38+
[ "$(PYTHON_FILES)" = "" ] || python -m ruff check --select I $(PYTHON_FILES)
39+
[ "$(PYTHON_FILES)" = "" ] || python -m mypy --strict $(PYTHON_FILES)
40+
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && python -m mypy --strict $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
41+
42+
format format_diff:
43+
ruff format $(PYTHON_FILES)
44+
ruff check --select I --fix $(PYTHON_FILES)
45+
46+
spell_check:
47+
codespell --toml pyproject.toml
48+
49+
spell_fix:
50+
codespell --toml pyproject.toml -w
51+
52+
######################
53+
# HELP
54+
######################
55+
56+
help:
57+
@echo '----'
58+
@echo 'format - run code formatters'
59+
@echo 'lint - run linters'
60+
@echo 'test - run unit tests'
61+
@echo 'tests - run unit tests'
62+
@echo 'test TEST_FILE=<test_file> - run all tests in file'
63+
@echo 'test_watch - run unit tests in watch mode'
64+

langgraph.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": ["."],
33
"graphs": {
4-
"agent": "./react_agent/graph.py:graph"
4+
"agent": "./src/react_agent/graph.py:graph"
55
},
66
"env": ".env"
77
}

pyproject.toml

+50-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
[tool.poetry]
1+
[project]
22
name = "react-agent"
33
version = "0.0.1"
44
description = "Starter template for making a custom Reasoning and Action agent (using tool calling) in LangGraph."
5-
authors = ["William Fu-Hinthorn <[email protected]>"]
6-
license = "MIT"
5+
authors = [
6+
{ name = "William Fu-Hinthorn", email = "[email protected]" },
7+
]
78
readme = "README.md"
9+
license = { text = "MIT" }
10+
requires-python = ">=3.9"
11+
dependencies = [
12+
"langgraph>=0.2.6",
13+
"langchain-openai>=0.1.22",
14+
"langchain-anthropic>=0.1.23",
15+
"langchain>=0.2.14",
16+
"langchain-fireworks>=0.1.7",
17+
"python-dotenv>=1.0.1",
18+
]
819

9-
[tool.poetry.dependencies]
10-
python = "^3.9"
11-
langgraph = "^0.2.6"
12-
langchain-openai = "^0.1.22"
13-
langchain-anthropic = "^0.1.23"
14-
langchain = "^0.2.14"
15-
langchain-fireworks = "^0.1.7"
16-
python-dotenv = "^1.0.1"
1720

18-
[tool.poetry.group.dev.dependencies]
19-
mypy = "^1.11.1"
20-
ruff = "^0.6.1"
21+
[project.optional-dependencies]
22+
dev = ["mypy>=1.11.1", "ruff>=0.6.1"]
2123

2224
[build-system]
23-
requires = ["poetry-core"]
24-
build-backend = "poetry.core.masonry.api"
25+
requires = ["setuptools>=73.0.0", "wheel"]
26+
build-backend = "setuptools.build_meta"
27+
28+
[tool.setuptools]
29+
packages = ["langgraph.templates.retrieval_graph", "retrieval_graph"]
30+
[tool.setuptools.package-dir]
31+
"langgraph.templates.retrieval_graph" = "src/retrieval_graph"
32+
"retrieval_graph" = "src/retrieval_graph"
33+
34+
35+
[tool.setuptools.package-data]
36+
"*" = ["py.typed"]
37+
38+
[tool.ruff]
39+
lint.select = [
40+
"E", # pycodestyle
41+
"F", # pyflakes
42+
"I", # isort
43+
"D", # pydocstyle
44+
"D401", # First line should be in imperative mood
45+
"T201",
46+
"UP",
47+
]
48+
lint.ignore = [
49+
"UP006",
50+
"UP007",
51+
# We actually do want to import from typing_extensions
52+
"UP035",
53+
# Relax the convention by _not_ requiring documentation for every function parameter.
54+
"D417",
55+
"E501",
56+
]
57+
[tool.ruff.lint.pydocstyle]
58+
convention = "google"

react_agent/__init__.py

Whitespace-only changes.

react_agent/graph.py

-91
This file was deleted.

react_agent/utils/__init__.py

-3
This file was deleted.

react_agent/utils/configuration.py

-28
This file was deleted.

react_agent/utils/state.py

-52
This file was deleted.

src/react_agent/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""React Agent.
2+
3+
This module defines a custom reasoning and action agent graph.
4+
It invokes tools in a simple loop.
5+
"""
6+
7+
from react_agent.graph import graph
8+
9+
__all__ = ["graph"]

src/react_agent/configuration.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Define the configurable parameters for the agent."""
2+
3+
from __future__ import annotations
4+
5+
from dataclasses import dataclass, fields
6+
from typing import Annotated, Optional
7+
8+
from langchain_core.runnables import RunnableConfig, ensure_config
9+
10+
11+
@dataclass(kw_only=True)
12+
class Configuration:
13+
"""The configuration for the agent."""
14+
15+
system_prompt: str = "You are a helpful AI assistant.\nSystem time: {system_time}"
16+
model_name: Annotated[
17+
str, {"__template_metadata__": {"kind": "llm"}}
18+
] = "claude-3-5-sonnet-20240620"
19+
scraper_tool_model_name: Annotated[
20+
str, {"__template_metadata__": {"kind": "llm"}}
21+
] = "accounts/fireworks/models/firefunction-v2"
22+
23+
@classmethod
24+
def from_runnable_config(
25+
cls, config: Optional[RunnableConfig] = None
26+
) -> Configuration:
27+
"""Create a Configuration instance from a RunnableConfig object."""
28+
config = ensure_config(config)
29+
configurable = config.get("configurable") or {}
30+
_fields = {f.name for f in fields(cls) if f.init}
31+
return cls(**{k: v for k, v in configurable.items() if k in _fields})

0 commit comments

Comments
 (0)