Open-source agent SDK (pure Python)
Project description
OpenAgentic SDK (Python)
Pure-Python, open-source Agent SDK inspired by the Claude Agent SDK programming model.
Status: early (APIs may change), but the core runtime + tool loop are usable today.
This project exists for people who want the “agent runtime” experience (multi-turn sessions, tool calls, approvals,
skills/commands from .claude/, resumable logs) in a small, hackable Python codebase.
See README.zh_cn.md for a Chinese overview.
What you get
- A minimal agent runtime:
run()/ streamingquery()/ CAS-stylequery_messages(). - A persistent session model: durable
session_id,events.jsonl,resume=<session_id>. - A real tool loop: model requests tools → permission gate → tool execution → tool results → model continues.
- Human-friendly console output by default (debug mode available).
.claudecompatibility: project memory, slash commands, and skills on disk.- OpenAI + OpenAI-compatible providers (the examples use a real OpenAI-compatible backend by default).
Quickstart (uv)
Prereqs: Python 3.11+ and uv.
Install into a new project:
mkdir oas_test && cd oas_test
uv init
uv add openagentic-sdk
export RIGHTCODE_API_KEY="..." # required
export RIGHTCODE_BASE_URL="https://www.right.codes/codex/v1" # optional
export RIGHTCODE_MODEL="gpt-5.2" # optional
export RIGHTCODE_TIMEOUT_S="120" # optional
uv run oa chat
Windows (PowerShell):
mkdir oas_test
cd oas_test
uv init
uv add openagentic-sdk
$env:RIGHTCODE_API_KEY="..." # required
$env:RIGHTCODE_BASE_URL="https://www.right.codes/codex/v1" # optional
$env:RIGHTCODE_MODEL="gpt-5.2" # optional
$env:RIGHTCODE_TIMEOUT_S="120" # optional
uv run oa chat
Quickstart (local)
Prereqs: Python 3.11+.
Install (optional, for editable dev):
pip install -e .
Set env (examples + CLI default to RIGHTCODE):
RIGHTCODE_API_KEY(required)RIGHTCODE_BASE_URL(optional, defaulthttps://www.right.codes/codex/v1)RIGHTCODE_MODEL(optional, defaultgpt-5.2)RIGHTCODE_TIMEOUT_S(optional, default120)
Run unit tests:
python3 -m unittest -q
Run examples:
python3 example/01_run_basic.py- See
example/README.mdfor the full list and required env vars.
oa CLI
Install (editable):
pip install -e .
If oa isn't found after installation on Windows, add the scripts directory printed by pip to PATH (or run python -m openagentic_cli chat).
Install via uv (recommended):
uv add openagentic-sdk
uv run oa --help
uv run oa chat
Optional (recommended): install ripgrep (rg) so the agent can search your repo quickly when using shell tools.
- Windows (PowerShell):
winget install BurntSushi.ripgrep.MSVC - WSL/Ubuntu:
sudo apt-get update && sudo apt-get install -y ripgrep
Commands:
oa chat(multi-turn REPL;/helpfor slash commands)oa run "prompt"(--json,--no-stream)oa resume <session_id>(alias ofoa chat --resume <session_id>)oa logs <session_id>(summarizeevents.jsonl)
Sessions are stored under ~/.openagentic-sdk by default (override with OPENAGENTIC_SDK_HOME).
Publishing
See docs/publishing.md.
Usage
Streaming:
import asyncio
from openagentic_sdk import OpenAgenticOptions, query
from openagentic_sdk.providers import OpenAIProvider
from openagentic_sdk.permissions import PermissionGate
async def main() -> None:
options = OpenAgenticOptions(
provider=OpenAIProvider(),
model="gpt-4.1-mini",
api_key="...", # OpenAI API key
permission_gate=PermissionGate(permission_mode="prompt", interactive=True),
setting_sources=["project"],
)
async for event in query(prompt="Find TODOs in this repo", options=options):
print(event.type)
asyncio.run(main())
One-shot:
import asyncio
from openagentic_sdk import OpenAgenticOptions, run
from openagentic_sdk.providers import OpenAIProvider
from openagentic_sdk.permissions import PermissionGate
async def main() -> None:
options = OpenAgenticOptions(
provider=OpenAIProvider(),
model="gpt-4.1-mini",
api_key="...",
permission_gate=PermissionGate(permission_mode="callback", approver=lambda *_: True),
)
result = await run(prompt="Explain this project", options=options)
print(result.final_text)
asyncio.run(main())
OpenAI-compatible backend (the examples default to RIGHTCODE):
from openagentic_sdk import OpenAgenticOptions, run
from openagentic_sdk.providers.openai_compatible import OpenAICompatibleProvider
from openagentic_sdk.permissions import PermissionGate
options = OpenAgenticOptions(
provider=OpenAICompatibleProvider(base_url="https://www.right.codes/codex/v1"),
model="gpt-5.2",
api_key="...", # RIGHTCODE_API_KEY
cwd=".",
permission_gate=PermissionGate(permission_mode="prompt", interactive=True),
setting_sources=["project"],
)
Built-in tools
Default registry includes:
Read,Write,EditGlob,GrepBashWebFetchWebSearch(Tavily; requiresTAVILY_API_KEY)TodoWriteSlashCommand(loads.claude/commands/<name>.md)Skill(CAS-style single tool for.claude/skills/**/SKILL.md)SkillList,SkillLoad,SkillActivate(legacy/compat)
For OpenAI-compatible providers, tool schemas include long-form “how to use this tool” descriptions (opencode-style) to make the model follow rules more reliably.
.claude compatibility
When setting_sources=["project"], the SDK can index:
CLAUDE.mdor.claude/CLAUDE.md(memory).claude/skills/**/SKILL.md.claude/commands/*.md
When setting_sources=["project"], query() prepends a system message with project memory + skills/commands index; SkillActivate adds an "Active Skills" section persisted via skill.activated events (survives resume).
Console output (human-first)
Examples use openagentic_sdk.console.ConsoleRenderer, which:
- Prints assistant text by default (human-friendly).
- In debug mode (
--debugorOPENAGENTIC_SDK_CONSOLE_DEBUG=1), prints tool/hook/result summaries.
Try the interactive CLI chat example:
python3 example/45_cli_chat.py
Event compatibility
events.jsonlis forward-compatible for added fields: deserialization ignores unknown keys on known eventtypes.- Unknown event
types raiseopenagentic_sdk.errors.UnknownEventTypeError.
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
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 openagentic_sdk-0.1.1.tar.gz.
File metadata
- Download URL: openagentic_sdk-0.1.1.tar.gz
- Upload date:
- Size: 90.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
483cc881d19c682da54bfaeae3cc206d9784c8fa813f0bededd58765cbd83fa4
|
|
| MD5 |
4e2583bf4e6bbc47ec7412a2b9e98c12
|
|
| BLAKE2b-256 |
f74b97b5b1f55c6fa937a61b5bab3bbf60ca79e437061a6aae3ee541c542aafc
|
File details
Details for the file openagentic_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: openagentic_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 93.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d8a170d8389f2b1fc4a8414bae7319cc5861bcd97e5eaf8ebb475982d54dc56
|
|
| MD5 |
8c8e38e9d8e0d403bf2b1b3d58572bf0
|
|
| BLAKE2b-256 |
d430155069df465aa0a56357e2093b9873db0702d14dc0267dc50936ac03ef5f
|