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 Thread
async def main() -> None:
run = await Thread("main", workspace=".").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
Thread(id, ...) requires a human-readable id. kagent maps that id to Codex's generated thread
id using a local shelve store at .kagent/threads inside the workspace.
from kagent import Thread
thread = Thread("refactor-auth", workspace=".")
await thread.run("Refactor auth.py without changing behavior.")
await thread.run("Now run the tests and fix any failures.")
Optional process-local API-key config:
import os
from kagent import config
config("api_key", api_key=os.environ["OPENAI_API_KEY"])
Constructor options:
Thread(
id="main",
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,
)
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.
await Thread("goal-test", runner="cli", yolo=True).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/layouthatchlingbuild backend- MIT license
py.typedfor typed package consumersuv.lockcommitted for reproducible local development- pytest, ruff, and mypy for validation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_python_kagent-0.1.0.tar.gz.
File metadata
- Download URL: codex_python_kagent-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27d6ea697bb20e436bf2891875cedc611800aa0bf1ab20f5d3217b8dc0418bb7
|
|
| MD5 |
a1884ba9461e873db46313809cba852d
|
|
| BLAKE2b-256 |
916c1d3a3ec80ba52707a8da07fef09eb0f3aca6ad98b31bec6236cf992d437f
|
File details
Details for the file codex_python_kagent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codex_python_kagent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be51cf2da7cc9d2641954f0eea6746a77379ac4d3c450897487500a1dbbb7728
|
|
| MD5 |
276bb78acd83338d149d0b871e0fa523
|
|
| BLAKE2b-256 |
b3dc74c37947d83004bfc4fdec8df23b203869de5395a8c8d665935a44193885
|