# LangChain tools

> Use LangChain tools as Pyrula tools.

Source: https://docs.pyrula.io/agents/integrations/langchain/

`from_langchain_tool` wraps a LangChain `BaseTool` as a Pyrula [`@tool`](https://docs.pyrula.io/agents/authoring/tools.md). Needs `pip install "pyrula[agents,langchain]"`.

```python
from pyrula.agents.integrations import from_langchain_tool
from pyrula.agents.decorators.agent import agent

search = from_langchain_tool(my_langchain_tool, timeout=30.0, retry=0)   # also read_only=, writes=

@agent
async def assistant(ctx, message: str) -> None:
    async for _ in ctx.llm.stream(messages=[{"role": "user", "content": message}], tools=[search]):
        ...
```

The input schema comes from `args_schema`, else a single `input: str`. `read_only=True` lets [branches](https://docs.pyrula.io/agents/authoring/tools.md#branches) run it live; `writes=True` marks side effects. Defaults are `False`, so in a branch a plain LangChain tool replays its recorded result or is refused. For a chat model, see [`durable_chat_model`](https://docs.pyrula.io/agents/integrations/durable-vs-not.md#durable_chat_model).

A sync LangChain tool runs in a thread a timeout cannot stop, and the async wrapper is retried on timeout. With `retry>=1`, use an async tool, keep `retry=0`, or make the tool idempotent by its own key (it never sees a Pyrula `ToolContext`). For graphs, see [LangGraph](https://docs.pyrula.io/agents/integrations/langgraph.md).
