datarobot_genai.core.chat.completions
completions
FinalAssistantTextAccumulator
Reassemble assistant text from AG-UI events, keeping only the final message.
A chat completion carries a single content string, so a run that produced more
than one assistant message has to collapse to one of them. The one the caller asked
for is the last: in a multi-node LangGraph graph (the recipe template's
researcher_node -> responder_node shape) every node emits its own assistant
message, but only the responder's is the answer. Concatenating them yields the
reported "ParisParis" corruption. The same rule drops a tool-calling agent's
pre-tool preamble in favour of its final answer.
A message boundary is either an explicit TextMessageStartEvent or a change of
message_id on a delta (chunk-only streams never emit a START). Streams with a
single message are unaffected: every delta lands in the same message.
Source code in datarobot_genai/core/chat/completions.py
add
Feed one AG-UI event; non-text events are ignored.
Source code in datarobot_genai/core/chat/completions.py
is_streaming
Return True when the request asks for streaming, False otherwise.
Accepts both pydantic types and plain dictionaries.
Source code in datarobot_genai/core/chat/completions.py
backfill_model
Replace NAT's "unknown-model" placeholder (or None) with fallback.
NAT defaults ChatResponse.model / ChatResponseChunk.model to the literal
"unknown-model" whenever the workflow output didn't carry one. Callers pass the
agent's configured model (:func:default_response_model) as fallback so the
response reports the model the agent actually ran. A real model the workflow
produced — or a deliberately-set one such as moderation's MODERATION_MODEL_NAME
— is preserved.
Source code in datarobot_genai/core/chat/completions.py
final_assistant_text
Return the final assistant message's text from a complete AG-UI event sequence.
See :class:FinalAssistantTextAccumulator for why earlier messages are discarded.
Source code in datarobot_genai/core/chat/completions.py
convert_chat_completion_params_to_run_agent_input
convert_chat_completion_params_to_run_agent_input(chat_completion_params: CompletionCreateParams | Mapping[str, Any]) -> RunAgentInput
Convert a chat completion parameters to a run agent input.
Source code in datarobot_genai/core/chat/completions.py
agent_chat_completion_wrapper
async
agent_chat_completion_wrapper(agent: BaseAgent, chat_completion_params: CompletionCreateParams | Mapping[str, Any], mcp_tools_factory: Callable[[], Any]) -> InvokeReturn | tuple[str, MultiTurnSample | None, UsageMetrics]
Wrap the agent's invoke method in a chat completion wrapper.
MCP tools from mcp_tools_factory are combined with any tools already on
agent (MCP first, then existing agent.tools).
Returns
InvokeReturn When streaming is requested - the raw async event generator tuple[str, MultiTurnSample | None, UsageMetrics] When non-streaming - the reassembled final text, pipeline interactions, and accumulated usage metrics.