Skip to main content

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() / streaming query() / CAS-style query_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).
  • .claude compatibility: project memory, slash commands, and skills on disk.
  • OpenAI + OpenAI-compatible providers (the examples use a real OpenAI-compatible backend by default).

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, default https://www.right.codes/codex/v1)
  • RIGHTCODE_MODEL (optional, default gpt-5.2)

Run unit tests:

python3 -m unittest -q

Run examples:

  • python3 example/01_run_basic.py
  • See example/README.md for 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).

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; /help for slash commands)
  • oa run "prompt" (--json, --no-stream)
  • oa resume <session_id> (alias of oa chat --resume <session_id>)
  • oa logs <session_id> (summarize events.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, Edit
  • Glob, Grep
  • Bash
  • WebFetch
  • WebSearch (Tavily; requires TAVILY_API_KEY)
  • TodoWrite
  • SlashCommand (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.md or .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 (--debug or OPENAGENTIC_SDK_CONSOLE_DEBUG=1), prints tool/hook/result summaries.

Try the interactive CLI chat example:

  • python3 example/45_cli_chat.py

Event compatibility

  • events.jsonl is forward-compatible for added fields: deserialization ignores unknown keys on known event types.
  • Unknown event types raise openagentic_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

openagentic_sdk-0.1.0.tar.gz (90.5 kB view details)

Uploaded Source

Built Distribution

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

openagentic_sdk-0.1.0-py3-none-any.whl (93.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openagentic_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 90.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for openagentic_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed88dbc32b5a032c27884ee04fbc49e868042d7816c3e5a6a4e155b401f3b7e3
MD5 5c2d1e39085e9532f0488c82b980b277
BLAKE2b-256 7aa35a9566c2f78b2d73fe8cb054981bd19e654dc8d86f287fb88987352dcfbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openagentic_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09367d19e2d19b3fc70a16da9d33606b4e7af5b1e5455bd34d2a346745c09f9d
MD5 f2af21444f18ca3918ed38d29d379419
BLAKE2b-256 5343acfc0abe1eeae9e5b44c77cb97ffbc4b16888f959b2e36f2de70b99a4dd6

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