langchain-claude-code-mimir 0.1.1__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.
- langchain_claude_code_mimir-0.1.1/.github/workflows/publish.yml +47 -0
- langchain_claude_code_mimir-0.1.1/.gitignore +13 -0
- langchain_claude_code_mimir-0.1.1/.python-version +1 -0
- langchain_claude_code_mimir-0.1.1/LICENSE +21 -0
- langchain_claude_code_mimir-0.1.1/PKG-INFO +207 -0
- langchain_claude_code_mimir-0.1.1/README.md +174 -0
- langchain_claude_code_mimir-0.1.1/examples/bind_tools_example.py +51 -0
- langchain_claude_code_mimir-0.1.1/examples/deepagents_example.py +63 -0
- langchain_claude_code_mimir-0.1.1/pyproject.toml +53 -0
- langchain_claude_code_mimir-0.1.1/src/langchain_claude_code/__init__.py +22 -0
- langchain_claude_code_mimir-0.1.1/src/langchain_claude_code/claude_chat_model.py +921 -0
- langchain_claude_code_mimir-0.1.1/src/langchain_claude_code/claude_code_tools.py +41 -0
- langchain_claude_code_mimir-0.1.1/src/langchain_claude_code/py.typed +0 -0
- langchain_claude_code_mimir-0.1.1/tests/test_claude_chat_model.py +710 -0
- langchain_claude_code_mimir-0.1.1/uv.lock +2650 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Publishes langchain-claude-code-mimir to PyPI via OIDC trusted publishing
|
|
4
|
+
# (no API token stored). Fires on a version tag push (v*) or a manual run.
|
|
5
|
+
# PyPI verifies the OIDC claim against the trusted-publisher config registered
|
|
6
|
+
# for this project (owner: jasoncarreira, repo: langchain-claude-code,
|
|
7
|
+
# workflow: publish.yml, environment: <blank>). Register a "pending publisher"
|
|
8
|
+
# on pypi.org BEFORE the first run, or the publish step fails OIDC verification.
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
tags:
|
|
13
|
+
- "v*"
|
|
14
|
+
workflow_dispatch:
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build:
|
|
18
|
+
name: Build sdist + wheel
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v5
|
|
22
|
+
- name: Install uv
|
|
23
|
+
uses: astral-sh/setup-uv@v3
|
|
24
|
+
- name: Build
|
|
25
|
+
run: uv build
|
|
26
|
+
- name: Upload dist artifact
|
|
27
|
+
uses: actions/upload-artifact@v5
|
|
28
|
+
with:
|
|
29
|
+
name: dist
|
|
30
|
+
path: dist/
|
|
31
|
+
|
|
32
|
+
publish:
|
|
33
|
+
name: Publish to PyPI (trusted publishing)
|
|
34
|
+
needs: build
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
permissions:
|
|
37
|
+
# The ONLY extra permission trusted publishing needs: mint an OIDC
|
|
38
|
+
# token the workflow presents to PyPI. No username/password/api-token.
|
|
39
|
+
id-token: write
|
|
40
|
+
steps:
|
|
41
|
+
- name: Download dist artifact
|
|
42
|
+
uses: actions/download-artifact@v5
|
|
43
|
+
with:
|
|
44
|
+
name: dist
|
|
45
|
+
path: dist/
|
|
46
|
+
- name: Publish to PyPI
|
|
47
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tomas Roda
|
|
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,207 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-claude-code-mimir
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: LangChain chat model wrapper for the Claude Code Agent SDK — Mimir distribution of langchain-claude-code with bundled adapter fixes (upstream PRs #2/#4/#6, unmerged). Import package remains ``langchain_claude_code``.
|
|
5
|
+
Project-URL: Homepage, https://github.com/jasoncarreira/langchain-claude-code
|
|
6
|
+
Project-URL: Repository, https://github.com/jasoncarreira/langchain-claude-code
|
|
7
|
+
Project-URL: Issues, https://github.com/jasoncarreira/langchain-claude-code/issues
|
|
8
|
+
Project-URL: Upstream, https://github.com/agentmish/langchain-claude-code
|
|
9
|
+
Author-email: Tomas Roda <dev@tomasroda.com>
|
|
10
|
+
Maintainer: Jason Carreira
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: agent,anthropic,claude,langchain,llm
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: claude-agent-sdk>=0.1.10
|
|
22
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: langgraph>=0.2; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Provides-Extra: examples
|
|
28
|
+
Requires-Dist: ddgs>=9.9.2; extra == 'examples'
|
|
29
|
+
Requires-Dist: deepagents>=0.2.8; extra == 'examples'
|
|
30
|
+
Requires-Dist: langchain-community>=0.4.1; extra == 'examples'
|
|
31
|
+
Requires-Dist: langchain>=1.1.0; extra == 'examples'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# langchain-claude-code
|
|
35
|
+
|
|
36
|
+
[](https://badge.fury.io/py/langchain-claude-code)
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
[](https://www.python.org/downloads/)
|
|
39
|
+
|
|
40
|
+
LangChain chat model wrapper for the Claude Code Agent SDK. Use Claude Code as a drop-in LangChain `BaseChatModel` with full tool support, streaming, and LangGraph compatibility.
|
|
41
|
+
|
|
42
|
+
## Prerequisites
|
|
43
|
+
|
|
44
|
+
**Claude Code CLI** (required):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install -g @anthropic-ai/claude-code
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install langchain-claude-code
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
With example dependencies:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install langchain-claude-code[examples]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Authentication
|
|
63
|
+
|
|
64
|
+
### Option 1: API Key (for Anthropic API users)
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
68
|
+
|
|
69
|
+
model = ClaudeCodeChatModel(api_key="sk-ant-...")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or set the environment variable:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Option 2: OAuth Token (for Claude Max subscribers)
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
82
|
+
|
|
83
|
+
model = ClaudeCodeChatModel(oauth_token="...")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Or set the environment variable:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
export CLAUDE_CODE_OAUTH_TOKEN="..."
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Quick Start
|
|
93
|
+
|
|
94
|
+
### Basic Usage
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import asyncio
|
|
98
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
99
|
+
from langchain_core.messages import HumanMessage
|
|
100
|
+
|
|
101
|
+
async def main():
|
|
102
|
+
model = ClaudeCodeChatModel(model="sonnet")
|
|
103
|
+
response = await model.ainvoke([HumanMessage(content="What is 2 + 2?")])
|
|
104
|
+
print(response.content)
|
|
105
|
+
|
|
106
|
+
asyncio.run(main())
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### With Tool Binding
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
113
|
+
from langchain_community.tools.ddg_search.tool import DuckDuckGoSearchTool
|
|
114
|
+
|
|
115
|
+
model = ClaudeCodeChatModel(model="haiku")
|
|
116
|
+
model = model.bind_tools([DuckDuckGoSearchTool()])
|
|
117
|
+
|
|
118
|
+
response = await model.ainvoke([
|
|
119
|
+
HumanMessage(content="Search for the latest news about AI")
|
|
120
|
+
])
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Using Claude Code's Built-in Tools
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from langchain_claude_code import ClaudeCodeChatModel, ClaudeTool
|
|
127
|
+
|
|
128
|
+
model = ClaudeCodeChatModel(
|
|
129
|
+
model="sonnet",
|
|
130
|
+
allowed_tools=[
|
|
131
|
+
ClaudeTool.WEB_SEARCH,
|
|
132
|
+
ClaudeTool.WEB_FETCH,
|
|
133
|
+
ClaudeTool.BASH,
|
|
134
|
+
ClaudeTool.READ,
|
|
135
|
+
ClaudeTool.WRITE,
|
|
136
|
+
],
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Streaming
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
async for chunk in model.astream([HumanMessage(content="Write a poem")]):
|
|
144
|
+
print(chunk.content, end="", flush=True)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Configuration
|
|
148
|
+
|
|
149
|
+
| Parameter | Type | Default | Description |
|
|
150
|
+
|-----------|------|---------|-------------|
|
|
151
|
+
| `model` | `str` | `"opus"` | Model to use: `opus`, `sonnet`, `haiku` |
|
|
152
|
+
| `permission_mode` | `str` | `"default"` | Permission mode: `default`, `acceptEdits`, `plan`, `bypassPermissions` |
|
|
153
|
+
| `allowed_tools` | `list` | `[]` | List of allowed Claude Code tools |
|
|
154
|
+
| `disallowed_tools` | `list` | `[]` | List of disallowed tools |
|
|
155
|
+
| `system_prompt` | `str` | `None` | Custom system prompt |
|
|
156
|
+
| `max_turns` | `int` | `None` | Maximum conversation turns |
|
|
157
|
+
| `max_budget_usd` | `float` | `None` | Maximum budget in USD |
|
|
158
|
+
| `cwd` | `str` | `None` | Working directory for file operations |
|
|
159
|
+
| `api_key` | `str` | `None` | Anthropic API key |
|
|
160
|
+
| `oauth_token` | `str` | `None` | Claude Code OAuth token |
|
|
161
|
+
|
|
162
|
+
## Permission Modes
|
|
163
|
+
|
|
164
|
+
| Mode | Description |
|
|
165
|
+
|------|-------------|
|
|
166
|
+
| `default` | Prompts for confirmation on potentially dangerous operations |
|
|
167
|
+
| `acceptEdits` | Automatically accepts file edits without confirmation |
|
|
168
|
+
| `plan` | Planning mode - generates plans without executing |
|
|
169
|
+
| `bypassPermissions` | Bypasses all permission checks (use with caution) |
|
|
170
|
+
|
|
171
|
+
> **Security Note**: When using `acceptEdits` or `bypassPermissions`, Claude Code will modify your filesystem without confirmation. Use these modes only in sandboxed environments or when you trust the input.
|
|
172
|
+
|
|
173
|
+
## Available Tools
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from langchain_claude_code import ClaudeTool
|
|
177
|
+
|
|
178
|
+
# File operations
|
|
179
|
+
ClaudeTool.READ
|
|
180
|
+
ClaudeTool.WRITE
|
|
181
|
+
ClaudeTool.EDIT
|
|
182
|
+
ClaudeTool.GLOB
|
|
183
|
+
ClaudeTool.GREP
|
|
184
|
+
|
|
185
|
+
# Shell
|
|
186
|
+
ClaudeTool.BASH
|
|
187
|
+
ClaudeTool.BASH_OUTPUT
|
|
188
|
+
|
|
189
|
+
# Web
|
|
190
|
+
ClaudeTool.WEB_SEARCH
|
|
191
|
+
ClaudeTool.WEB_FETCH
|
|
192
|
+
|
|
193
|
+
# Other
|
|
194
|
+
ClaudeTool.TASK
|
|
195
|
+
ClaudeTool.TODO_WRITE
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Examples
|
|
199
|
+
|
|
200
|
+
See the [examples/](examples/) directory for complete examples:
|
|
201
|
+
|
|
202
|
+
- `bind_tools_example.py` - Using LangChain tools with Claude Code
|
|
203
|
+
- `deepagents_example.py` - Integration with DeepAgents/LangGraph
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# langchain-claude-code
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/langchain-claude-code)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
|
|
7
|
+
LangChain chat model wrapper for the Claude Code Agent SDK. Use Claude Code as a drop-in LangChain `BaseChatModel` with full tool support, streaming, and LangGraph compatibility.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
**Claude Code CLI** (required):
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @anthropic-ai/claude-code
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install langchain-claude-code
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
With example dependencies:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install langchain-claude-code[examples]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Authentication
|
|
30
|
+
|
|
31
|
+
### Option 1: API Key (for Anthropic API users)
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
35
|
+
|
|
36
|
+
model = ClaudeCodeChatModel(api_key="sk-ant-...")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or set the environment variable:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Option 2: OAuth Token (for Claude Max subscribers)
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
49
|
+
|
|
50
|
+
model = ClaudeCodeChatModel(oauth_token="...")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or set the environment variable:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
export CLAUDE_CODE_OAUTH_TOKEN="..."
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
### Basic Usage
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import asyncio
|
|
65
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
66
|
+
from langchain_core.messages import HumanMessage
|
|
67
|
+
|
|
68
|
+
async def main():
|
|
69
|
+
model = ClaudeCodeChatModel(model="sonnet")
|
|
70
|
+
response = await model.ainvoke([HumanMessage(content="What is 2 + 2?")])
|
|
71
|
+
print(response.content)
|
|
72
|
+
|
|
73
|
+
asyncio.run(main())
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### With Tool Binding
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
80
|
+
from langchain_community.tools.ddg_search.tool import DuckDuckGoSearchTool
|
|
81
|
+
|
|
82
|
+
model = ClaudeCodeChatModel(model="haiku")
|
|
83
|
+
model = model.bind_tools([DuckDuckGoSearchTool()])
|
|
84
|
+
|
|
85
|
+
response = await model.ainvoke([
|
|
86
|
+
HumanMessage(content="Search for the latest news about AI")
|
|
87
|
+
])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Using Claude Code's Built-in Tools
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from langchain_claude_code import ClaudeCodeChatModel, ClaudeTool
|
|
94
|
+
|
|
95
|
+
model = ClaudeCodeChatModel(
|
|
96
|
+
model="sonnet",
|
|
97
|
+
allowed_tools=[
|
|
98
|
+
ClaudeTool.WEB_SEARCH,
|
|
99
|
+
ClaudeTool.WEB_FETCH,
|
|
100
|
+
ClaudeTool.BASH,
|
|
101
|
+
ClaudeTool.READ,
|
|
102
|
+
ClaudeTool.WRITE,
|
|
103
|
+
],
|
|
104
|
+
)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Streaming
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
async for chunk in model.astream([HumanMessage(content="Write a poem")]):
|
|
111
|
+
print(chunk.content, end="", flush=True)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
| Parameter | Type | Default | Description |
|
|
117
|
+
|-----------|------|---------|-------------|
|
|
118
|
+
| `model` | `str` | `"opus"` | Model to use: `opus`, `sonnet`, `haiku` |
|
|
119
|
+
| `permission_mode` | `str` | `"default"` | Permission mode: `default`, `acceptEdits`, `plan`, `bypassPermissions` |
|
|
120
|
+
| `allowed_tools` | `list` | `[]` | List of allowed Claude Code tools |
|
|
121
|
+
| `disallowed_tools` | `list` | `[]` | List of disallowed tools |
|
|
122
|
+
| `system_prompt` | `str` | `None` | Custom system prompt |
|
|
123
|
+
| `max_turns` | `int` | `None` | Maximum conversation turns |
|
|
124
|
+
| `max_budget_usd` | `float` | `None` | Maximum budget in USD |
|
|
125
|
+
| `cwd` | `str` | `None` | Working directory for file operations |
|
|
126
|
+
| `api_key` | `str` | `None` | Anthropic API key |
|
|
127
|
+
| `oauth_token` | `str` | `None` | Claude Code OAuth token |
|
|
128
|
+
|
|
129
|
+
## Permission Modes
|
|
130
|
+
|
|
131
|
+
| Mode | Description |
|
|
132
|
+
|------|-------------|
|
|
133
|
+
| `default` | Prompts for confirmation on potentially dangerous operations |
|
|
134
|
+
| `acceptEdits` | Automatically accepts file edits without confirmation |
|
|
135
|
+
| `plan` | Planning mode - generates plans without executing |
|
|
136
|
+
| `bypassPermissions` | Bypasses all permission checks (use with caution) |
|
|
137
|
+
|
|
138
|
+
> **Security Note**: When using `acceptEdits` or `bypassPermissions`, Claude Code will modify your filesystem without confirmation. Use these modes only in sandboxed environments or when you trust the input.
|
|
139
|
+
|
|
140
|
+
## Available Tools
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from langchain_claude_code import ClaudeTool
|
|
144
|
+
|
|
145
|
+
# File operations
|
|
146
|
+
ClaudeTool.READ
|
|
147
|
+
ClaudeTool.WRITE
|
|
148
|
+
ClaudeTool.EDIT
|
|
149
|
+
ClaudeTool.GLOB
|
|
150
|
+
ClaudeTool.GREP
|
|
151
|
+
|
|
152
|
+
# Shell
|
|
153
|
+
ClaudeTool.BASH
|
|
154
|
+
ClaudeTool.BASH_OUTPUT
|
|
155
|
+
|
|
156
|
+
# Web
|
|
157
|
+
ClaudeTool.WEB_SEARCH
|
|
158
|
+
ClaudeTool.WEB_FETCH
|
|
159
|
+
|
|
160
|
+
# Other
|
|
161
|
+
ClaudeTool.TASK
|
|
162
|
+
ClaudeTool.TODO_WRITE
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Examples
|
|
166
|
+
|
|
167
|
+
See the [examples/](examples/) directory for complete examples:
|
|
168
|
+
|
|
169
|
+
- `bind_tools_example.py` - Using LangChain tools with Claude Code
|
|
170
|
+
- `deepagents_example.py` - Integration with DeepAgents/LangGraph
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Example: Binding LangChain tools to ClaudeCodeChatModel.
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to use DuckDuckGo search with Claude Code.
|
|
4
|
+
|
|
5
|
+
Prerequisites:
|
|
6
|
+
pip install langchain-claude-code[examples]
|
|
7
|
+
npm install -g @anthropic-ai/claude-code
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import asyncio
|
|
11
|
+
|
|
12
|
+
from langchain_claude_code import ClaudeCodeChatModel
|
|
13
|
+
from langchain_community.tools.ddg_search.tool import DuckDuckGoSearchTool
|
|
14
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
async def main():
|
|
18
|
+
model = ClaudeCodeChatModel(
|
|
19
|
+
model="haiku",
|
|
20
|
+
permission_mode="acceptEdits",
|
|
21
|
+
)
|
|
22
|
+
model = model.bind_tools([DuckDuckGoSearchTool()])
|
|
23
|
+
|
|
24
|
+
messages = [
|
|
25
|
+
SystemMessage(content="You are a helpful web search assistant."),
|
|
26
|
+
HumanMessage(
|
|
27
|
+
content="Using DuckDuckGo, find out the exact release date of Gemini 3 Pro"
|
|
28
|
+
),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
res = await model.ainvoke(messages)
|
|
32
|
+
|
|
33
|
+
print("\n=== Tool Calls ===")
|
|
34
|
+
for tc in (
|
|
35
|
+
res.response_metadata.get("internal_tool_calls", [])
|
|
36
|
+
if res.response_metadata
|
|
37
|
+
else []
|
|
38
|
+
):
|
|
39
|
+
print(tc)
|
|
40
|
+
|
|
41
|
+
print("\n=== Content (includes tool output) ===")
|
|
42
|
+
print(res.content)
|
|
43
|
+
|
|
44
|
+
if res.response_metadata:
|
|
45
|
+
cost = res.response_metadata.get("total_cost_usd")
|
|
46
|
+
if cost is not None:
|
|
47
|
+
print(f"\nCost: ${cost:.6f}")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Example: Using ClaudeCodeChatModel with DeepAgents/LangGraph.
|
|
2
|
+
|
|
3
|
+
This example demonstrates integration with the deepagents library for
|
|
4
|
+
building complex agent workflows.
|
|
5
|
+
|
|
6
|
+
Prerequisites:
|
|
7
|
+
pip install langchain-claude-code[examples]
|
|
8
|
+
npm install -g @anthropic-ai/claude-code
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
from deepagents import create_deep_agent
|
|
14
|
+
from langchain_core.messages import AIMessage
|
|
15
|
+
|
|
16
|
+
from langchain_claude_code import ClaudeCodeChatModel, ClaudeTool
|
|
17
|
+
|
|
18
|
+
system_prompt = (
|
|
19
|
+
"You are an expert researcher. Your job is to conduct thorough "
|
|
20
|
+
"research and then write a polished report."
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
model = ClaudeCodeChatModel(
|
|
24
|
+
model="haiku",
|
|
25
|
+
permission_mode="acceptEdits",
|
|
26
|
+
allowed_tools=[
|
|
27
|
+
ClaudeTool.WEB_FETCH,
|
|
28
|
+
ClaudeTool.WEB_SEARCH,
|
|
29
|
+
ClaudeTool.BASH,
|
|
30
|
+
ClaudeTool.BASH_OUTPUT,
|
|
31
|
+
],
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
agent = create_deep_agent(
|
|
35
|
+
model=model,
|
|
36
|
+
name="Claude Code Agent",
|
|
37
|
+
system_prompt=system_prompt,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
for chunk, meta in agent.stream(
|
|
42
|
+
{
|
|
43
|
+
"messages": [
|
|
44
|
+
{
|
|
45
|
+
"role": "user",
|
|
46
|
+
"content": (
|
|
47
|
+
"What is langgraph? If you could not perform web searches "
|
|
48
|
+
"you must explicitly say so."
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
stream_mode="messages",
|
|
54
|
+
):
|
|
55
|
+
if (
|
|
56
|
+
type(chunk) == AIMessage
|
|
57
|
+
and chunk.tool_calls is not None
|
|
58
|
+
and len(chunk.tool_calls)
|
|
59
|
+
):
|
|
60
|
+
for tc in chunk.tool_calls:
|
|
61
|
+
print(f"Tool call: {json.dumps(tc)}")
|
|
62
|
+
else:
|
|
63
|
+
chunk.pretty_print()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "langchain-claude-code-mimir"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
description = "LangChain chat model wrapper for the Claude Code Agent SDK — Mimir distribution of langchain-claude-code with bundled adapter fixes (upstream PRs #2/#4/#6, unmerged). Import package remains ``langchain_claude_code``."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
requires-python = ">=3.11"
|
|
8
|
+
authors = [{ name = "Tomas Roda", email = "dev@tomasroda.com" }]
|
|
9
|
+
maintainers = [{ name = "Jason Carreira" }]
|
|
10
|
+
keywords = ["langchain", "claude", "anthropic", "agent", "llm"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Programming Language :: Python :: 3.11",
|
|
16
|
+
"Programming Language :: Python :: 3.12",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
18
|
+
]
|
|
19
|
+
dependencies = ["claude-agent-sdk>=0.1.10", "langchain-core>=0.3.0"]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
examples = [
|
|
23
|
+
"ddgs>=9.9.2",
|
|
24
|
+
"deepagents>=0.2.8",
|
|
25
|
+
"langchain>=1.1.0",
|
|
26
|
+
"langchain-community>=0.4.1",
|
|
27
|
+
]
|
|
28
|
+
dev = [
|
|
29
|
+
"pytest>=8.0",
|
|
30
|
+
"pytest-asyncio>=0.24",
|
|
31
|
+
# Used in the runtime-injected-args skip test — verifies our bridge
|
|
32
|
+
# filters out tools annotated with langgraph's ``ToolRuntime``.
|
|
33
|
+
# Runtime is optional at production time (the helper falls back to
|
|
34
|
+
# returning False if langgraph isn't installed), so it lives in
|
|
35
|
+
# ``dev`` rather than core ``dependencies``.
|
|
36
|
+
"langgraph>=0.2",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/jasoncarreira/langchain-claude-code"
|
|
41
|
+
Repository = "https://github.com/jasoncarreira/langchain-claude-code"
|
|
42
|
+
Issues = "https://github.com/jasoncarreira/langchain-claude-code/issues"
|
|
43
|
+
Upstream = "https://github.com/agentmish/langchain-claude-code"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["hatchling"]
|
|
47
|
+
build-backend = "hatchling.build"
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/langchain_claude_code"]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.sdist]
|
|
53
|
+
exclude = ["digest.txt", "docs/", ".cursor/", "AGENTS.md"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from langchain_claude_code.claude_chat_model import ClaudeCodeChatModel
|
|
2
|
+
from langchain_claude_code.claude_code_tools import (
|
|
3
|
+
ClaudeTool,
|
|
4
|
+
normalize_tools,
|
|
5
|
+
DEFAULT_READ_ONLY,
|
|
6
|
+
DEFAULT_WRITE,
|
|
7
|
+
DEFAULT_NETWORK,
|
|
8
|
+
DEFAULT_SHELL,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
ChatClaudeCode = ClaudeCodeChatModel
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"ClaudeCodeChatModel",
|
|
15
|
+
"ChatClaudeCode",
|
|
16
|
+
"ClaudeTool",
|
|
17
|
+
"normalize_tools",
|
|
18
|
+
"DEFAULT_READ_ONLY",
|
|
19
|
+
"DEFAULT_WRITE",
|
|
20
|
+
"DEFAULT_NETWORK",
|
|
21
|
+
"DEFAULT_SHELL",
|
|
22
|
+
]
|