Skip to main content

urai

Urai means “dialog” in Tamil. It defines the chat behaviour shared by every backend. aidialog defines message parts. A backend package such as rishi talks to an inference engine. Urai manages the conversation between those boundaries.

A backend implements one model step. Urai supplies model resolution, portable options, history, tools, streaming, callbacks, and usage accounting.

Install

pip install uraiyadal

Urai does not include an inference backend. Install one separately, then import its backend module to register a runtime.

Start a chat

The examples below assume a backend has registered a remote runtime. Pass its model name to mk_chat, then call the returned chat with a message:

from urai import mk_chat, resp_text

chat = mk_chat('gpt-5.1', runtime='remote', sp='Answer briefly.', temp=0.2)
reply = chat('What is 6 times 7?')
print(resp_text(reply))

chat.hist contains the normalized conversation. The same history shape works with every backend.

[(msg['role'], resp_text(msg)) for msg in chat.hist]

Resolve a model before loading it

resolve identifies a registered runtime and context window without building a backend:

from urai import resolve

spec = resolve('claude-sonnet-4.6', runtime='remote')
print(spec.runtime, spec.ctx, spec.local)

chat = mk_chat(spec)

A resolved ModelSpec can be cached, compared, and passed between layers.

Configure one turn

Constructor options set defaults for the conversation. Generation options passed to a call apply only to that turn:

reply = chat('Explain the hard part.', effort='high', temp=0.9)

Urai translates portable names such as ctx and temp to backend-specific names. Unsupported options produce a warning. Backend-only options belong in extra.

Add a tool

A Python callable becomes a tool from its signature and docstring:

def add(a: int, b: int) -> int:
    "Add two integers."
    return a + b

chat = mk_chat('gpt-5.1', runtime='remote', tools=[add], approve=lambda call: True)
reply = chat('Use the tool to add 20 and 22.')
print(resp_text(reply))

Approval runs before each local tool call. Provider-run tools are recorded but never executed locally.

Modules

module contract
core usage, callbacks, and response rendering
tags <think> and <tool_call> parsing
msgs canonical messages and wire conversions
caps model input, output, and context capabilities
opts model resolution and portable options
chat synchronous and asynchronous conversation state
loop tool approval, execution, budgets, and context recovery
eval classification, structured output, and grading
sandbox Python-fence execution
record deterministic recording and replay
broker isolated conversations over one shared engine

Write a backend

Subclass Chat, declare option translations, and register the runtime. Add ToolLoopMixin when the backend returns tool calls as data.

from urai import Chat, ToolLoopMixin, Runtime, register_runtime

class MyChat(ToolLoopMixin, Chat):
    _runtime = 'mine'
    _opt_map = {'ctx': 'n_ctx'}
    _opt_skip = ('effort',)

    def _model_step(self, **kw): ...
    def _stream_step(self, **kw): ...

register_runtime(Runtime('mine', 'mypkg.chat.MyChat', pats=('.mine',)))

Chat('model.mine') now dispatches to MyChat.

Develop

The notebooks in nbs/ are the source. Files in urai/ are generated.

uv sync --all-extras --group dev
uv run nbdev-export
uv run nbdev-test
uv run nbdev-clean

The test suite uses scripted backends. It does not load a model or require network access.

Metadata

Release files for uraiyadal 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uraiyadal 0.0.10
File Size Uploaded
uraiyadal-0.0.10.tar.gz 48.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uraiyadal 0.0.10
File Interpreter ABI Platform
uraiyadal-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 103.2 kB

Release files / uraiyadal-0.0.10.tar.gz

Download URL uraiyadal-0.0.10.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
afd05b496ead5b90367cae9c2ec04f06b96d8322f91d6c222746a39b21bd96fc
BLAKE2b-256 checksum
How to use checksums
042a70f4f9818215f669fa71a867325cef1c8634dddb940e3a264084b9991fff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / uraiyadal-0.0.10-py3-none-any.whl

Download URL uraiyadal-0.0.10-py3-none-any.whl
Size 55.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9d6f0b53d70f0ad5f73f842c6fa835440460c508cfac8f9e9593adcd24f5b29
BLAKE2b-256 checksum
How to use checksums
07ae362b89644a32c12a4fbbf9602d1df757263ffdc932d02fef9c7e2243d026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page