Skip to main content

A streaming terminal REPL for any agent.

Project description

partnuh

A streaming terminal REPL for any agent.

partnuh is purely aesthetic: it's the fast, multi-line, token-streaming terminal REPL. You build your agent with its own dependencies — smolagents, an OpenAI-compatible chat model, anything — and hand it to partnuh.run(), which auto-wraps it. partnuh never builds agents and imports no framework of its own.

import partnuh
from smolagents import ToolCallingAgent, OpenAIServerModel

agent = ToolCallingAgent(tools=[...], model=OpenAIServerModel(...))  # your agent
partnuh.wrap(agent, name="Private Caller").run()                     # one line → a full CLI

Run the example locally (from a checkout)

Install the package into a virtualenv in editable mode, then run the example — examples/basic_agent.py, a complete agent CLI in a few lines:

cd partnuh
python3 -m venv .venv
.venv/bin/pip install -e ".[smolagents,dotenv]"   # or ".[all]"
cp .env.template .env                              # add your OPENROUTER_API_KEY

.venv/bin/python examples/basic_agent.py             # interactive
.venv/bin/python examples/basic_agent.py "21 + 21?"  # one-shot

It auto-loads .env. See the comments in the file for how each part maps to the library.

Install (as a dependency)

pip install partnuh                 # core (bring your own agent)
pip install "partnuh[openai]"       # + OpenAI/OpenRouter chat backend
pip install "partnuh[smolagents]"   # + smolagents adapter
pip install "partnuh[all]"

Use

Bring your own agent. Build it however you like, then partnuh.run() it. What you pass is auto-wrapped: an already-CliAgent, a smolagents agent, or a plain stream function all just work.

import os, partnuh
from smolagents import OpenAIServerModel, ToolCallingAgent, tool

@tool
def add(a: int, b: int) -> int:
    "Add two integers.\n\nArgs:\n  a: first\n  b: second"
    return a + b

model = OpenAIServerModel(model_id="openai/gpt-5.4-nano",
                          api_base="https://openrouter.ai/api/v1",
                          api_key=os.environ["OPENROUTER_API_KEY"])
agent = ToolCallingAgent(tools=[add], model=model, stream_outputs=True)

partnuh.wrap(agent, name="Private Caller").run()   # auto-wrapped; no partnuh agent type to learn

wrap() returns a configurable Cli; .run() launches it. Configure it with CliConfig fields as keyword overrides:

partnuh.wrap(agent, name="Private Caller", prompt_str="❯ ", stream_speed=0.3).run()

(partnuh.run(agent, ...) is shorthand for wrap(agent, ...).run().)

Anything is an agent — a generator function is enough (no key, no framework):

import partnuh
from partnuh import TextDelta

def echo(prompt, session_id):
    for word in f"you said: {prompt}".split(" "):
        yield TextDelta(word + " ")

partnuh.wrap(echo, name="Echo").run()

Optional sugar: for the no-framework chat case there's AgentSpec, a thin helper over the OpenAI/OpenRouter backend. It's convenience only — partnuh doesn't need it.

agent = partnuh.AgentSpec(name="Private Caller", model="openai/gpt-5.4-nano").build()
partnuh.wrap(agent).run()

In the REPL

  • Enter submits, Shift+Enter inserts a newline (works across terminals — see below). Backspace on a blank line joins back to the previous line.
  • /tools list tools · /reset clear history · /help · /quit

Configuring behavior

from partnuh import CliConfig

partnuh.run(agent, config=CliConfig(
    stream_speed=0.0,      # 0 = as-fast-as-tokens-arrive; 1.0 = slow typewriter
    show_tool_calls=True,  # render the tool-call markers
    banner=True,
    commands={"clear": lambda d, args: __import__("os").system("clear")},
))

How it works (ports & adapters)

There is no universal in-process agent object shared across frameworks, so partnuh defines a tiny contract and ships adapters:

  • CliAgent protocol — name, model, tools, and stream(prompt, session_id) -> Iterator[Event].
  • Event union — TextDelta, ToolCallStarted, ToolResult, Error, Done. Every adapter translates its framework's native stream into these; a bare str is treated as a TextDelta.
  • Adaptersfrom_openai, from_smolagents, from_callable. Add your own by yielding Events.
  • Pacer — renders the event stream to the terminal with optional speed control.

The Shift+Enter trick

Terminals encode Shift+Enter differently, and prompt_toolkit's default collapses the common Ghostty/xterm encoding into plain Enter (so it submits instead of adding a newline). partnuh registers every known Shift+Enter escape sequence (\x1b[27;2;13~, kitty's \x1b[13;2u, …) and maps it to "insert newline" — no terminal config required.

License

MIT

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

partnuh-0.0.3.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

partnuh-0.0.3-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file partnuh-0.0.3.tar.gz.

File metadata

  • Download URL: partnuh-0.0.3.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for partnuh-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6a968da877573b7a23041874b2f2d33bd1d5ada7a39fbb9950ab853db64849f4
MD5 02063c4f60e4c95d3977b863498ee83c
BLAKE2b-256 1b7709935dc0866fadc28fa43d187db3528c1260566642107ab840619d6636d1

See more details on using hashes here.

File details

Details for the file partnuh-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: partnuh-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for partnuh-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 db185d43d36c55aa95b457d71dd24489a3167cd5e1064f249aa2d94b1cf57b94
MD5 77fb410f9efd62c67336ddd1d1657fe5
BLAKE2b-256 eb82b5a0977f5d8074e6d86033b7e957ed0b7f772e97d7d3993042bddf08f343

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