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
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | str | Yes | - | The model used by the assistant. |
system_prompt | str | Yes | - | Instructions that define the assistant's role and behavior. |
api_key | str | No | Environment variable | Custodian Labs API key. |
base_url | str | No | Environment variable | Assistant API base URL. |
timeout | float | No | 30.0 | Request timeout in seconds. |
max_retries | int | No | 2 | Number of retries for failed server requests. |
For API key and API URL configuration, see Authentication.
Methods
| Method | Purpose | Learn 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
- Builder API: configure an assistant with a fluent builder style.
- Data Sources and RAG: add knowledge files and understand retrieval.
- Chat Sessions: manage multi-turn conversations.