Skip to content

LangChain Integration

Integrate Zubbl with LangChain agents.

Setup

pip install zubbl-sdk langchain

Wrapping a LangChain Agent

from langchain.agents import create_openai_tools_agent
from zubbl import ZubblClient

zubbl = ZubblClient(api_key="zubbl_xxx")

# Create your LangChain agent
agent = create_openai_tools_agent(llm, tools, prompt)

# Wrap it with Zubbl
smart_agent = zubbl.wrap(agent)

# Use as normal -- Zubbl records and learns
result = smart_agent.invoke({"input": "Analyze this codebase"})

Manual Integration

from zubbl.types import Trajectory, Step, TaskStatus
from uuid import uuid4

# Get recommendations before running
policy = zubbl.query(task_description="code_analysis")

# Inject into agent prompt
if policy:
    enhanced_prompt = f"{base_prompt}\n\nRecommended actions:\n"
    for action in policy.recommended_actions:
        enhanced_prompt += f"- {action}\n"

# Run and record
result = agent.invoke({"input": task})
trajectory = Trajectory(
    trajectory_id=str(uuid4()),
    task_description=task,
    steps=[Step(action="invoke", tool_output=str(result))],
    status=TaskStatus.SUCCESS if result else TaskStatus.FAILURE,
)
zubbl.ingest(trajectory)