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 urai

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uraiyadal-0.0.4.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uraiyadal-0.0.4-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file uraiyadal-0.0.4.tar.gz.

File metadata

  • Download URL: uraiyadal-0.0.4.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for uraiyadal-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1dbef3b7bb2a85cfbbde5c42e912b1275badc21e57bbaaa73b66b8800317a358
MD5 5a2cbc2027ba4d94a8dbf00978e9ae65
BLAKE2b-256 9a952eb26f5a56000b331c9c5c6ec8c3f200f53dd55707f5b0e81107bc25214f

See more details on using hashes here.

File details

Details for the file uraiyadal-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: uraiyadal-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.1

File hashes

Hashes for uraiyadal-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4574e8db906667c6499330af112841dcd0f76d5b4b957dc5c71e87e882cc47b7
MD5 e2f11a38eeb07b6718b3d62963f5dfc0
BLAKE2b-256 c5eaad10487fe17e996491721da6a1afa30e223d2894e2f9f4529edbc970a909

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.6

2 files

0.0.5

2 files

This release

0.0.4 This release

2 files

0.0.2

2 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