Package 'rho.ai'

Title: Rho AI Protocol
Description: Defines S7 protocols for models, messages, content, tools, credentials, capabilities, and normalized provider event streams. Includes adapters for OpenAI, OpenAI Codex, Anthropic, GitHub Copilot, Z.ai, Ollama, and deterministic provider fixtures.
Authors: Sounkou Mahamane Toure [aut, cre]
Maintainer: Sounkou Mahamane Toure <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1.9000
Built: 2026-07-15 18:48:47 UTC
Source: https://github.com/sounkou-bioinfo/Rho

Help Index


Explicit credentials, login effects, and provider catalog state

Description

Credentials are owned by a CredentialStore; login interaction is owned by a LoginIO. Reads, refreshes, writes, prompts, and notifications are explicit async operations. RhoModels owns provider selection and serialized refresh gates instead of relying on process-global auth state.


Normalized assistant and provider event protocols

Description

Providers emit the typed AssistantEvent hierarchy. Provider-specific wire events are decoded and reduced through separate S7 generics, keeping wire formats out of the agent loop.


Message content and tool contracts

Description

Messages contain typed content objects rather than discriminator strings. Tool execution is asynchronous, and overlap is represented by an S7 value that the agent can dispatch on.


Semantic operations, handlers, and provider activity

Description

A RhoOperation states what a conversation may do. A handler binds that semantic request to a concrete implementation for the selected model. Bindings record both the handler and the reason it was selected; request translators turn bindings into provider wire values while encoding a request.

Details

Provider-hosted activity is normalized as Content, never as a local ToolCall. The agent can therefore retain and report a web search without placing it in its executable tool registry.


Models, providers, and capability operations

Description

Shared model facts live in typed capability, limits, and pricing objects. Provider-specific behavior is queried with typed operation values and S7 dispatch, avoiding a lowest-common-denominator boolean map.


Normalized token usage and pricing

Description

Usage components are disjoint: input excludes cache reads and writes, while output includes any reported reasoning tokens. reasoning is an optional breakdown of output; it is never added to total a second time. The optional cache_write_1h value is a subset of cache_write.

Details

rho_price_usage() is the open pricing protocol. Its default Model method selects the highest matching long-context tier, prices every component, and returns a new Usage value. Model subclasses may provide methods for provider-specific pricing rules.


Anthropic Messages dialect

Description

Anthropic request construction is a reduction over typed request sections. Model catalog facts select thinking, temperature, cache, and tool-input capabilities; request methods never infer behavior from model names.

Details

AnthropicMessagesEndpoint separates the Messages dialect from endpoint authentication and transport. Anthropic and GitHub Copilot therefore share message translation and event reduction while retaining their own endpoint headers, URLs, and credentials.

Stream JSON is decoded once into typed wire events. S7 methods translate blocks, deltas, and stop reasons into the provider-neutral AssistantEvent protocol.


Runtime-compiled model catalog

Description

The catalog stores model facts as package data. rho_model_expression() turns a typed provider profile, protocol, and record into an inspectable R call. rho_compile_catalog_model() evaluates that call to produce the S7 model value used by provider dispatch. Extensions may add provider profiles, protocols, and expression methods without rewriting the catalog reader.

Details

Catalog refresh is an explicit development operation. Package installation and ordinary runtime use never contact a catalog service.


OpenAI-compatible Chat Completions stream protocol

Description

Chat Completions chunks are parsed into typed wire values and reduced by S7 methods to the normalized AssistantEvent protocol.


Typed OpenAI Responses request composition

Description

OpenAI request bodies are reductions over typed sections. Model-specific methods select the sections and their defaults; section methods alone emit wire field names and provider values. Extensions can specialize rho_openai_request_sections() for a model subclass or append a new OpenAIRequestSection with a rho_request_fields() method.

Details

Canonical thinking requests are values. ThinkingOff therefore dispatches separately from enabled levels without comparing provider wire strings.


Typed OpenAI Responses wire protocol

Description

The OpenAI Responses decoder maps JSON/SSE payloads to typed wire event and output-item classes before reducing them to normalized assistant events. Provider extensions may add narrower S7 methods for new item or event types.


Z.ai provider

Description

Z.ai uses the OpenAI-compatible Chat Completions protocol with explicit thinking preservation and tool-call streaming policies.