Retrievers (RAG) for Google ADK that uses langchain
Project description
Langchain Retrievers for Google ADK
Install
uv add adk-retrieval
Usage
This library exposes LangchainRetrievalTool which is a Google ADK tool.
The tool expects an instance of langchain retriever (See - https://docs.langchain.com/oss/python/integrations/retrievers)
By default LangchainRetrievalTool returns str which is the page_content of the first langchain Document. If that satisfies your needs then
look at the basic example below.
In some cases, you would want to post-process the documents and convert them to str as you see fit. In that case, you can either write your own Retriever or use the callback. See the little sophisticated example below.
Basic example
Below is a basic example that shows how to use a retriever from langchain in Google ADK agent.
The first (langchain) document's page_content is returned by LangchainRetrievalTool irrespective of any top_k you may have used in your langchain Retriever.
import wikipedia
from google.adk.agents import LlmAgent
from langchain_community.retrievers import WikipediaRetriever
from adk_retrieval import LangchainRetrievalTool
root_agent = LlmAgent(
name="adk_wikipedia_agent",
description="Agent for summarizing Wikipedia articles.",
instruction="""You are a specialized search & summarizer agent for Wikipedia articles.
""",
model="gemini-2.5-flash",
tools=[
LangchainRetrievalTool(
name="wikipedia_retrieval_tool",
description="Tool for retrieving Wikipedia articles based on user queries.",
retriever=WikipediaRetriever(wiki_client=wikipedia),
)
],
)
A little sophisticated example
This example shows how you provide your own callback that takes all the documents returned by your langchain Retriever and convert them into a single string.
import wikipedia
from google.adk.agents import LlmAgent
from langchain_community.retrievers import WikipediaRetriever
from langchain_core.documents import Document
from adk_retrieval import LangchainRetrievalTool
# an example post-processing function that combines multiple documents into a single string
async def post_process(docs: list[Document]) -> str:
sources = []
for index, doc in enumerate(docs):
sources.append(f"Source {index + 1}:\n{doc.page_content}\n")
return "\n\n".join(sources)
root_agent = LlmAgent(
name="wiki_sophisticated",
description="Agent for summarizing Wikipedia articles.",
instruction="""You are a specialized search & summarizer agent for Wikipedia articles.
""",
model="gemini-2.5-flash",
tools=[
LangchainRetrievalTool(
name="wikipedia_retrieval_tool",
description="Tool for retrieving Wikipedia articles based on user queries.",
retriever=WikipediaRetriever(wiki_client=wikipedia, top_k_results=3),
post_process=post_process,
)
],
)
Examples
Open this repository in devcontainer and all dependencies will be setup for you
# Run examples using the built-in `adk web`
uv run adk web examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adk_retrieval-0.0.2.tar.gz.
File metadata
- Download URL: adk_retrieval-0.0.2.tar.gz
- Upload date:
- Size: 224.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d8849d739771a217f5aab6c2ae1cb13627951b417782298290a29603a54952e
|
|
| MD5 |
c67ac5fbf52ff9e83aa5433ee877dff0
|
|
| BLAKE2b-256 |
007f3103a169b91cbab94ee962af7faa5dcc0c4aec457d5204f8a8ac31512493
|
Provenance
The following attestation bundles were made for adk_retrieval-0.0.2.tar.gz:
Publisher:
publish.yaml on ksachdeva/adk-retrieval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adk_retrieval-0.0.2.tar.gz -
Subject digest:
9d8849d739771a217f5aab6c2ae1cb13627951b417782298290a29603a54952e - Sigstore transparency entry: 712744591
- Sigstore integration time:
-
Permalink:
ksachdeva/adk-retrieval@bb445a2a568b041e96b25d706e3cf016581974b4 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/ksachdeva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@bb445a2a568b041e96b25d706e3cf016581974b4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file adk_retrieval-0.0.2-py3-none-any.whl.
File metadata
- Download URL: adk_retrieval-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa9ee3ca9b1df40659ce21e0d8610409648e1997088c460f25eb95270f1a64e
|
|
| MD5 |
19a548ad43d8cd1789de5fca84d481a7
|
|
| BLAKE2b-256 |
24da0b7ca23c09e34e5179c64c966a12f59b9994b929f728ef44f612241f4481
|
Provenance
The following attestation bundles were made for adk_retrieval-0.0.2-py3-none-any.whl:
Publisher:
publish.yaml on ksachdeva/adk-retrieval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
adk_retrieval-0.0.2-py3-none-any.whl -
Subject digest:
6aa9ee3ca9b1df40659ce21e0d8610409648e1997088c460f25eb95270f1a64e - Sigstore transparency entry: 712744592
- Sigstore integration time:
-
Permalink:
ksachdeva/adk-retrieval@bb445a2a568b041e96b25d706e3cf016581974b4 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/ksachdeva
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@bb445a2a568b041e96b25d706e3cf016581974b4 -
Trigger Event:
release
-
Statement type: