mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 18:50:33 +00:00
Widen `bind_tools` to accept `TypedDict` via `Mapping` so that users may
import and use Anthropic's built-in tool types:
```python
import subprocess
from anthropic.types.beta import BetaToolBash20250124Param
from langchain.tools import tool
tool_spec = BetaToolBash20250124Param(
name="bash",
type="bash_20250124",
strict=True,
)
@tool(extras={"provider_tool_definition": tool_spec})
def bash(*, command: str, restart: bool = False, **kw):
"""Execute a bash command."""
if restart:
return "Bash session restarted"
try:
result = subprocess.run(
command,
shell=True,
capture_output=True,
text=True,
timeout=30,
)
return result.stdout + result.stderr
except Exception as e:
return f"Error: {e}"
# Bind bash tool to your model
```
---------
Co-authored-by: Chester Curme <chester.curme@gmail.com>