Skip to main content

Prime Agent Python Client

CI PyPI Python

An async, typed Python host client for the public JSONL RPC mode of Prime Agent.

This package owns the application-side boundary: subprocess lifecycle, correlated commands, streamed events, timeouts, cancellation, diagnostics, and extension UI responses. Prime Agent remains the coding runtime and must be installed separately.

Community project: this package is maintained by Superagentic AI. It is not an official Prime Intellect product and is not endorsed by Prime Intellect. Prime Agent and Prime Intellect are names of their respective owners.

Why this package exists

Prime Agent documents a capable RPC protocol, but its bundled host client is TypeScript. Python applications otherwise need to reimplement framing, correlation, lifecycle, and evolving event handling. This package provides one small, dependency-free implementation that can be shared by CLIs, IDEs, services, notebooks, and agent harnesses.

Install

Install Prime Agent first and complete its normal login or provider setup:

curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh
prime-agent

Then install the Python client:

pip install prime-agent-python-client

Quick start

import asyncio

from prime_agent_client import PrimeSession


async def main() -> None:
    async with PrimeSession(
        cwd="/path/to/repository",
        provider="anthropic",
        model="claude-sonnet-4-20250514",
    ) as session:
        async for event in session.prompt_stream("Fix the failing tests"):
            if event.type != "message_update":
                continue
            update = event.get("assistantMessageEvent", {})
            if update.get("type") == "text_delta":
                print(update.get("delta", ""), end="", flush=True)


asyncio.run(main())

No shell is used. PrimeSession launches the public executable as prime-agent --mode rpc with an argv sequence.

High-level API

async with PrimeSession(cwd=".") as session:
    await session.prompt("Implement the feature")
    await session.steer("Keep the public API backward compatible")
    await session.follow_up("Run the focused tests when finished")

    state = await session.state()
    messages = await session.messages()
    stats = await session.stats()
    models = await session.available_models()

    await session.set_model("anthropic", "claude-sonnet-4-20250514")
    await session.compact("Keep decisions and unresolved failures")
    await session.refine(instructions="Remove redundant context")

Session operations include new, switch_session, set_session_name, fork, and clone. The lower-level PrimeRpcTransport.request() method makes new protocol commands usable before a convenience method is added.

Event compatibility

Events are intentionally open rather than modelled as a closed enum:

async for event in session.prompt_stream("Inspect the repository"):
    print(event.type, event.raw)

PrimeEvent.raw preserves the complete RPC object, including event types and fields introduced by later Prime Agent versions. Malformed records become observable protocol_error events instead of disappearing.

The transport follows Prime Agent's strict framing requirements:

  • LF is the only record delimiter
  • CRLF input is accepted
  • U+2028 and U+2029 inside JSON strings do not split records
  • requests are correlated by generated IDs
  • pending requests fail immediately if the process exits
  • stderr is retained in a bounded diagnostic buffer

Extension UI

Interactive extensions can ask the host to select, confirm, or collect input:

async def ui(event):
    if event.get("method") == "confirm":
        return True
    return {"cancelled": True}


async with PrimeSession(cwd=".", ui_handler=ui) as session:
    await session.prompt_and_wait("Run the extension workflow")

Notification and status events are delivered to the handler but do not receive a protocol response, matching Prime Agent's fire-and-forget semantics.

Compatibility

The 0.1 line is tested against Prime Agent 0.7.0 and 0.7.1. Unknown versions are allowed because the RPC protocol is additive, but they are marked as untested:

assert session.compatibility is not None
print(session.compatibility.tested)

The library supports Python 3.10 through 3.13 and has no runtime Python dependencies.

Security

Prime Agent executes model-generated Python and project commands with the permissions of its process. This client is a transport, not a sandbox. Run it only in repositories and execution environments whose trust model you understand.

Contributing

See CONTRIBUTING.md. Protocol changes should include a fake RPC fixture test and, where possible, validation against the public Prime Agent executable.

License

Apache-2.0. See LICENSE and NOTICE.

Download files

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

Source Distribution

prime_agent_python_client-0.1.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

prime_agent_python_client-0.1.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for prime_agent_python_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4809791357bc1cd6c648fed65e435df859ac8f54a7225434d00bb571ea101b3
MD5 3834380543ecba01bb8611fba61cd156
BLAKE2b-256 a6f18883e31cd31f5ecfec83fe7a1400169b523223f3efaef1aa636bfa2d9e4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prime_agent_python_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c0ee24914dcf02077b38969867202d4ef6a1ae90cba213b8a003ce304f75da1
MD5 dba5aca7c4afe62d57891676db67d821
BLAKE2b-256 ed4c04de6a4f2bd7e30d6cba52f4860fe0d5f496d6c0be916a3547203adfb45d

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