Skip to main content

Async Codex-backed coding agent SDK.

Project description

kagent

Async Python SDK for running Codex-backed coding-agent tasks with a small, memorable thread API.

The PyPI distribution is codex-python-kagent; the import package is kagent.

import asyncio

from kagent import Kagent


async def main() -> None:
    agent = Kagent()
    run = await agent.thread("main").run("Create hello.txt with exactly: hello")
    print(run.text)


asyncio.run(main())

Status

kagent is experimental. It wraps the local Codex CLI/app-server flow and currently depends on the experimental OpenAI Codex Python SDK for runner="sdk".

The package itself has no required runtime dependencies so it can be built and published cleanly. The default runner uses the Codex CLI. The experimental Codex Python SDK is kept in a local uv dependency group instead of PyPI metadata.

Install

In a uv project:

uv add codex-python-kagent
kagent login

For API-key auth instead of ChatGPT subscription auth:

export OPENAI_API_KEY="sk-..."
kagent login --api-key-env OPENAI_API_KEY

For local development in this repo:

uv sync --group dev --group codex --group examples

The local machine must also have the Codex CLI installed and authenticated:

codex login status

API

Use Kagent() when you already authenticated with kagent login or codex login.

from kagent import Kagent

agent = Kagent(workspace=".")
thread = agent.thread("refactor-auth")
await thread.run("Refactor auth.py without changing behavior.")
await thread.run("Now run the tests and fix any failures.")

Or trigger Codex auth from Python, inspired by OpenHands-style login constructors:

import os

from kagent import Kagent

agent = Kagent.login()
api_agent = Kagent.login(api_key=os.environ["OPENAI_API_KEY"])

Constructor options:

Kagent(
    workspace=".",
    model="gpt-5.4-mini",
    runner="cli",
    ask_for_approval="never",
    sandbox="danger-full-access",
    skip_git_repo_check=True,
    yolo=True,
    codex_bin=None,
    store_path=None,
)

agent.thread(id, ...) requires a human-readable id. kagent maps that id to Codex's generated session id using a local shelve store at .kagent/threads inside the workspace.

runner="cli" uses codex exec through an async subprocess. It stores Codex's generated session id in .kagent/threads, then uses codex exec resume on later runs with the same human-readable Thread id.

runner="sdk" uses the experimental Codex app-server SDK and persistent threads. It requires the local development codex dependency group.

agent = Kagent(runner="cli", yolo=True)

await agent.thread("goal-test").run(
    "Create hello.txt with exactly the text hello.",
    goal=True,
)

There is no native codex exec --goal flag. goal=True translates to a prompt beginning with /goal ..., which is the behavior verified locally. Goal runs use the CLI runner, not app-server SDK thread persistence.

yolo=True maps to Codex's --dangerously-bypass-approvals-and-sandbox flag.

Examples

Run the Codex example:

uv run --group codex python examples/codex_thread.py

Run the OpenHands comparison example:

uv run --group examples python examples/openhands_thread.py

OpenHands may require interactive ChatGPT subscription login on first run.

Development

uv sync --group dev --group codex --group examples
uv run pytest
uv run ruff check .
uv run mypy
uv build

Publish:

export UV_PUBLISH_TOKEN="pypi-..."
uv build
uv publish

The package uses:

  • src/ layout
  • hatchling build backend
  • MIT license
  • py.typed for typed package consumers
  • uv.lock committed for reproducible local development
  • pytest, ruff, and mypy for validation

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

codex_python_kagent-0.1.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

codex_python_kagent-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file codex_python_kagent-0.1.1.tar.gz.

File metadata

  • Download URL: codex_python_kagent-0.1.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for codex_python_kagent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 974b0155558cd4963d47fcb1036eeb69561be70b20fa3448fbf9299abf239e8b
MD5 07b7c9e3a4be01e5313252817375cb10
BLAKE2b-256 7da175d11a7cf5726ff4faaba601c268d27e7b116b9e287bd6146e8f56368390

See more details on using hashes here.

File details

Details for the file codex_python_kagent-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_python_kagent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5dd473ada124a4ec86c85f2d7a321903e3eb8eaa0074381120cff14e43fca216
MD5 8406d728cfb48ee8ca65cea6f48b4226
BLAKE2b-256 12e61dea19f29a2430919f374e8b16b35d9a3d3b3e5dfcb8cd177a89514ac113

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