Skip to main content

create_assistant()

The fastest way to deploy an assistant. A single function call creates the assistant and deploys it in one step, returning an App ready to chat.

When to use this

Use create_assistant() when you want the fewest lines of code and don't need to reuse the assistant configuration across multiple deploys. For more control, see AssistantBuilder or the Assistant class.

Signature

from custodian_labs import create_assistant

app = create_assistant(
model="gpt-4o",
prompt="You are a helpful assistant.",
examples=None, # optional
api_key=None, # falls back to CUSTODIAN_SDK_API_KEY env var
base_url=None, # falls back to CUSTODIAN_SDK_BASE_URL env var
timeout=30.0,
max_retries=2,
)

Parameters

ParameterTypeRequiredDefaultDescription
modelstrYesLLM model name (e.g. "gpt-4o", "gpt-4o-mini")
promptstrYesSystem prompt for the assistant
exampleslist[dict]NoNoneFew-shot examples. Each dict must have "user" and "assistant" keys
api_keystrNoenv varYour CustodianAI API key
base_urlstrNoenv varAssistant API base URL
timeoutfloatNo30.0Request timeout in seconds
max_retriesintNo2Number of retries on 5xx errors

Returns: App

Examples

Minimal

from custodian_labs import create_assistant

app = create_assistant(
model="gpt-4o",
prompt="You are a helpful customer support assistant for Acme Corp.",
)

response = app.chat("What are your business hours?")
print(response.response)

With few-shot examples

app = create_assistant(
model="gpt-4o",
prompt="You are a triage assistant. Classify support tickets.",
examples=[
{
"user": "My order hasn't arrived after 2 weeks.",
"assistant": "Category: Shipping. Priority: High.",
},
{
"user": "I'd like to change my email address.",
"assistant": "Category: Account. Priority: Low.",
},
],
)

Multi-turn conversation

App retains session state automatically — each call to .chat() continues the same conversation:

app = create_assistant(model="gpt-4o", prompt="You are a helpful assistant.")

app.chat("My name is Alex.")
response = app.chat("What's my name?")
print(response.response) # "Your name is Alex."

Call app.reset_session() to start a fresh conversation.