Skip to main content

OTURN: Orchestrated Task Unified Reactive Nucleus

Project description

OTURN

OTURN = Orchestrated Task Unified Reactive Nucleus.

OTURN is a small async runtime for turn-based agent systems.

What It Provides

  • Reducer-style stream state machine (agent_stream_state.py)
  • Queue-based multi-subscriber pub/sub (subscribe(queue), unsubscribe(queue))
  • Turn runtime with tool execution and approval/choice callbacks
  • LiteLLM streaming adapter with normalized semantic events
  • Session/history persistence via Context + SessionStore

Installation

cd oturn
uv sync
uv pip install -e .

Build:

uv build

Core Types

  • Oturn: high-level agent runtime
  • OTurnNucleus: generic reducer nucleus for non-LLM state machines
  • Transition: reducer output (state, events, terminal)
  • Context: conversation history + persistence wrapper
  • BaseTool: tool protocol/base class

Oturn Event Stream

Published events include:

  • assistant_delta
  • assistant_reasoning_delta
  • assistant_final
  • tool_call_delta
  • tool_call
  • tool_output
  • tool_exit
  • approval_request
  • choice_request
  • message_sent
  • run_aborted
  • error
  • debug_latency / tool_call_debug (when debug flags are enabled)

Minimal Oturn Example

import asyncio
from pathlib import Path

from oturn import (
    Oturn,
    OturnConfig,
    OturnProviderConfig,
    OturnModelConfig,
    OturnAgentConfig,
    Context,
    WeatherTool,
)


async def main() -> None:
    cfg = OturnConfig(
        model="<provider/model>",
        provider=OturnProviderConfig(api_key="<API_KEY>"),
        model_config=OturnModelConfig(max_output_tokens=4096, temperature=0.7),
        agent_config=OturnAgentConfig(max_steps=50, user_name="User"),
    )

    agent = Oturn(work_dir=Path.cwd(), config=cfg, tools=[WeatherTool])
    ctx = Context(Path.cwd() / ".oturn" / "sessions" / "demo.md", work_dir=Path.cwd())

    q: asyncio.Queue[dict] = asyncio.Queue()
    agent.subscribe(q)

    agent.enqueue_user_input_nowait("What's the weather in Tokyo?")
    task = asyncio.create_task(agent.run_queues(ctx))

    try:
        while True:
            ev = await q.get()
            print(ev)
    finally:
        task.cancel()


asyncio.run(main())

Tool Injection Model

OTURN uses explicit runtime tool injection. Pass tool classes when constructing Oturn:

agent = Oturn(work_dir=work_dir, config=cfg, tools=[WeatherTool])

Example tools in oturn.tools.examples:

  • WeatherTool (get_weather)
  • HostConfigTool (get_host_config)

Usage and Tool-Call Delta Accessors

Usage data is available via context accessors.

  • get_last_usage(ctx) -> dict | None
  • get_last_total_tokens(ctx) -> int | None
  • get_tool_call_deltas() -> list[tool_call_delta]
  • get_tool_call_delta(delta_id) -> tool_call_delta | None

Session/History

  • Session persistence is handled by Context + SessionStore.
  • Records are stored as markdown event/message documents (Chron-based serialization via chronml).
  • Default metadata root name is .oturn (DEFAULT_META_DIRNAME).
  • Session files are created under a date-partitioned global directory:
    • ~/.oturn/global_sessions/YYYYMMDD/<session_id>.md
  • When work_dir is available, SessionStore also creates a local session link:
    • <work_dir>/.oturn/sessions/<session_id>.md -> global session file
  • Persistence is incremental:
    • append_message(...) appends a single serialized record
    • append_compact(...) appends compaction markers the same way
  • Context.restore() loads existing session markdown into in-memory history.
  • Configurable knobs:
    • meta_dirname: rename .oturn namespace for local/global paths
    • global_sessions_root: override ~/.<meta_dirname>/global_sessions
  • You can also import/export session markdown via:
    • Context.export_md_as_config(...)
    • Context.import_md_as_config(...)

Project details


Download files

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

Source Distribution

oturn-0.1.0.tar.gz (173.3 kB view details)

Uploaded Source

Built Distribution

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

oturn-0.1.0-py3-none-any.whl (204.4 kB view details)

Uploaded Python 3

File details

Details for the file oturn-0.1.0.tar.gz.

File metadata

  • Download URL: oturn-0.1.0.tar.gz
  • Upload date:
  • Size: 173.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for oturn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4a96f94b9348fc74e82ed6d8811d9cc134c9e9b90ca20789b50436cbe782a0a
MD5 91fa0327e17ae3ecac764b0f4333752d
BLAKE2b-256 e76809d36ca8f9ef26543e348c56c8f4978eb612718a35e2638805043c72239c

See more details on using hashes here.

File details

Details for the file oturn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: oturn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 204.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for oturn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14a9fe158f6648feafd2f0498268a5c34262334d7a5f73e4659e39fcc72b0895
MD5 a1d6f46969a3b5aa55d3d2d3d39b7b3c
BLAKE2b-256 60a2549b7623b50aade63cf409c4a104d374cfa0e9e3449865f2f771b26d04d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page