Skip to main content

Python implementation of paw agents and AI integrations

Project description

kitpaw

Python implementation of paw agents and AI integrations.

Async API

kitpaw.pi_agent.ai is asyncio-first. Use stream / complete.

import asyncio

from kitpaw.pi_agent.ai import Context, UserMessage, complete, stream, get_model


async def main() -> None:
    model = get_model("openai", "gpt-4o-mini")

    response_stream = stream(
        model,
        Context(messages=[UserMessage(content="Say hello")]),
        {"max_tokens": 64},
    )
    async for event in response_stream:
        print(event.type)

    result = await complete(
        model,
        Context(messages=[UserMessage(content="Say hello")]),
        {"max_tokens": 64},
    )
    print(result)


asyncio.run(main())

HTTP Client Reuse

stream() and complete() accept an optional http_client_factory in options. Use it when the caller wants to reuse a shared httpx.AsyncClient and its connection pool.

If http_client_factory is omitted, the library creates and closes a fresh client per call. If http_client_factory is provided, the library uses the returned client and does not close it.

Agent Runtime

kitpaw.pi_agent.agent provides the higher-level agent runtime on top of kitpaw.pi_agent.ai.

import asyncio

from kitpaw.pi_agent.agent import Agent, AgentTool, AgentToolResult
from kitpaw.pi_agent.ai import TextContent


async def main() -> None:
    agent = Agent()
    agent.set_system_prompt("You are a concise assistant.")

    agent.set_tools(
        [
            AgentTool(
                name="echo",
                label="Echo",
                description="Return the provided text",
                parameters={
                    "type": "object",
                    "properties": {"text": {"type": "string"}},
                    "required": ["text"],
                },
                execute=lambda _tool_call_id, args, *_: AgentToolResult(
                    content=[TextContent(text=args["text"])],
                    details=None,
                ),
            )
        ]
    )

    await agent.prompt("Say hello")
    print(agent.state.messages[-1])


asyncio.run(main())

Use agent.continue_() to resume from the last non-assistant message, or agent.follow_up() and agent.steer() to queue additional messages for the next turn.

Code Agent

kitpaw.pi_agent.code_agent is the Python port of the pi coding-agent package. It currently ships:

  • SDK session creation via create_agent_session()
  • built-in coding tools (read, bash, edit, write, grep, find, ls)
  • pi / kitpaw CLI entrypoints with print, JSON, RPC, and interactive modes
  • real-time streaming output in interactive mode

Run a print-mode smoke:

pi -p "Reply with exactly the word pong."

Run interactive mode (streaming output):

pi

Run JSON mode:

pi --mode json "List the files in this repository"

Run RPC mode:

pi --mode rpc

Custom System Prompt

Place an AGENTS.md file in your project root to override the default system prompt. The content is loaded automatically at session startup. If no AGENTS.md is found, the built-in default is used.

Local environment

Put local credentials in the repository root .env.local. The package and tests load this file automatically when present.

Recommended .env.local:

OPENAI_BASE_URL=https://open.bigmodel.cn/api/coding/paas/v4
OPENAI_API_KEY=your-local-key
OPENAI_MODEL=glm-4.7
OPENAI_FALLBACK_MODEL=glm-4.5

.env.local is ignored by git and must not be committed.

Commands

Install dependencies and run the default test suite:

uv run pytest

Run the real upstream smoke test explicitly:

PAW_RUN_REAL_E2E=1 uv run pytest -m real_e2e

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

kitpaw-0.1.0.tar.gz (222.4 kB view details)

Uploaded Source

Built Distribution

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

kitpaw-0.1.0-py3-none-any.whl (139.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kitpaw-0.1.0.tar.gz
  • Upload date:
  • Size: 222.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kitpaw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1fa5336607e3a65d24ce9754a2b749dd4eb7a93e66c367517fe2050609461f65
MD5 5b6f9a9b01b187bdf9b94aad3d52ed49
BLAKE2b-256 807dad81168d3d1ce3ab6151848d2083dec552062a6c091dd850999fd4d35d49

See more details on using hashes here.

Provenance

The following attestation bundles were made for kitpaw-0.1.0.tar.gz:

Publisher: python-publish.yml on reyoung/kitpaw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: kitpaw-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 139.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kitpaw-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c88abbfcf14d45aac2d953cda3fe5ca2b69cae70a42ea84200be2fc411c0a72b
MD5 5b97c3a4768e3c1063e896c98b89cfdb
BLAKE2b-256 b936844b738d102381d01b11e80c08cdd8f378366fdf6f0ffc42b92bbde4f438

See more details on using hashes here.

Provenance

The following attestation bundles were made for kitpaw-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on reyoung/kitpaw

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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