This release is a pre-release and may not be stable for production use.
kaiwen-agent
Provider-neutral, asynchronous Python runtime for building tool-using agents. Product applications own their prompts, domain tools, authorization context, persistence choice, and HTTP surface.
pip install "kaiwen-agent[openai]"
For OpenAI Live primary WebSocket support:
pip install "kaiwen-agent[openai-live]"
Optional text providers are installed independently:
pip install "kaiwen-agent[gemini]"
pip install "kaiwen-agent[ollama]"
Minimal agent
import asyncio
from pydantic import BaseModel
from kaiwen_agent import Agent, AgentContext, tool
from kaiwen_agent.models.openai import OpenAIResponsesProvider
from kaiwen_agent.types import AgentInput
class ProjectQuery(BaseModel):
category: str | None = None
@tool(
name="projects.read",
description="List projects visible to the current user",
input_model=ProjectQuery,
permissions={"projects.read"},
)
async def read_projects(
context: AgentContext,
query: ProjectQuery,
) -> list[dict[str, str]]:
repository = context.services["projects"]
return await repository.list(category=query.category)
async def main() -> None:
agent = Agent(
name="portfolio",
model=OpenAIResponsesProvider(
model="your-model-id",
instructions="Help visitors discover relevant products.",
store=False,
),
tools=[read_projects],
permissions={"projects.read"},
)
result = await agent.run(
AgentInput(text="Show me the games"),
context=AgentContext(
session_id="session-id",
permissions=frozenset({"projects.read"}),
services={"projects": your_repository},
),
)
print(result.text)
asyncio.run(main())
For a single-agent composition that keeps normal chat tool-free and makes action tools explicit:
from kaiwen_agent import AgentRuntime, RuntimeIdentity
runtime = AgentRuntime(name="assistant", model=provider, tools=[read_projects])
reply = await runtime.chat(
"Merhaba",
identity=RuntimeIdentity(session_id="session-id"),
)
AgentRuntime.action() exposes only the tool names selected by trusted host code.
AgentRuntime.run() keeps workflow mode fail-closed. Autonomous hosts explicitly
compose WorkflowController with durable run state, the existing Task Runtime, and
completion gates; it never falls back to an unsafe in-memory workflow.
Larger applications can register immutable AgentDefinition records and compose
them through AgentFactory plus a strict WorkspaceProfile. The factory resolves
exact prompt and capability versions, constructs a fresh provider instance, validates
tool visibility against both capability and workspace allowlists, and records the
selected versions in runtime context. Policy and execution-time permission checks
remain authoritative; configuration never grants additional access.
The smallest credential-free runtime example is
examples/simple-runtime. The provider-neutral fake
speech composition is in examples/speech-pipeline.
Durable single-agent workflow and least-privilege team composition are demonstrated
in examples/autonomous-single-agent and
examples/software-agent-team. All four are
executed by CI so their public imports stay valid.
Applications may inject ContextBuilder, ContextWindow, and
ContextCompactionManager into the runtime. Context collection stays optional for
simple chat, uses a provider-specific TokenCounter when available, and never treats
lossy session summaries as policy or configuration. Use
ArtifactToolResultProcessor when large tool output should be stored out-of-band and
represented to the model by an owner-scoped artifact reference.
Runtime delivery requirements use immutable StandardsPack definitions and
host-registered verifiers. CompletionGate accepts a mandatory requirement only when
its artifact evidence is owned by the trusted user, belongs to the current run, and
matches both the protected input fingerprint and declared evidence type. The package
does not include product-specific test, legal, citation, or CI verifiers.
OPENAI_API_KEY is read by the OpenAI SDK from the server environment. The
runtime never stores it and it must never be exposed to browser code.
Runtime capabilities
- Provider-neutral async agent loop and deterministic fake provider.
- Typed Pydantic tool inputs and deny-by-default permission intersection.
- Approval, idempotency, timeout, and retry handling for side effects.
- Session, run, event, and audit ports with a SQLite reference adapter.
- SSE event fan-out and trace propagation.
- Durable task graphs, workers, checkpoints, mailbox control, resource locks, cancellation, and bounded concurrency.
- Optional OpenAI Responses API adapter.
- Optional Gemini Generate Content and Ollama Chat adapters. Provider SDKs only return tool proposals; central runtime execution remains authoritative.
- Technical model capability records and data-locality-aware routing that prevents
cloud fallback for
local_onlyrequests. - Provider-neutral Realtime sessions, OpenAI Live/WebRTC adapters, durable text-and-voice conversations, and allowlisted background task delegation.
- Trusted OpenAI Live sideband execution through the same permission, approval, idempotency, and audit pipeline used by text agents.
- Deterministic lifecycle and central policy runtimes, bounded context assembly, short-term session summaries, and policy-gated long-term memory.
- Non-blocking background jobs projected onto the existing Task Runtime, including progress events, cooperative cancellation, parent-child progress, and recovery.
- A deterministic Trigger Router that filters, deduplicates, debounces, and coalesces untrusted events before scheduling lifecycle wakeups.
- Policy-gated model routing, hierarchical runtime budgets, immutable versioned prompt and declarative skill registries, owner-scoped artifacts, and inspectable capability manifests.
- Structured evaluation, observation-only replay, fail-closed simulation, tenant-scoped redacted dead letters, backpressure, optional Redis coordination leases with fencing tokens, fixed-catalog tenant-scoped metrics, heartbeat health, and an allowlisted server-side secret-provider boundary.
- Optional PostgreSQL full-text + pgvector hybrid memory retrieval via
kaiwen-agent[postgres-memory]. - Optional Redis distributed lease coordination via
kaiwen-agent[redis]. - Optional root-bounded workspace filesystem tools and trusted MCP bindings. Remote discovery does not grant authority; both use the central tool safety pipeline.
Realtime usage and integration boundaries are documented in the repository's
docs/realtime.md, docs/openai-live.md, and docs/conversation-bridge.md files.
Side effects
Tools marked reversible or destructive receive a runtime idempotency key.
Set requires_approval=True and supply an application-owned ApprovalGate for
publishing, deleting, deploying, calling, or sending messages. Applications
must still perform authorization inside their own service boundary. Memory setup and
its trust boundaries are documented in docs/long-term-memory.md.
Coding-agent handoff
When asking another coding agent to integrate this package, provide the root
repository files AGENTS.md and docs/consumer-agent-brief.md. The complete,
provider-free example is in examples/basic-agent.
Metadata
Release files for kaiwen-agent 0.5.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kaiwen_agent-0.5.0a1.tar.gz | 200.2 kB | With provenance | Details for kaiwen_agent-0.5.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kaiwen_agent-0.5.0a1-py3-none-any.whl | Python 3 | none | any | Details for kaiwen_agent-0.5.0a1-py3-none-any.whl |
Total release size: 437.0 kB
Release files / kaiwen_agent-0.5.0a1.tar.gz
| Download URL | kaiwen_agent-0.5.0a1.tar.gz |
|---|---|
| Size | 200.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cd0fd241944feb4ae02945e8145724e1eebbd521234e4f7441141e26a724fec
|
|
BLAKE2b-256 checksum How to use checksums |
d5753fa91e33c4e68064c4c5d1dfe8425f39fca676d14559a9bc75c7a4123c1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.
Transparency logRelease files / kaiwen_agent-0.5.0a1-py3-none-any.whl
| Download URL | kaiwen_agent-0.5.0a1-py3-none-any.whl |
|---|---|
| Size | 236.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8419b726910ea886f20d7d509bec88219a80f860d4c29bcb04f099bd3f65ce21
|
|
BLAKE2b-256 checksum How to use checksums |
430ac9c1c555b78f08c1cd7e1504d4abafca16534964105d5dff480c46406b39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.
Transparency logSecurity for kaiwen-agent 0.5.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for kaiwen_agent-0.5.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.