roboto.ai#
Submodules#
Package Contents#
- class roboto.ai.AISummary(/, **data)#
Bases:
pydantic.BaseModelA wire-transmissible representation of an AI summary
- Parameters:
data (Any)
- created: datetime.datetime#
The time at which the summary was created.
- status: AISummaryStatus#
The status of the summary.
- summary_id: str#
The ID of the summary.
- text: str#
The text of the summary.
- class roboto.ai.AgentSession(record, roboto_client=None, client_tools=None)#
An interactive AI agent session within the Roboto platform.
An AgentSession is a conversational interface with Roboto’s AI assistant, enabling users to ask questions, request data analysis, and interact with their robotics data through natural language. Sessions maintain conversation history and support streaming responses for real-time interaction.
The primary control-flow primitives are
run()(drive the session forward with auto-dispatch of client-side tools) andevents()(observe events as the agent generates without taking any actions).Examples
Fire-and-forget with client-side tools:
>>> from roboto.ai import AgentSession, client_tool >>> @client_tool ... def remember(fact: str) -> str: ... """Store a fact in long-term memory.""" ... ... >>> session = AgentSession.start("Remember my favorite color is blue.", client_tools=[remember]) >>> session.run()
Observing events as they happen:
>>> session = AgentSession.start("Explain machine learning.") >>> for event in session.events(): ... if isinstance(event, AgentTextDeltaEvent): ... print(event.text, end="", flush=True)
- Parameters:
roboto_client (Optional[roboto.http.RobotoClient])
client_tools (Optional[collections.abc.Sequence[Union[roboto.ai.agent_session.client_tool.ClientTool, roboto.ai.agent_session.record.ClientToolSpec]]])
- property client_tool_names: list[str]#
Names of client-side tools registered on this session with callbacks.
- Return type:
list[str]
- events(tick=0.2, timeout=None)#
Yield events from the agent as they are generated.
Polls the session and yields
AgentEventobjects as new content arrives. Does not auto-dispatch client-side tools — if the session reachesAgentSessionStatus.CLIENT_TOOL_TURN, the generator returns and the caller is expected to callsubmit_client_tool_results()(and then callevents()again to continue). For automatic dispatch, userun().- Parameters:
tick (float) – Polling interval in seconds between checks for new content.
timeout (Optional[float]) – Maximum time to wait in seconds. If None, waits indefinitely.
- Yields:
AgentEventobjects (AgentStartTextEvent,AgentTextDeltaEvent,AgentTextEndEvent,AgentToolUseEvent,AgentToolResultEvent,AgentErrorEvent) as they become available. Text events are scoped to a single message: anAgentTextEndEventis emitted at the end of each message that carried text, so adjacent assistant messages produce separate start/end pairs.- Raises:
TimeoutError – If
timeoutelapses before the session pauses.- Return type:
collections.abc.Generator[roboto.ai.agent_session.event.AgentEvent, None, None]
Examples
Stream text output as it arrives:
>>> for event in session.events(): ... if isinstance(event, AgentTextDeltaEvent): ... print(event.text, end="", flush=True)
- fork(message_sequence_num)#
Fork this session’s history up to a specific message into a new session owned by the caller.
Available to the session’s creator (forking their own session) and to Roboto admins (
is_roboto_admin) forking anyone’s session. The new session carries the source session’sorg_idso tool calls resolve against the source org’s data. The new session is owned by the caller, so admin forks of a customer session never appear in the customer’s session list.- Parameters:
message_sequence_num (int) – Highest message sequence number (inclusive) to copy.
- Returns:
A new
AgentSessioninstance for the forked session.- Raises:
RobotoUnauthorizedException – If the caller is not a member of the source session’s org, or is a member but is neither the source session’s creator nor a Roboto admin.
RobotoInvalidRequestException – If
message_sequence_numis out of range or points at a message still generating.
- Return type:
- classmethod from_id(session_id, roboto_client=None, load_messages=True)#
Retrieve an existing agent session by its unique identifier.
Loads a previously created session from the Roboto platform, allowing users to resume conversations and access message history.
- Parameters:
session_id (str) – Unique identifier for the session. Accepts both
ags_*and legacych_*identifiers.roboto_client (Optional[roboto.http.RobotoClient]) – HTTP client for API communication. If None, uses the default client.
load_messages (bool) – Whether to load the session’s messages. If False, the session’s messages will be empty.
- Returns:
AgentSession instance representing the existing session.
- Raises:
RobotoNotFoundException – If the session does not exist.
RobotoUnauthorizedException – If the caller lacks permission to access the session.
- Return type:
Examples
Resume an existing session:
>>> session = AgentSession.from_id("ags_abc123") >>> print(f"Session has {len(session.messages)} messages") Session has 5 messages
- property latest_message: roboto.ai.agent_session.record.AgentMessage | None#
The most recent message in the conversation, or None if no messages exist.
- Return type:
- property messages: list[roboto.ai.agent_session.record.AgentMessage]#
Complete list of messages in the conversation in chronological order.
- Return type:
- refresh()#
Update the session with the latest messages and status.
Fetches any new messages or status changes from the server and updates the local session state.
- Returns:
Self for method chaining.
- Return type:
- register_client_tool(tool)#
Register a client-side tool for auto-dispatch in subsequent turns.
The tool’s spec is not sent to the backend by this call; pass it via the
client_tools=argument onsend(),send_text(), orsubmit_client_tool_results()on the next outbound request.- Parameters:
tool (roboto.ai.agent_session.client_tool.ClientTool) – The ClientTool to register.
- Returns:
Self for method chaining.
- Return type:
- run(*, on_event=None, tick=0.2, timeout=None)#
Drive the session forward until it is the user’s turn.
Polls the session, auto-dispatching any pending client-side tool invocations against the callbacks registered with this session (via
start(),send(), orregister_client_tool()). Returns once the session status isAgentSessionStatus.USER_TURN.If the agent requests a client-side tool that has no registered callback, an
errorresult is submitted automatically with a descriptive message so the agent can recover, and execution continues. If a registered callback raises, the exception is caught and also submitted as anerrorresult.- Parameters:
on_event (Optional[OnEvent]) – Optional callback invoked for each
AgentEventas the agent generates (text deltas, tool uses, tool results, start/end markers). Use this for progress display or logging.tick (float) – Polling interval in seconds between status checks.
timeout (Optional[float]) – Total time budget in seconds across the whole loop. If None, waits indefinitely.
- Returns:
Self for method chaining.
- Raises:
TimeoutError – If the
timeoutbudget is exhausted before the session reachesUSER_TURN.RuntimeError – If the session is in
CLIENT_TOOL_TURNwith no messages (i.e. a server state that should not be reachable), or if an unexpectedAgentSessionStatusvalue is observed.RobotoHttpException – Propagated from the underlying
submit_client_tool_results()POST if the server rejects the submission (for example, a concurrent caller already answered the tool-use).
- Return type:
Examples
Fire-and-forget:
>>> session = AgentSession.start("Remember my favorite color is blue.", client_tools=[remember]) >>> session.run()
With progress logging:
>>> def log(event): ... if isinstance(event, AgentToolUseEvent): ... print(f"[tool-use] {event.name}({event.input})") >>> session.run(on_event=log)
- send(message=None, *, client_context=None, client_tools=None, analysis_scope=None, goals=None)#
Send a structured message to the session.
- Parameters:
message (Optional[roboto.ai.agent_session.record.AgentMessage]) – AgentMessage object containing the message content and metadata. Optional when at least one entry is provided in
goals; in that case the server synthesizes a minimal user message for the turn.client_context (Optional[roboto.ai.core.ClientViewingContext]) – Optional
ClientViewingContextdescribing what the calling client is currently viewing when this message was composed. Informational only; seeAgentSession.start()for full semantics.client_tools (Optional[collections.abc.Sequence[Union[roboto.ai.agent_session.client_tool.ClientTool, roboto.ai.agent_session.record.ClientToolSpec]]]) – Optional client-side tools to add or update for this and subsequent turns. ClientTool callbacks are registered on the session for auto-dispatch.
analysis_scope (Optional[roboto.ai.core.AnalysisScope]) – Optional replacement
AnalysisScope. When provided, overwrites the session’s current scope for all subsequent tool invocations. WhenNone, the session’s existing scope (if any) is left untouched.goals (Optional[collections.abc.Sequence[roboto.ai.goals.AgentGoal]]) – Optional structured goals to declare for this turn. The agent runner enforces achievement of every declared goal before completing the turn.
- Returns:
Self for method chaining.
- Raises:
RobotoInvalidRequestException – If the message format is invalid.
RobotoUnauthorizedException – If the caller lacks permission to send messages.
- Return type:
- send_text(text, *, client_context=None, client_tools=None, analysis_scope=None, goals=None)#
Send a text message to the session.
Convenience method for sending a simple text message without needing to construct an
AgentMessage.- Parameters:
text (str) – Text content to send to the assistant.
client_context (Optional[roboto.ai.core.ClientViewingContext]) – Optional
ClientViewingContextdescribing what the calling client is currently viewing.client_tools (Optional[collections.abc.Sequence[Union[roboto.ai.agent_session.client_tool.ClientTool, roboto.ai.agent_session.record.ClientToolSpec]]]) – Optional client-side tools to add or update.
analysis_scope (Optional[roboto.ai.core.AnalysisScope]) – Optional replacement
AnalysisScope; seesend()for update semantics.goals (Optional[collections.abc.Sequence[roboto.ai.goals.AgentGoal]]) – Optional goals to declare for this turn. See
send()for full semantics.
- Returns:
Self for method chaining.
- Raises:
RobotoInvalidRequestException – If the text is empty or invalid.
RobotoUnauthorizedException – If the caller lacks permission to send messages.
- Return type:
- property session_id: str#
Unique identifier for this session.
- Return type:
str
- classmethod start(message=None, *, client_context=None, system_prompt=None, model_profile=None, org_id=None, client_tools=None, analysis_scope=None, goals=None, roboto_client=None)#
Start a new agent session with an initial message.
Creates a new session and sends the initial message to begin the conversation. The AI assistant will process the message and generate a response, which can be driven to completion with
run()or observed event-by-event withevents().- Parameters:
message (Optional[Union[str, roboto.ai.agent_session.record.AgentMessage, collections.abc.Sequence[roboto.ai.agent_session.record.AgentMessage]]]) – Initial message to start the conversation. Can be a text string, a single AgentMessage, or a sequence of AgentMessage objects for multi-turn initialization. Optional when at least one entry is provided in
goals; in that case the server synthesizes a minimal user message — implicitly “achieve the goals” — and the agent will work to achieve every declared goal during the first turn.client_context (Optional[roboto.ai.core.ClientViewingContext]) – Optional
ClientViewingContextdescribing what the calling client (e.g. the Web UI) is currently displaying when this session is started. Lets the agent resolve deictic references like “this dataset” without the user spelling them out. Informational only; does not gate authorization or scope tools — seeanalysis_scopefor that.system_prompt (Optional[str]) – Optional system prompt to customize the AI assistant’s behavior for this conversation.
model_profile (Optional[str]) – Optional model profile ID (e.g. “standard”, “advanced”). Defaults to the deployment’s default profile.
org_id (Optional[str]) – Organization ID to create the session in. If None, uses the caller’s default organization.
client_tools (Optional[collections.abc.Sequence[Union[roboto.ai.agent_session.client_tool.ClientTool, roboto.ai.agent_session.record.ClientToolSpec]]]) – Optional list of client-side tools to make available to the agent. Accepts
ClientToolinstances (which include a callback for auto-dispatch) and bareClientToolSpecobjects (which describe the tool but require the caller to submit results manually).analysis_scope (Optional[roboto.ai.core.AnalysisScope]) – Optional
AnalysisScopefor the session (e.g. a time window or topic-pattern filter). When provided, the scope is persisted on the session and delivered to every tool invocation on the server side. Individual tools opt in to honoring the scope as they are adopted.goals (Optional[collections.abc.Sequence[roboto.ai.goals.AgentGoal]]) – Optional structured goals to declare for the first turn. When provided,
messagemay be omitted; the server will synthesize a minimal user message and the agent runner will enforce achievement of every declared goal before completing the turn.roboto_client (Optional[roboto.http.RobotoClient]) – HTTP client for API communication. If None, uses the default client.
- Returns:
AgentSession instance representing the newly created session.
- Raises:
RobotoInvalidRequestException – If the message format is invalid.
RobotoUnauthorizedException – If the caller lacks permission to create sessions.
- Return type:
Examples
Start and drive a session with client-side tools:
>>> from roboto.ai import client_tool >>> @client_tool ... def recall(query: str) -> str: ... """Search long-term memory for facts matching a query.""" ... ... >>> session = AgentSession.start("What do you remember?", client_tools=[recall]) >>> session.run()
- property status: roboto.ai.agent_session.record.AgentSessionStatus#
Current status of the session.
- Return type:
- submit_client_tool_results(results, client_tools=None)#
Submit results of client-side tool execution to resume the session.
- Parameters:
results (collections.abc.Sequence[roboto.ai.agent_session.record.ClientToolResult]) – Tool results from client-side execution.
client_tools (Optional[collections.abc.Sequence[Union[roboto.ai.agent_session.client_tool.ClientTool, roboto.ai.agent_session.record.ClientToolSpec]]]) – Optional updated client-side tools for the next invocation. ClientTool callbacks are registered on the session for auto-dispatch.
- Returns:
Self for method chaining.
- Return type:
- submit_feedback(message_sequence_num, sentiment, categories=None, notes=None)#
Submit structured feedback on a specific assistant message in this session.
Persists categorized feedback so it can be reviewed by Roboto operators. Re-submitting from the same user on the same message overwrites
sentiment,categories, andnoteson the existing row rather than creating a duplicate; thefeedback_idand originalcreated/created_byare preserved.- Parameters:
message_sequence_num (int) – Zero-indexed position of the assistant message being rated.
sentiment (roboto.ai.agent_session.feedback.FeedbackSentiment) – Overall rating direction.
categories (Optional[list[roboto.ai.agent_session.feedback.FeedbackCategory]]) – Zero or more categories describing the feedback. Must match
sentiment.FeedbackCategory.OTHERis always permitted but requiresnotes.notes (Optional[str]) – Free-text notes. Required when
FeedbackCategory.OTHERis among the categories.
- Returns:
The persisted feedback as a
UserFeedbackRecord. Admin triage columns (admin_label,admin_note,resolved,resolved_by,resolved_at) are intentionally not part of this shape — they are only visible through the admin API.- Raises:
RobotoInvalidRequestException – If the message is still generating, the sentiment/category combination is invalid, or
OTHERis used without notes.RobotoUnauthorizedException – If the caller cannot access this session.
RobotoNotFoundException – If
message_sequence_numis out of range.
- Return type:
- property transcript: str#
Human-readable transcript of the entire conversation.
Returns a formatted string containing all messages in the conversation, with role indicators and message content clearly separated.
- Return type:
str
- unregister_client_tool(name)#
Remove a previously registered client-tool callback.
This only removes the local callback. The backend was told about the tool in
StartAgentSessionRequestclient_tools(or via a latersend()) and may still emittool_useevents for it; once the callback is gone,run()will submit an error result for those invocations so the agent can recover. There is no server-side deregistration API.The tool name remains recorded as a declared client tool on this session, so the dispatcher still treats it as client-side (and not as a server tool whose result the server will post).
- Parameters:
name (str) – Name of the client tool to unregister.
- Returns:
Trueif a callback was removed,Falseif no callback was registered undername.- Return type:
bool
- class roboto.ai.AgentSessionRecord(/, **data)#
Bases:
pydantic.BaseModelComplete record of an agent session.
Contains all the persistent data for a session including metadata, message history, and synchronization state.
- Parameters:
data (Any)
- property chat_id: str#
Backwards-compatible alias — serialized as chat_id in API responses.
- Return type:
str
- continuation_token: str#
Token used for incremental updates and synchronization.
- created: datetime.datetime#
Timestamp when this agent session was created.
- created_by: str#
User ID of the person who created this agent session.
- forked_from_message_sequence_num: int | None = None#
Message sequence number in the source session that this fork was taken from.
Populated in tandem with
forked_from_session_id; both areNonefor sessions that were not created as a fork.
- forked_from_session_id: str | None = None#
If this session was forked, the id of the source session.
Noneotherwise.
- goals: list[AgentSessionGoalRecord] | None = None#
Goals declared across this session’s turns, ordered by allocation (i.e. by
goal_index).Nonemeans goals were not loaded for this record (full-session reads populate the field; lightweight or legacy reads may omit it). An empty list means goals were loaded but the session never declared any.
- messages: list[AgentMessage] = None#
Complete list of messages in the conversation.
- model_profile: str | None = None#
Model profile used for this agent session (e.g., ‘standard’, ‘advanced’).
- org_id: str#
Organization ID that owns this agent session.
- session_id: str = None#
Unique identifier for this agent session.
- status: AgentSessionStatus#
Current status of this agent session.
- title: str | None = None#
Title of this agent session.
- class roboto.ai.ClientTool(fn, *, name, description, input_schema)#
A client-side tool with an execution callback.
Wraps a Python callable as a tool that the Roboto agent can request the client to execute. The tool’s JSON schema is inferred from the callable’s type hints; the tool description and per-parameter descriptions are taken from the function’s Google-style docstring unless passed explicitly.
Most callers build ClientTools via the
client_tool()decorator orClientTool.from_function()rather than instantiating this class directly.Examples
Using the decorator — descriptions come from the docstring:
>>> @client_tool ... def remember(fact: str, tags: Optional[list[str]] = None) -> str: ... """Store a fact in long-term memory. ... ... Args: ... fact: A standalone sentence worth remembering. ... tags: Optional tags for later retrieval. ... """ ... ...
Using
Annotated[T, Field(...)]instead (takes precedence over the docstring):>>> from typing import Annotated >>> from pydantic import Field >>> @client_tool ... def recall( ... query: Annotated[str, Field(description="Substring to search for.")], ... ) -> str: ... """Search long-term memory.""" ... ...
Using the factory with explicit overrides:
>>> tool = ClientTool.from_function( ... my_fn, ... name="store_fact", ... description="Store a fact in long-term memory.", ... )
- Parameters:
fn (collections.abc.Callable[Ellipsis, Any])
name (str)
description (str)
input_schema (dict[str, Any])
- classmethod from_function(fn, *, name=None, description=None, input_schema=None)#
Build a ClientTool from a Python callable.
The tool’s name defaults to
fn.__name__. The tool description defaults to the summary-and-body offn’s docstring (everything before the first Google-style section header likeArgs:orReturns:). Per-parameter descriptions are pulled from the docstring’sArgs:section, and can be overridden withtyping.Annotated[T, pydantic.Field(description="...")]orparam: T = pydantic.Field(description="...").- Parameters:
fn (collections.abc.Callable[Ellipsis, Any]) – The callable to invoke when the tool is dispatched.
name (Optional[str]) – Override for the tool name (default:
fn.__name__).description (Optional[str]) – Override for the tool description (default: the docstring’s summary-and-body). Required if
fnhas no docstring.input_schema (Optional[dict[str, Any]]) – Override for the input JSON Schema (default: inferred from
fn’s type hints and docstring).
- Returns:
A ClientTool wrapping the given callable.
- Raises:
ValueError – If the description cannot be resolved, or if
input_schemais not provided and the signature cannot be automatically converted (e.g. uses*argsor**kwargs).- Return type:
- property name: str#
Tool name surfaced to the LLM.
- Return type:
str
- property spec: roboto.ai.agent_session.record.ClientToolSpec#
Declarative spec sent to the Roboto backend.
- Return type:
- class roboto.ai.ClientToolResult(/, **data)#
Bases:
pydantic.BaseModelResult of executing a client-side tool.
- Parameters:
data (Any)
- output: dict[str, Any] | None = None#
Structured output returned by the tool.
- runtime_ms: int#
Wall-clock execution time of the tool in milliseconds.
- status: ClientToolResultStatus#
Outcome of the tool execution.
- tool_name: str#
Name of the tool that was executed.
- tool_use_id: str#
Identifier of the tool invocation this result corresponds to.
- class roboto.ai.ClientToolResultStatus#
Bases:
roboto.compat.StrEnumOutcome of executing a client-side tool.
- DECLINED = 'declined'#
- ERROR = 'error'#
- SUCCESS = 'success'#
- class roboto.ai.ClientToolSpec(/, **data)#
Bases:
pydantic.BaseModelDeclarative specification for a client-side tool.
Unlike AgentTool (which is an ABC with a __call__ method for server-side execution), ClientToolSpec is a plain data model. The backend includes it in the LLM’s tool list but never executes it — the client is responsible for execution and submitting the result.
- Parameters:
data (Any)
- description: str#
- input_schema: dict[str, Any]#
- name: str#