LangChain (Python) callback handler that adds RANKIGI cryptographic receipts to every LLM, tool, agent, and retriever step.
Project description
rankigi-langchain
LangChain (Python) callback handler that adds RANKIGI cryptographic receipts to every LLM, tool, agent, retriever, and LangGraph node.
Compatible with langchain-core >= 0.1 and LangGraph.
Install
pip install rankigi-langchain
Setup
First, enroll a connector passport in your RANKIGI dashboard (Agents → New, type "connector"). Copy the credentials into your environment:
export RANKIGI_API_KEY=rnk_...
export RANKIGI_AGENT_ID=<uuid>
export RANKIGI_PASSPORT_ID=<uuid>
export RANKIGI_SIGNING_KEY=<base64 ed25519 seed>
Then attach the callback:
from rankigi_langchain import RankigiCallbackHandler
from langchain.agents import AgentExecutor
executor = AgentExecutor(
agent=agent,
tools=tools,
callbacks=[RankigiCallbackHandler(agent_tag="checkout-service-prod")],
)
Or pass per-invocation via RunnableConfig:
executor.invoke(
{"input": "..."},
config={"callbacks": [RankigiCallbackHandler(agent_tag="checkout-service-prod")]},
)
LangGraph works the same way:
graph.invoke(
state,
config={"callbacks": [RankigiCallbackHandler(agent_tag="research-agent")]},
)
What gets a receipt
| LangChain callback | RANKIGI action |
|---|---|
on_llm_end / on_chat_model_start+end |
llm_call |
on_tool_end |
tool_call |
on_agent_action |
agent_action |
on_agent_finish |
agent_finish |
on_chain_start/end (LangGraph nodes + top-level only) |
chain_start / chain_end |
on_retriever_end |
retrieval |
any on_*_error callback |
*_error with severity="warn" |
What gets hashed
Prompts, completions, tool inputs, tool outputs, agent reasoning, retriever queries, and document contents are SHA-256-hashed locally by the SDK before any network call. Only the hashes plus safe metadata (model name, token counts, latency, run/parent IDs, LangGraph node names) reach RANKIGI.
Safety
Every callback is wrapped in try/except. SDK or network failures are absorbed silently — the callback never raises into LangChain. The underlying SDK has a durable disk queue that absorbs RANKIGI downtime and retries.
Explicit credentials
If you can't use env vars, pass the credentials directly:
RankigiCallbackHandler(
api_key=os.environ["RANKIGI_API_KEY"],
agent_id=os.environ["RANKIGI_AGENT_ID"],
passport_id=os.environ["RANKIGI_PASSPORT_ID"],
signing_private_key=os.environ["RANKIGI_SIGNING_KEY"],
agent_tag="checkout-service-prod",
)
Test injection
For unit tests, pass a mock client:
class FakeClient:
def track(self, **kwargs): ...
RankigiCallbackHandler(client=FakeClient())
License
MIT
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 rankigi_langchain-1.0.0.tar.gz.
File metadata
- Download URL: rankigi_langchain-1.0.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fcdd028730fa5844de884642ff696283547cf76d0754ddc6dafe4e229a159ba
|
|
| MD5 |
85457fa82e1788b3ed1a5619ecc19849
|
|
| BLAKE2b-256 |
94ce20d358383aeb7f319ed6f46d5858a249fc33f84fc275da0ce565b7f970aa
|
File details
Details for the file rankigi_langchain-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rankigi_langchain-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ff2994a0fabeea2df4f8e798e0e37b2923ee09f60a59194779d31cff6353b8b
|
|
| MD5 |
97e4682dca50b755078dd60e7232fefd
|
|
| BLAKE2b-256 |
254cb8ff47d861e76847a2255fdb3a67a4f09186908930799cba45bd33a6d7a1
|