LangChain tool for ADK¶
The LangchainTool wrapper adapts LangChain tools and LangChain-compatible tool objects so your ADK agents can call them directly. Instead of rewriting existing tool definitions, you wrap a tool instance and register it in your agent's tools list. The adapter translates parameter schemas into model-compatible function declarations, preserves tool metadata, and forwards arguments during execution.
Use cases¶
- Reuse existing LangChain tools: Bring prebuilt and custom LangChain tools into ADK agents without rewriting execution logic or parameter schemas.
- Structured parameter validation: Wrap structured tools backed by Pydantic models, Zod schemas, or JSON Schema definitions so the model receives typed argument declarations.
- Direct tool responses: Return raw tool output directly to the caller without an extra model summarization step when a wrapped tool sets parameter
return_direct=True.
Prerequisites¶
- Python 3.11 or later for ADK Python, or Node.js 20.19 or later for ADK TypeScript.
- An ADK project configured with model credentials, such as a Gemini API key set
in
GOOGLE_API_KEY. - Any API keys or additional dependencies required by the specific LangChain tool you wrap.
Installation¶
Follow the instructions below to install this integration.
LangChain community tool packages
If you are using LangChain community tool packages, make sure you also install them into your ADK agent development environment.
Use with agent¶
Wrap a LangChain tool with LangchainTool and pass it to your agent's tools
list:
from google.adk.agents import Agent
from google.adk.integrations.langchain import LangchainTool
from langchain_core.tools import tool
@tool
def calculate_order_total(unit_price: float, quantity: int) -> float:
"""Calculate the total price for an order."""
return unit_price * quantity
adk_order_tool = LangchainTool(tool=calculate_order_total)
root_agent = Agent(
model="gemini-flash-latest",
name="langchain_tool_agent",
instruction="Help users calculate order totals using the available tool.",
tools=[adk_order_tool],
)
import { LlmAgent } from "@google/adk";
import { LangchainTool } from "@google/adk-integrations";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const calculateOrderTotal = tool(
async ({ unitPrice, quantity }) => unitPrice * quantity,
{
name: "calculate_order_total",
description: "Calculate the total price for an order.",
schema: z.object({
unitPrice: z.number().describe("Price per unit"),
quantity: z.number().int().describe("Number of units"),
}),
},
);
const adkOrderTool = new LangchainTool(calculateOrderTotal);
const rootAgent = new LlmAgent({
model: "gemini-flash-latest",
name: "langchain_tool_agent",
instruction: "Help users calculate order totals using the available tool.",
tools: [adkOrderTool],
});
export { rootAgent };
Available tools¶
This integration wraps supported LangChain tools you provide rather than
exposing a fixed catalog of endpoints. For tool requirements and constraints,
see Limitations. In ADK Python, wrap any
langchain_core.tools.BaseTool instance, including StructuredTool and
@tool-decorated functions, or any object implementing a run or _run
method. In ADK TypeScript, wrap any object that satisfies the
LangchainToolLike type, including tools created with @langchain/core/tools.
The integration exports the following classes, functions, and types:
| Symbol | Language | Description |
|---|---|---|
LangchainTool |
Python, TypeScript | Wraps a LangChain tool as an ADK FunctionTool, translating its schema and forwarding calls. |
LangchainToolConfig |
Python, TypeScript | Configuration schema for creating a LangchainTool from an Agent Config file in ADK Python or from constructor options in ADK TypeScript. |
isLangchainTool |
TypeScript | Type guard that checks whether an object is an instance of LangchainTool. |
LangchainToolLike |
TypeScript | Structural type for a LangChain-compatible tool object with optional name, description, argsSchema, schema, args, and a runner method: invoke, call, run, func, _run, or _call. |
LangchainSchemaLike |
TypeScript | Accepted parameter schema types: ADK SchemaLike such as Zod schemas, objects with toJsonSchema(), jsonSchema(), or modelJsonSchema(), or plain JSON Schema objects. |
Configuration¶
Configure how the LangChain tool exposes a wrapped tool to your agent by overriding its name and description. By default, ADK inherits metadata and parameter schemas from the wrapped tool and adapts its execution behavior—such as async calls, return_direct, runner resolution, and context forwarding—to match the ADK runtime.
Constructor and config options¶
Override the wrapped tool's name and description when creating a
LangchainTool:
| Option | Required | Default | Description |
|---|---|---|---|
tool |
Yes | None | LangChain tool instance to wrap, or its fully qualified import path in ADK Python Agent Config files. |
name |
No | tool.name |
Custom tool name exposed to the model. Falls back to the wrapped function's name (or "langchain_tool" in TypeScript) when absent. |
description |
No | tool.description |
Custom tool description exposed to the model. Falls back to the wrapped function's docstring in Python, or "" if absent. |
In ADK Python Agent Config files, LangchainToolConfig defaults omitted name
and description fields to "" and overrides the wrapped tool's metadata, so
specify both fields explicitly in YAML.
Structured schemas and execution behavior¶
During tool declaration and execution, LangchainTool adapts LangChain schemas
and execution conventions to ADK:
- Structured tools and async functions: Wrap
StructuredToolinstances with a synchronousfuncor an asynchronouscoroutineand a Pydanticargs_schema. ADK builds the model function declaration fromargs_schemaand ignores LangChain's internalrun_managerparameter. - Direct returns: When a wrapped tool sets
return_direct=True, ADK setstool_context.actions.skip_summarization = Trueafter a successful call so the raw result returns directly. If the tool returns an error dictionary with a truthy"error"key, such as a missing-argument error, ADK keeps summarization enabled so the model can observe the error and retry. - Canonical import path: Import
LangchainToolfromgoogle.adk.integrations.langchain. The oldergoogle.adk.tools.langchain_toolpath is deprecated.
from google.adk.integrations.langchain import LangchainTool
from langchain_core.tools.structured import StructuredTool
from pydantic import BaseModel, Field
class AddInput(BaseModel):
x: int = Field(..., description="First integer")
y: int = Field(..., description="Second integer")
async def add_numbers(x: int, y: int) -> int:
return x + y
structured_tool = StructuredTool.from_function(
coroutine=add_numbers,
name="add_numbers",
description="Adds two integers together.",
args_schema=AddInput,
)
adk_add_tool = LangchainTool(
tool=structured_tool,
name="sum_two_integers",
description="Compute the sum of two integers.",
)
- Constructor forms: Construct
LangchainToolwith either a tool instance and an optional overrides object,new LangchainTool(tool, { name, description }), or a singleLangchainToolConfigobject,new LangchainTool({ tool, name, description }). - Runner resolution: ADK resolves the tool's execution method in order:
invoke,call,run,func,_run, then_call. Prefer public entrypoints such asinvokeorcallwhen available so LangChain validates inputs once. - Schema sources: ADK extracts parameter definitions from
tool.args,tool.argsSchema, ortool.schema, supporting Zod schemas, objects withtoJsonSchema(),jsonSchema(), ormodelJsonSchema(), and plain JSON Schema objects. - Context forwarding: ADK passes the optional ADK
Contextas the second argument when callinginvoke,call,run,_run, or_call. When wrapping afunc-onlyDynamicTool, ADK passes only the arguments object.
import type { Context } from "@google/adk";
import { LangchainTool } from "@google/adk-integrations";
import { z } from "zod";
const sessionLookupTool = new LangchainTool({
name: "lookup_session_note",
description: "Look up a note scoped to the current session.",
tool: {
argsSchema: z.object({
key: z.string().describe("Note key to look up"),
}),
_run: (args: Record<string, unknown>, toolContext?: Context) => {
const sessionId = toolContext?.sessionId ?? "unknown";
return `Fetched '${String(args.key)}' for session ${sessionId}`;
},
},
});
Load from Agent Config¶
Load a LangchainTool from an Agent Config YAML file using
LangchainTool.from_config and LangchainToolConfig. Set tool to the fully
qualified Python import path of an existing LangChain tool instance, and specify
name and description explicitly so ADK does not overwrite them with empty
strings:
tools:
- name: google.adk.integrations.langchain.LangchainTool
args:
tool: my_package.my_tools.calculate_order_total
name: calculate_order_total
description: Calculate the total price for an order.
Limitations¶
-
Required execution method: LangChain tools must include specific syntax to work effectively with your ADK agent.
- ADK Python: The wrapped object must define a
runor_runmethod, and aStructuredToolmust definefunc,coroutine, or a subclass_runoverride, or initialization raisesValueError. - ADK TypeScript: The wrapped object must define
invoke,call,run,func,_run, or_call, or initialization throwsTypeError.
- ADK Python: The wrapped object must define a
-
LangChain runtime-injected parameters: LangChain tools that rely on LangGraph-specific runtime injection, such as
ToolRuntimeorCommandstate updates, require a LangGraph execution runtime, andLangchainTooldoes not populate those parameters automatically.