langgraph-cli 0.2.10__tar.gz → 0.2.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- langgraph_cli-0.2.12/.gitignore +184 -0
- langgraph_cli-0.2.12/Makefile +36 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/PKG-INFO +14 -20
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/README.md +4 -4
- langgraph_cli-0.2.12/examples/.env.example +10 -0
- langgraph_cli-0.2.12/examples/.gitignore +1 -0
- langgraph_cli-0.2.12/examples/Makefile +13 -0
- langgraph_cli-0.2.12/examples/graphs/agent.py +95 -0
- langgraph_cli-0.2.12/examples/graphs/langgraph.json +16 -0
- langgraph_cli-0.2.12/examples/graphs/storm.py +636 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/graphs_submod/agent.py +95 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/graphs_submod/subprompt.txt +0 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/hello.py +1 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/langgraph.json +9 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/prompt.txt +0 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_a/requirements.txt +4 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/graphs_submod/agent.py +95 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/graphs_submod/subprompt.txt +0 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/hello.py +4 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/langgraph.json +9 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/prompt.txt +0 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/requirements.txt +4 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/utils/__init__.py +0 -0
- langgraph_cli-0.2.12/examples/graphs_reqs_b/utils/greeter.py +2 -0
- langgraph_cli-0.2.12/examples/langgraph.json +16 -0
- langgraph_cli-0.2.12/examples/my_app.py +62 -0
- langgraph_cli-0.2.12/examples/pipconf.txt +2 -0
- langgraph_cli-0.2.12/examples/poetry.lock +285 -0
- langgraph_cli-0.2.12/examples/pyproject.toml +21 -0
- langgraph_cli-0.2.12/generate_schema.py +248 -0
- langgraph_cli-0.2.12/js-examples/.dockerignore +2 -0
- langgraph_cli-0.2.12/js-examples/.env.example +3 -0
- langgraph_cli-0.2.12/js-examples/.eslintrc.cjs +62 -0
- langgraph_cli-0.2.12/js-examples/.gitignore +19 -0
- langgraph_cli-0.2.12/js-examples/LICENSE +21 -0
- langgraph_cli-0.2.12/js-examples/README.md +79 -0
- langgraph_cli-0.2.12/js-examples/jest.config.js +18 -0
- langgraph_cli-0.2.12/js-examples/langgraph.json +8 -0
- langgraph_cli-0.2.12/js-examples/package.json +45 -0
- langgraph_cli-0.2.12/js-examples/src/agent/graph.ts +104 -0
- langgraph_cli-0.2.12/js-examples/src/agent/state.ts +59 -0
- langgraph_cli-0.2.12/js-examples/static/studio.png +0 -0
- langgraph_cli-0.2.12/js-examples/tests/agent.test.ts +8 -0
- langgraph_cli-0.2.12/js-examples/tests/graph.int.test.ts +18 -0
- langgraph_cli-0.2.12/js-examples/tsconfig.json +25 -0
- langgraph_cli-0.2.12/js-examples/yarn.lock +3816 -0
- langgraph_cli-0.2.12/langgraph_cli/__init__.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/cli.py +12 -9
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/config.py +32 -11
- langgraph_cli-0.2.12/langgraph_cli/py.typed +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/templates.py +2 -2
- langgraph_cli-0.2.12/langgraph_cli/util.py +25 -0
- langgraph_cli-0.2.12/pyproject.toml +62 -0
- langgraph_cli-0.2.12/schemas/schema.json +684 -0
- langgraph_cli-0.2.12/schemas/schema.v0.json +684 -0
- langgraph_cli-0.2.12/tests/__init__.py +0 -0
- langgraph_cli-0.2.12/tests/integration_tests/__init__.py +0 -0
- langgraph_cli-0.2.12/tests/integration_tests/test_cli.py +13 -0
- langgraph_cli-0.2.12/tests/unit_tests/__init__.py +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/agent.py +82 -0
- langgraph_cli-0.2.12/tests/unit_tests/cli/__init__.py +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/cli/langgraph.json +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/cli/pyproject.toml +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/cli/test_cli.py +571 -0
- langgraph_cli-0.2.12/tests/unit_tests/cli/test_templates.py +70 -0
- langgraph_cli-0.2.12/tests/unit_tests/conftest.py +16 -0
- langgraph_cli-0.2.12/tests/unit_tests/graphs/agent.py +6 -0
- langgraph_cli-0.2.12/tests/unit_tests/multiplatform/js.mts +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/multiplatform/python.py +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/pipconfig.txt +0 -0
- langgraph_cli-0.2.12/tests/unit_tests/test_config.json +19 -0
- langgraph_cli-0.2.12/tests/unit_tests/test_config.py +1115 -0
- langgraph_cli-0.2.12/tests/unit_tests/test_docker.py +148 -0
- langgraph_cli-0.2.12/uv.lock +1607 -0
- langgraph_cli-0.2.10/pyproject.toml +0 -63
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/LICENSE +0 -0
- {langgraph_cli-0.2.10/langgraph_cli → langgraph_cli-0.2.12/examples/graphs_reqs_a}/__init__.py +0 -0
- /langgraph_cli-0.2.10/langgraph_cli/py.typed → /langgraph_cli-0.2.12/examples/graphs_reqs_a/graphs_submod/__init__.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/__main__.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/analytics.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/constants.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/docker.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/exec.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/progress.py +0 -0
- {langgraph_cli-0.2.10 → langgraph_cli-0.2.12}/langgraph_cli/version.py +0 -0
- /langgraph_cli-0.2.10/langgraph_cli/util.py → /langgraph_cli-0.2.12/tests/unit_tests/helpers.py +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
.vs/
|
|
2
|
+
.vscode/
|
|
3
|
+
.idea/
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
pip-wheel-metadata/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
docs/docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
notebooks/
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
.python-version
|
|
91
|
+
|
|
92
|
+
# pipenv
|
|
93
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
94
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
95
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
96
|
+
# install all needed dependencies.
|
|
97
|
+
#Pipfile.lock
|
|
98
|
+
|
|
99
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
100
|
+
__pypackages__/
|
|
101
|
+
|
|
102
|
+
# Celery stuff
|
|
103
|
+
celerybeat-schedule
|
|
104
|
+
celerybeat.pid
|
|
105
|
+
|
|
106
|
+
# SageMath parsed files
|
|
107
|
+
*.sage.py
|
|
108
|
+
|
|
109
|
+
# Environments
|
|
110
|
+
.env
|
|
111
|
+
.envrc
|
|
112
|
+
.venv
|
|
113
|
+
.venvs
|
|
114
|
+
env/
|
|
115
|
+
venv/
|
|
116
|
+
ENV/
|
|
117
|
+
env.bak/
|
|
118
|
+
venv.bak/
|
|
119
|
+
|
|
120
|
+
# Spyder project settings
|
|
121
|
+
.spyderproject
|
|
122
|
+
.spyproject
|
|
123
|
+
|
|
124
|
+
# Rope project settings
|
|
125
|
+
.ropeproject
|
|
126
|
+
|
|
127
|
+
# mkdocs documentation
|
|
128
|
+
/site
|
|
129
|
+
|
|
130
|
+
# mypy
|
|
131
|
+
.mypy_cache/
|
|
132
|
+
.dmypy.json
|
|
133
|
+
dmypy.json
|
|
134
|
+
|
|
135
|
+
# Pyre type checker
|
|
136
|
+
.pyre/
|
|
137
|
+
|
|
138
|
+
# macOS display setting files
|
|
139
|
+
.DS_Store
|
|
140
|
+
|
|
141
|
+
# Wandb directory
|
|
142
|
+
wandb/
|
|
143
|
+
|
|
144
|
+
# asdf tool versions
|
|
145
|
+
.tool-versions
|
|
146
|
+
/.ruff_cache/
|
|
147
|
+
|
|
148
|
+
*.pkl
|
|
149
|
+
*.bin
|
|
150
|
+
|
|
151
|
+
# integration test artifacts
|
|
152
|
+
data_map*
|
|
153
|
+
\[('_type', 'fake'), ('stop', None)]
|
|
154
|
+
|
|
155
|
+
# Replit files
|
|
156
|
+
*replit*
|
|
157
|
+
|
|
158
|
+
node_modules
|
|
159
|
+
docs/.yarn/
|
|
160
|
+
docs/node_modules/
|
|
161
|
+
docs/.docusaurus/
|
|
162
|
+
docs/.cache-loader/
|
|
163
|
+
docs/_dist
|
|
164
|
+
docs/api_reference/api_reference.rst
|
|
165
|
+
docs/api_reference/experimental_api_reference.rst
|
|
166
|
+
docs/api_reference/_build
|
|
167
|
+
docs/api_reference/*/
|
|
168
|
+
!docs/api_reference/_static/
|
|
169
|
+
!docs/api_reference/templates/
|
|
170
|
+
!docs/api_reference/themes/
|
|
171
|
+
docs/docs_skeleton/build
|
|
172
|
+
docs/docs_skeleton/node_modules
|
|
173
|
+
docs/docs_skeleton/yarn.lock
|
|
174
|
+
|
|
175
|
+
# Any new jupyter notebooks
|
|
176
|
+
# not intended for the repo
|
|
177
|
+
Untitled*.ipynb
|
|
178
|
+
|
|
179
|
+
Chinook.db
|
|
180
|
+
|
|
181
|
+
.vercel
|
|
182
|
+
.turbo
|
|
183
|
+
.editorconfig
|
|
184
|
+
.scratch
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.PHONY: test lint format test-integration update-schema
|
|
2
|
+
|
|
3
|
+
######################
|
|
4
|
+
# TESTING AND COVERAGE
|
|
5
|
+
######################
|
|
6
|
+
|
|
7
|
+
test:
|
|
8
|
+
uv run pytest tests/unit_tests
|
|
9
|
+
test-integration:
|
|
10
|
+
uv run pytest tests/integration_tests
|
|
11
|
+
|
|
12
|
+
######################
|
|
13
|
+
# LINTING AND FORMATTING
|
|
14
|
+
######################
|
|
15
|
+
|
|
16
|
+
# Define a variable for Python and notebook files.
|
|
17
|
+
PYTHON_FILES=.
|
|
18
|
+
MYPY_CACHE=.mypy_cache
|
|
19
|
+
lint format: PYTHON_FILES=.
|
|
20
|
+
lint_diff format_diff: PYTHON_FILES=$(shell git diff --name-only --relative --diff-filter=d main . | grep -E '\.py$$|\.ipynb$$')
|
|
21
|
+
lint_package: PYTHON_FILES=langgraph_cli
|
|
22
|
+
lint_tests: PYTHON_FILES=tests
|
|
23
|
+
lint_tests: MYPY_CACHE=.mypy_cache_test
|
|
24
|
+
|
|
25
|
+
lint lint_diff lint_package lint_tests:
|
|
26
|
+
uv run ruff check .
|
|
27
|
+
[ "$(PYTHON_FILES)" = "" ] || uv run ruff format $(PYTHON_FILES) --diff
|
|
28
|
+
[ "$(PYTHON_FILES)" = "" ] || uv run ruff check --select I $(PYTHON_FILES)
|
|
29
|
+
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) || uv run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
|
|
30
|
+
|
|
31
|
+
format format_diff:
|
|
32
|
+
uv run ruff format $(PYTHON_FILES)
|
|
33
|
+
uv run ruff check --select I --fix $(PYTHON_FILES)
|
|
34
|
+
|
|
35
|
+
update-schema:
|
|
36
|
+
uv run python generate_schema.py
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: langgraph-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.12
|
|
4
4
|
Summary: CLI for interacting with LangGraph API
|
|
5
|
-
|
|
5
|
+
Project-URL: Repository, https://www.github.com/langchain-ai/langgraph
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
6
8
|
Requires-Python: >=3.9
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
9
|
+
Requires-Dist: click>=8.1.7
|
|
10
|
+
Requires-Dist: langgraph-sdk>=0.1.0; python_version >= '3.11'
|
|
14
11
|
Provides-Extra: inmem
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist: langgraph-
|
|
17
|
-
Requires-Dist:
|
|
18
|
-
Requires-Dist: python-dotenv (>=0.8.0) ; extra == "inmem"
|
|
19
|
-
Project-URL: Repository, https://www.github.com/langchain-ai/langgraph
|
|
12
|
+
Requires-Dist: langgraph-api>=0.1.20; (python_version >= '3.11') and extra == 'inmem'
|
|
13
|
+
Requires-Dist: langgraph-runtime-inmem>=0.0.8; (python_version >= '3.11') and extra == 'inmem'
|
|
14
|
+
Requires-Dist: python-dotenv>=0.8.0; extra == 'inmem'
|
|
20
15
|
Description-Content-Type: text/markdown
|
|
21
16
|
|
|
22
17
|
# LangGraph CLI
|
|
@@ -108,20 +103,19 @@ To develop the CLI itself:
|
|
|
108
103
|
|
|
109
104
|
1. Clone the repository
|
|
110
105
|
2. Navigate to the CLI directory: `cd libs/cli`
|
|
111
|
-
3. Install development dependencies: `
|
|
106
|
+
3. Install development dependencies: `uv pip install`
|
|
112
107
|
4. Make your changes to the CLI code
|
|
113
108
|
5. Test your changes:
|
|
114
109
|
```bash
|
|
115
110
|
# Run CLI commands directly
|
|
116
|
-
|
|
111
|
+
uv run langgraph --help
|
|
117
112
|
|
|
118
113
|
# Or use the examples
|
|
119
114
|
cd examples
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
uv pip install
|
|
116
|
+
uv run langgraph dev # or other commands
|
|
122
117
|
```
|
|
123
118
|
|
|
124
119
|
## License
|
|
125
120
|
|
|
126
121
|
This project is licensed under the terms specified in the repository's LICENSE file.
|
|
127
|
-
|
|
@@ -87,17 +87,17 @@ To develop the CLI itself:
|
|
|
87
87
|
|
|
88
88
|
1. Clone the repository
|
|
89
89
|
2. Navigate to the CLI directory: `cd libs/cli`
|
|
90
|
-
3. Install development dependencies: `
|
|
90
|
+
3. Install development dependencies: `uv pip install`
|
|
91
91
|
4. Make your changes to the CLI code
|
|
92
92
|
5. Test your changes:
|
|
93
93
|
```bash
|
|
94
94
|
# Run CLI commands directly
|
|
95
|
-
|
|
95
|
+
uv run langgraph --help
|
|
96
96
|
|
|
97
97
|
# Or use the examples
|
|
98
98
|
cd examples
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
uv pip install
|
|
100
|
+
uv run langgraph dev # or other commands
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
## License
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
OPENAI_API_KEY=placeholder
|
|
2
|
+
ANTHROPIC_API_KEY=placeholder
|
|
3
|
+
TAVILY_API_KEY=placeholder
|
|
4
|
+
LANGCHAIN_TRACING_V2=false
|
|
5
|
+
LANGCHAIN_ENDPOINT=placeholder
|
|
6
|
+
LANGCHAIN_API_KEY=placeholder
|
|
7
|
+
LANGCHAIN_PROJECT=placeholder
|
|
8
|
+
LANGGRAPH_AUTH_TYPE=noop
|
|
9
|
+
LANGSMITH_AUTH_ENDPOINT=placeholder
|
|
10
|
+
LANGSMITH_TENANT_ID=placeholder
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.langgraph-data
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.PHONY: run_w_override
|
|
2
|
+
|
|
3
|
+
run:
|
|
4
|
+
uv run langgraph up --watch --no-pull
|
|
5
|
+
|
|
6
|
+
run_faux:
|
|
7
|
+
cd graphs && uv run langgraph up --no-pull
|
|
8
|
+
|
|
9
|
+
run_graphs_reqs_a:
|
|
10
|
+
cd graphs_reqs_a && uv run langgraph up --no-pull
|
|
11
|
+
|
|
12
|
+
run_graphs_reqs_b:
|
|
13
|
+
cd graphs_reqs_b && uv run langgraph up --no-pull
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
from typing import Annotated, Literal, TypedDict
|
|
3
|
+
|
|
4
|
+
from langchain_anthropic import ChatAnthropic
|
|
5
|
+
from langchain_community.tools.tavily_search import TavilySearchResults
|
|
6
|
+
from langchain_core.messages import BaseMessage
|
|
7
|
+
from langchain_openai import ChatOpenAI
|
|
8
|
+
from langgraph.graph import END, StateGraph, add_messages
|
|
9
|
+
from langgraph.prebuilt import ToolNode
|
|
10
|
+
|
|
11
|
+
tools = [TavilySearchResults(max_results=1)]
|
|
12
|
+
|
|
13
|
+
model_anth = ChatAnthropic(temperature=0, model_name="claude-3-sonnet-20240229")
|
|
14
|
+
model_oai = ChatOpenAI(temperature=0)
|
|
15
|
+
|
|
16
|
+
model_anth = model_anth.bind_tools(tools)
|
|
17
|
+
model_oai = model_oai.bind_tools(tools)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AgentState(TypedDict):
|
|
21
|
+
messages: Annotated[Sequence[BaseMessage], add_messages]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Define the function that determines whether to continue or not
|
|
25
|
+
def should_continue(state):
|
|
26
|
+
messages = state["messages"]
|
|
27
|
+
last_message = messages[-1]
|
|
28
|
+
# If there are no tool calls, then we finish
|
|
29
|
+
if not last_message.tool_calls:
|
|
30
|
+
return "end"
|
|
31
|
+
# Otherwise if there is, we continue
|
|
32
|
+
else:
|
|
33
|
+
return "continue"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Define the function that calls the model
|
|
37
|
+
def call_model(state, config):
|
|
38
|
+
if config["configurable"].get("model", "anthropic") == "anthropic":
|
|
39
|
+
model = model_anth
|
|
40
|
+
else:
|
|
41
|
+
model = model_oai
|
|
42
|
+
messages = state["messages"]
|
|
43
|
+
response = model.invoke(messages)
|
|
44
|
+
# We return a list, because this will get added to the existing list
|
|
45
|
+
return {"messages": [response]}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Define the function to execute tools
|
|
49
|
+
tool_node = ToolNode(tools)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ConfigSchema(TypedDict):
|
|
53
|
+
model: Literal["anthropic", "openai"]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Define a new graph
|
|
57
|
+
workflow = StateGraph(AgentState, config_schema=ConfigSchema)
|
|
58
|
+
|
|
59
|
+
# Define the two nodes we will cycle between
|
|
60
|
+
workflow.add_node("agent", call_model)
|
|
61
|
+
workflow.add_node("action", tool_node)
|
|
62
|
+
|
|
63
|
+
# Set the entrypoint as `agent`
|
|
64
|
+
# This means that this node is the first one called
|
|
65
|
+
workflow.set_entry_point("agent")
|
|
66
|
+
|
|
67
|
+
# We now add a conditional edge
|
|
68
|
+
workflow.add_conditional_edges(
|
|
69
|
+
# First, we define the start node. We use `agent`.
|
|
70
|
+
# This means these are the edges taken after the `agent` node is called.
|
|
71
|
+
"agent",
|
|
72
|
+
# Next, we pass in the function that will determine which node is called next.
|
|
73
|
+
should_continue,
|
|
74
|
+
# Finally we pass in a mapping.
|
|
75
|
+
# The keys are strings, and the values are other nodes.
|
|
76
|
+
# END is a special node marking that the graph should finish.
|
|
77
|
+
# What will happen is we will call `should_continue`, and then the output of that
|
|
78
|
+
# will be matched against the keys in this mapping.
|
|
79
|
+
# Based on which one it matches, that node will then be called.
|
|
80
|
+
{
|
|
81
|
+
# If `tools`, then we call the tool node.
|
|
82
|
+
"continue": "action",
|
|
83
|
+
# Otherwise we finish.
|
|
84
|
+
"end": END,
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# We now add a normal edge from `tools` to `agent`.
|
|
89
|
+
# This means that after `tools` is called, `agent` node is called next.
|
|
90
|
+
workflow.add_edge("action", "agent")
|
|
91
|
+
|
|
92
|
+
# Finally, we compile it!
|
|
93
|
+
# This compiles it into a LangChain Runnable,
|
|
94
|
+
# meaning you can use it as you would any other runnable
|
|
95
|
+
graph = workflow.compile()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"python_version": "3.12",
|
|
3
|
+
"dependencies": [
|
|
4
|
+
"langchain_community",
|
|
5
|
+
"langchain_anthropic",
|
|
6
|
+
"langchain_openai",
|
|
7
|
+
"wikipedia",
|
|
8
|
+
"scikit-learn",
|
|
9
|
+
"."
|
|
10
|
+
],
|
|
11
|
+
"graphs": {
|
|
12
|
+
"agent": "./agent.py:graph",
|
|
13
|
+
"storm": "./storm.py:graph"
|
|
14
|
+
},
|
|
15
|
+
"env": "../.env"
|
|
16
|
+
}
|