Skip to main content

Custodian Class

Use the Custodian class when you want to configure an assistant step by step before deploying it as an App.

For the shortest path to a working assistant, start with Create Your First Assistant. Use the Custodian class when you need to add examples, attach knowledge files, or reuse an assistant configuration before deployment.

Create an Assistant

from custodian_labs import Custodian

custodian = Custodian(
model="gpt-4o",
system_prompt="You are a helpful customer support assistant.",
privacy_enabled=True,
)

Constructor Parameters

ParameterTypeRequiredDefaultDescription
modelstrYes-The model used by the assistant.
system_promptstrYes-Instructions that define the assistant's role and behavior.
api_keystrNoEnvironment variableCustodian Labs API key.
base_urlstrNoEnvironment variableAssistant API base URL.
timeoutfloatNo30.0Request timeout in seconds.
max_retriesintNo2Number of retries for failed server requests.

For API key and API URL configuration, see Authentication.

Methods

MethodPurposeLearn more
.add_examples(examples)Add sample conversations to guide responses. Each example requires user and assistant fields.
Few shot training for LLMs
See the example below.
More info: https://www.ibm.com/think/topics/few-shot-prompting
.add_data_source_file(path)Attach a local knowledge file to the assistant.Data Sources and RAG
.deploy()Deploy the configured assistant and return a chat-ready App.Chat Sessions
.chat(message)Deploy the assistant and send a message in one call.Chat Sessions

Example

from custodian_labs import Custodian

custodian = Custodian(
model="gpt-4o",
system_prompt="You are a helpful assistant for customer support.",
privacy_enabled=True,
)

custodian.add_examples(
[
{
"user": "How do I reset my password?",
"assistant": "Go to settings, open security, and choose reset password.",
}
]
)

app = custodian.deploy()

reply = app.chat("How do I invite a new teammate?")
if reply is not None:
print(reply.response)
print(reply.session_id)

Use the returned App to start a conversation. For chat methods and session behavior, see Chat Sessions.

Next Steps