Examples
Copy-paste starting points. Install and set
CUSTODIAN_SDK_API_KEY first.
Run it now
- custodian-labs-python-examples — full runnable scripts on GitHub
- Open in Google Colab — agents, RAG, and multi-agent in one notebook, no local setup
Basic agent
from custodian_labs import Custodian
app = Custodian(model="gpt-4o", system_prompt="You are a helpful assistant.").deploy()
print(app.chat("Give me a short introduction.").response)
Few-shot examples
from custodian_labs import Custodian
custodian = Custodian(model="gpt-4o", system_prompt="You are a support triage assistant.")
custodian.add_examples([
{"user": "My order has not arrived.", "assistant": "Category: Shipping. Priority: High."},
{"user": "I want to change my email.", "assistant": "Category: Account. Priority: Low."},
])
print(custodian.deploy().chat("I was charged twice.").response)
Knowledge file (RAG)
from custodian_labs import Custodian
custodian = Custodian(model="gpt-4o", system_prompt="You are an HR policy assistant.")
custodian.add_data_source_file("./employee-handbook.pdf")
reply = custodian.deploy().chat("What is the remote work policy?")
print(reply.response, reply.retrieved_contexts)
Builder
from custodian_labs import CustodianBuilder
app = (
CustodianBuilder()
.with_model("gpt-4o")
.with_prompt("You are a product documentation assistant.")
.with_data_source_file("./product-guide.pdf")
.deploy()
)
print(app.chat("What does the guide say about setup?").response)
Multi-agent squad
from custodian_labs import Custodian, CustodianSquad
squad = CustodianSquad(
custodians=[
Custodian(name="billing", model="gpt-4o", system_prompt="Answer billing questions.",
topics=["billing", "invoice", "refund"]),
Custodian(name="data", model="gpt-4o", system_prompt="Answer from the CSV.",
topics=["data", "csv", "customer"]).add_data_source_file("./pii_data.csv"),
],
routing_mode="single",
)
reply = squad.deploy().chat("How many people are in the file, and which cities?")
print(reply.response, reply.selected_agent)
Web search + write workflow
from custodian_labs import Custodian, CustodianSquad
squad = CustodianSquad(
custodians=[
Custodian(name="research", model="gpt-4o", system_prompt="Research with sources.",
tools=["web_search"], output_key="research_notes"),
Custodian(name="writer", model="gpt-4o", system_prompt="Write a brief from the notes."),
],
routing_mode="workflow",
workflow_order=["research", "writer"],
)
print(squad.deploy().chat("Brief me on RAG evaluation methods.").response)
Multi-turn
from custodian_labs import Custodian
app = Custodian(model="gpt-4o", system_prompt="You are helpful.").deploy()
app.chat("My name is Alex.")
print(app.chat("What is my name?").response)
app.reset_session()
Guardian Layer
from custodian_labs import GuardianLayer
guardian = GuardianLayer()
out = guardian.deidentify_text_outputs("John Smith, 617-555-0100", masking_type="redact")
print(out.outputs[0].text)
result = guardian.deidentify_file("./pii_data.csv", masking_type="transform")
print(result.filename)
Error handling
from custodian_labs import Custodian, AISDKError
try:
print(Custodian(model="gpt-4o", system_prompt="You are helpful.").deploy().chat("Hi").response)
except AISDKError as e:
print(e)