If you already have a mature AI application, integrating Blocklog requires minimal code changes. This guide shows how to add Blocklog to existing projects.
Before:
def my_custom_tool(data: str) -> str:
return "Processed " + data
def main_agent(input_data: str):
print("Starting agent")
result = my_custom_tool(input_data)
print("Done")
return resultAfter (With Blocklog):
import blocklog
blocklog.init(api_key="blk_...")
@blocklog.tool
def my_custom_tool(data: str) -> str:
return "Processed " + data
@blocklog.agent(name="main_agent")
def main_agent(input_data: str):
print("Starting agent")
result = my_custom_tool(input_data)
with blocklog.decision(type="PROCESS", asset="data") as d:
d.record_input(data=input_data)
d.record_output(result=result)
print("Done")
return resultBlocklog automatically hooks into LangChain using client.instrument_langchain().
Before:
from langchain.llms import OpenAI
from langchain.chains import LLMChain
llm = OpenAI(temperature=0.9)
chain = LLMChain(llm=llm, prompt=prompt)
chain.run("example input")After (With Blocklog):
import blocklog
from langchain.llms import OpenAI
from langchain.chains import LLMChain
client = blocklog.init(api_key="blk_...")
client.instrument_langchain() # Automatically adds BlocklogLangChainCallbackHandler
llm = OpenAI(temperature=0.9)
chain = LLMChain(llm=llm, prompt=prompt)
# LangChain runs will now be automatically traced in Blocklog
chain.run("example input")Similarly, for LangGraph, simply call the instrumentation hook:
import blocklog
client = blocklog.init()
client.instrument_langgraph()
# Continue with normal LangGraph executionIf you use the official OpenAI Agents SDK, hook into the workflow:
import blocklog
client = blocklog.init()
client.instrument_openai_agents()
# Your OpenAI client and agent usage remains identical.