Conversations API
engine.conversations: model-led conversations over the database (Conversations),
and engine.chat_tools (Chat tools).
Key Modules
packages/nl2sql/src/nl2sql/api/conversations_api.py(ConversationsAPI, internal)packages/nl2sql/src/nl2sql/conversations/(api.pythe turn and its loop,agent.pythe[CONVERSATION]block and the step checks,prompts.py,store.pyownership and stored rows)packages/nl2sql/src/nl2sql/conversations/tools.py(the chat-tool runner),report.py(the Markdown report)packages/nl2sql/src/nl2sql/api/chat_tools_api.py(ChatToolsAPI, internal)packages/nl2sql/src/nl2sql/conversations/models.py(Conversation,Turn,ToolStep,ModelStep)
Public Surface
Every method takes user_context keyword-only and required. A conversation that is not the caller's is
ConversationNotFound; one already running a turn is ConversationBusy. InvalidArgument (a ValueError, 422) is raised, before
anything runs, for: neither or both of text and choice, a choice with nothing pending or not one of the
pending options, an empty message, a conversation at max_turns (CONVERSATION_TOO_LONG), retry with no
earlier question.
| Method |
|---|
start(*, user_context, datasource_id=None, dashboard_id=None) -> Conversation |
ask(conversation_id, text=None, *, user_context, choice=None, execute=True, cancellation_token=None, llm_override=None) -> Turn |
stream(conversation_id, text=None, *, user_context, choice=None, execute=True, llm_override=None) -> Iterator[Event] |
retry(conversation_id, *, user_context, approvals=(), llm_override=None) -> Turn (approvals are Approval objects or granted request ids) |
ask_only(conversation_id, question, *, user_context, choice=None, cancellation_token=None) -> QueryResult |
get(conversation_id, *, user_context) -> Conversation |
list(*, user_context, limit=20) -> list[ConversationInfo] |
delete(conversation_id, *, user_context) -> None (ConversationBusy while a turn runs) |
tool(conversation_id, name, args=None, *, user_context) -> Turn |
report(conversation_id, *, user_context, turns=None, title=None, include_rows=True) -> str |
engine.chat_tools.list() -> list[ChatToolInfo] |
start(dashboard_id=...)needs a dashboard the caller owns (DashboardNotFoundotherwise).askreturns the storedTurn:statusis that of the last step that did not endok, elseanswered;errorholds{"code", "message"}when the loop itself ended it (MODEL_STEP_INVALID, orRUN_LIMIT_REACHEDforstopped, or thePROVIDER_*code when the model provider refused a step). Acancellation_tokenthat is cancelled ends the turnerrorwithCANCELLEDafter the step in flight.- A timeout is not a cancel. Each
askstep runs on its own token, a child of the turn's: a run that exceedspipeline.timeout_sfails that step witherror.codePIPELINE_TIMEOUT, and the loop goes on, so the model can say so in its reply (withinmax_tool_calls). Cancelling the turn's token still cancels the step in flight.ask_only(MCP'sask) returns the timed-outQueryResultwithPIPELINE_TIMEOUT, and astreamstores the turn as usual. streamends withconversation.turn; see Streaming.ask_onlyreturns the run'sQueryResultwith its rows; the stored turn has none.toolruns one enabled chat tool as a turn of kindtooland makes no model call. Arguments the tool'sargs_modelrejects are anInvalidArgumentand store nothing; a tool that is not enabled, raises or cannot apply is a stored step witherror.codeUNKNOWN_CHAT_TOOL,TOOL_FAILEDorTOOL_NOT_APPLICABLE.reportreturns Markdown for the stored answered turns (orturns, a list of turn numbers). A turn number that does not exist, or a conversation with nothing answered, is anInvalidArgument.include_rows=Falseleaves the row tables and chart takeaways out, which is how thereporttool stores its output.- Every method needs a caller:
user_context=None, or a context with nouser_id, is aTypeError, not a shared anonymous owner. engine.chat_tools.list()takes no caller: it lists the enabled tools' names.