batch-bridge 0.0.1rc0__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.
@@ -0,0 +1,173 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # PyPI configuration file
171
+ .pypirc
172
+ .DS_Store
173
+ .langgraph_api/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 LangChain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ .PHONY: lint-docs format-docs build-docs serve-docs serve-clean-docs clean-docs codespell build-typedoc doctest
2
+
3
+ build-docs:
4
+ uv run --with-editable . python -m mkdocs build --clean -f docs/mkdocs.yml --strict
5
+
6
+ serve-clean-docs: clean-docs
7
+ uv run --with-editable . python -m mkdocs serve -c -f docs/mkdocs.yml --strict -w ./src/langmem
8
+
9
+ serve-docs: build-typedoc
10
+ uv run --with-editable . python -m mkdocs serve -f docs/mkdocs.yml -w ./src/langmem -w README.md
11
+
12
+ ## Run format against the project documentation.
13
+ format-docs:
14
+ uv run ruff format docs/docs
15
+ uv run ruff check --fix docs/docs
16
+
17
+ doctest:
18
+ @echo "Starting langgraph server..."
19
+ uvx --refresh --from "langgraph-cli[inmem]" --with-editable . --python 3.11 langgraph dev --no-browser > /dev/null 2>&1 & echo $$! > .langgraph.pid
20
+ @echo "Waiting for server to start..."
21
+ @sleep 2
22
+ @echo "Running tests..."
23
+ uv run --with-editable . python -m pytest tests/test_docstring_examples.py -vvv -n auto $(if $(k),-k "$(k)",) || (kill `cat .langgraph.pid` && rm .langgraph.pid && exit 1)
24
+ @echo "Cleaning up server..."
25
+ @kill `cat .langgraph.pid` && rm .langgraph.pid
26
+
27
+ doctest-watch:
28
+ @echo "Starting langgraph server..."
29
+ uvx --refresh --from "langgraph-cli[inmem]" --with-editable . --python 3.11 langgraph dev --no-browser > /dev/null 2>&1 & echo $$! > .langgraph.pid
30
+ @echo "Waiting for server to start..."
31
+ @sleep 2
32
+ @echo "Starting test watcher..."
33
+ PYTHONPATH=src uv run --with-editable . ptw tests/test_docstring_examples.py -- -vvv --last-failed --new-first $(if $(k),-k='$(k)',) || (kill `cat .langgraph.pid` && rm .langgraph.pid && exit 1)
34
+ @echo "Cleaning up server..."
35
+ @kill `cat .langgraph.pid` && rm .langgraph.pid
36
+
37
+
38
+ format:
39
+ uv run ruff format ./src
40
+ uv run ruff check --fix ./src
41
+
42
+ lint:
43
+ uv run ruff format --check ./src
44
+ uv run ruff check ./src
45
+ uv run mypy ./src
46
+
47
+ # Check the docs for linting violations
48
+ lint-docs:
49
+ uv run ruff format --check docs/docs
50
+ uv run ruff check docs/docs
51
+
52
+ uv run ruff format --check docs/docs
53
+ uv run ruff check docs/docs
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.4
2
+ Name: batch-bridge
3
+ Version: 0.0.1rc0
4
+ Summary: Prebuilt utilities for memory management and retrieval.
5
+ License: MIT License
6
+
7
+ Copyright (c) 2025 LangChain
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ License-File: LICENSE
27
+ Requires-Python: >=3.11
28
+ Requires-Dist: langgraph-api>=0.0.33
29
+ Requires-Dist: langgraph>=0.2.66
30
+ Description-Content-Type: text/markdown
31
+
32
+ # BatchBridge
33
+
34
+ BatchBridge is a library for efficient batch processing with LangGraph. It provides a mechanism to collect items, process them in batches, and handle results asynchronously using LangGraph's interrupt semantics.
35
+
36
+ ## What is BatchBridge?
37
+
38
+ Batch APIs can cut AI inference costs by 50% or more, but they're difficult to use in agent workflows. They force you to manually aggregate requests and design your entire agent loop around batch processing rather than focusing on individual tasks. This makes your code more complex, harder to maintain, and less shareable.
39
+
40
+ BatchBridge solves this by making batch APIs work like standard completion APIs in LangGraph. Your code makes normal API calls while BatchBridge handles batching, submission, polling, and resumption behind the scenes. This lets you design and improve an agent using single completions, then make a one-line change to let it economically scale.
41
+
42
+ We aim to give you significant cost savings with minimal code complexity.
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ pip install -e .
48
+ ```
49
+
50
+ Since BatchBridge relies on LangGraph's durable execution and cron functionality, it must be
51
+ run on the LangGraph platform.
52
+
53
+
54
+ ## Example with OpenAI's Batch API
55
+
56
+ BatchBridge has a native integration with OpenAI's Batch API:
57
+
58
+ ```python
59
+ from batch_bridge import patch_openai
60
+ from openai import AsyncOpenAI
61
+ from langgraph.graph import StateGraph
62
+ from typing_extensions import Annotated, TypedDict
63
+
64
+ # Patch the client at the global level
65
+ client = patch_openai(AsyncOpenAI())
66
+
67
+
68
+ class State(TypedDict):
69
+ messages: Annotated[list[dict], lambda x, y: x + y]
70
+
71
+
72
+ async def my_model(state: State):
73
+ # This will:
74
+ # 1. submit the message to our bridge graph
75
+ # 2. Interrupt this agent graph.
76
+ # 3. resume once the bridge graph detects that the batch is complete
77
+ result = await client.chat.completions.create(
78
+ model="gpt-4o-mini", messages=state["messages"]
79
+ )
80
+ return {"messages": [result]}
81
+
82
+
83
+ graph = StateGraph(State).add_node(my_model).add_edge("__start__", "my_model").compile()
84
+ ```
85
+
86
+ ## Basic Usage
87
+
88
+ Under the hood, BatchBridge relies on two basic functions:
89
+ a submit() function and a poll() function.
90
+
91
+ Here's a simple example of how to use BatchBridge:
92
+
93
+ ```python
94
+ from datetime import datetime, timedelta
95
+ from batch_bridge import Batcher
96
+
97
+ # Define functions for batch processing
98
+ def submit_batch(items):
99
+ """Submit a batch of items for processing."""
100
+ # In a real implementation, this would submit to an external API
101
+ # and return a batch ID
102
+ print(f"Submitting batch of {len(items)} items")
103
+ return "batch_123"
104
+
105
+ def poll_batch(batch_id):
106
+ """Poll for the results of a batch."""
107
+ # In a real implementation, this would check the status of the batch
108
+ # and return results when available
109
+ import time
110
+ time.sleep(2) # Simulate processing time
111
+ return [f"Processed: {item}" for item in ["item1", "item2"]]
112
+
113
+ # Create a batcher with default flush criteria
114
+ batcher = Batcher(
115
+ submit_func=submit_batch,
116
+ poll_func=poll_batch,
117
+ )
118
+ ```
119
+
120
+ ## License
121
+
122
+ MIT
@@ -0,0 +1,91 @@
1
+ # BatchBridge
2
+
3
+ BatchBridge is a library for efficient batch processing with LangGraph. It provides a mechanism to collect items, process them in batches, and handle results asynchronously using LangGraph's interrupt semantics.
4
+
5
+ ## What is BatchBridge?
6
+
7
+ Batch APIs can cut AI inference costs by 50% or more, but they're difficult to use in agent workflows. They force you to manually aggregate requests and design your entire agent loop around batch processing rather than focusing on individual tasks. This makes your code more complex, harder to maintain, and less shareable.
8
+
9
+ BatchBridge solves this by making batch APIs work like standard completion APIs in LangGraph. Your code makes normal API calls while BatchBridge handles batching, submission, polling, and resumption behind the scenes. This lets you design and improve an agent using single completions, then make a one-line change to let it economically scale.
10
+
11
+ We aim to give you significant cost savings with minimal code complexity.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install -e .
17
+ ```
18
+
19
+ Since BatchBridge relies on LangGraph's durable execution and cron functionality, it must be
20
+ run on the LangGraph platform.
21
+
22
+
23
+ ## Example with OpenAI's Batch API
24
+
25
+ BatchBridge has a native integration with OpenAI's Batch API:
26
+
27
+ ```python
28
+ from batch_bridge import patch_openai
29
+ from openai import AsyncOpenAI
30
+ from langgraph.graph import StateGraph
31
+ from typing_extensions import Annotated, TypedDict
32
+
33
+ # Patch the client at the global level
34
+ client = patch_openai(AsyncOpenAI())
35
+
36
+
37
+ class State(TypedDict):
38
+ messages: Annotated[list[dict], lambda x, y: x + y]
39
+
40
+
41
+ async def my_model(state: State):
42
+ # This will:
43
+ # 1. submit the message to our bridge graph
44
+ # 2. Interrupt this agent graph.
45
+ # 3. resume once the bridge graph detects that the batch is complete
46
+ result = await client.chat.completions.create(
47
+ model="gpt-4o-mini", messages=state["messages"]
48
+ )
49
+ return {"messages": [result]}
50
+
51
+
52
+ graph = StateGraph(State).add_node(my_model).add_edge("__start__", "my_model").compile()
53
+ ```
54
+
55
+ ## Basic Usage
56
+
57
+ Under the hood, BatchBridge relies on two basic functions:
58
+ a submit() function and a poll() function.
59
+
60
+ Here's a simple example of how to use BatchBridge:
61
+
62
+ ```python
63
+ from datetime import datetime, timedelta
64
+ from batch_bridge import Batcher
65
+
66
+ # Define functions for batch processing
67
+ def submit_batch(items):
68
+ """Submit a batch of items for processing."""
69
+ # In a real implementation, this would submit to an external API
70
+ # and return a batch ID
71
+ print(f"Submitting batch of {len(items)} items")
72
+ return "batch_123"
73
+
74
+ def poll_batch(batch_id):
75
+ """Poll for the results of a batch."""
76
+ # In a real implementation, this would check the status of the batch
77
+ # and return results when available
78
+ import time
79
+ time.sleep(2) # Simulate processing time
80
+ return [f"Processed: {item}" for item in ["item1", "item2"]]
81
+
82
+ # Create a batcher with default flush criteria
83
+ batcher = Batcher(
84
+ submit_func=submit_batch,
85
+ poll_func=poll_batch,
86
+ )
87
+ ```
88
+
89
+ ## License
90
+
91
+ MIT
@@ -0,0 +1,18 @@
1
+ {
2
+ "dependencies": ["."],
3
+ "graphs": {
4
+ "optimize_prompts": "./src/langmem/graphs/prompts.py:optimize_prompts",
5
+ "extract_memories": "./src/langmem/graphs/semantic.py:graph"
6
+ },
7
+ "env": ".env",
8
+ "auth": {
9
+ "path": "./src/langmem/graphs/auth.py:auth"
10
+ },
11
+ "store": {
12
+ "index": {
13
+ "embed": "openai:text-embedding-3-small",
14
+ "dims": 1536,
15
+ "fields": ["$"]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,83 @@
1
+ [project]
2
+ name = "batch-bridge"
3
+ version = "0.0.1-rc0"
4
+ description = "Prebuilt utilities for memory management and retrieval."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = { file = "LICENSE" }
8
+ dependencies = [
9
+ "langgraph>=0.2.66",
10
+ "langgraph-api>=0.0.33",
11
+ ]
12
+
13
+ [project.packages]
14
+ find = { where = ["src"] }
15
+
16
+ [build-system]
17
+ requires = ["hatchling"]
18
+ build-backend = "hatchling.build"
19
+
20
+ [dependency-groups]
21
+ dev = [
22
+ "anyio>=4.8.0",
23
+ "langgraph-cli[inmem]>=0.1.70",
24
+ "pytest>=8.3.4",
25
+ "pytest-watch>=4.2.0",
26
+ "pytest-xdist>=3.6.1",
27
+ ]
28
+ docs = [
29
+ "markdown-callouts>=0.4.0",
30
+ "markdown-include>=0.8.1",
31
+ "mkdocs>=1.6.1",
32
+ "mkdocs-autorefs>=1.3.0",
33
+ "mkdocs-exclude>=1.0.2",
34
+ "mkdocs-git-committers-plugin-2>=2.5.0",
35
+ "mkdocs-material>=9.6.1",
36
+ "mkdocs-minify-plugin>=0.8.0",
37
+ "mkdocs-redirects>=1.2.2",
38
+ "mkdocs-rss-plugin>=1.17.1",
39
+ "mkdocstrings>=0.27.0",
40
+ "mkdocstrings-python>=1.13.0",
41
+ "ruff>=0.9.4",
42
+ "nbformat>=5.10.4",
43
+ "nbconvert>=7.16.6",
44
+ ]
45
+
46
+ [tool.uv.workspace]
47
+ members = ["examples"]
48
+
49
+ [tool.ruff]
50
+ lint.select = ["E", "F", "I", "TID251"]
51
+ lint.ignore = ["E501"]
52
+ line-length = 88
53
+ indent-width = 4
54
+ extend-include = ["*.ipynb"]
55
+
56
+ [tool.ruff.format]
57
+ quote-style = "double"
58
+ indent-style = "space"
59
+ skip-magic-trailing-comma = false
60
+ line-ending = "auto"
61
+ docstring-code-format = true
62
+ docstring-code-line-length = "dynamic"
63
+
64
+ [tool.ruff.lint.flake8-tidy-imports.banned-api]
65
+ "typing.TypedDict".msg = "Use typing_extensions.TypedDict instead."
66
+
67
+ [tool.hatch.build]
68
+ exclude = [
69
+ "tests/",
70
+ "docs/",
71
+ ".github/",
72
+ "examples.py",
73
+ "examples/",
74
+ ".editorconfig",
75
+ "db/",
76
+ "evals/",
77
+ ".langgraph_api",
78
+ "*.ipynb",
79
+ ".python-version",
80
+ ".editorconfig",
81
+ ".venv*/**",
82
+ "pytest.ini",
83
+ ]
@@ -0,0 +1,10 @@
1
+ """BatchBridge: A library for batch processing with LangGraph.
2
+
3
+ This library provides functionality for batching items and processing them in bulk,
4
+ integrating with LangGraph's interrupt semantics for efficient batch handling.
5
+ """
6
+
7
+ from batch_bridge._base import Bridge, wait
8
+ from batch_bridge._openai import patch_openai
9
+
10
+ __all__ = ["Bridge", "wait", "patch_openai"]