Skip to main content

Harnessed

PyPI version Python versions CI status License: MIT Status: Alpha

A composable Python agent SDK. Keep tools, instructions and event hooks together in plugins, combine them into reusable packs, and stream typed events from a live session. Harnessed owns the agent loop and plugin lifetimes.

Python 3.12-3.14, Pydantic v2. Optional provider integrations use PydanticAI's Direct API.

Build an agent

uv add "harnessed[openai]"
import asyncio

from harnessed import Agent, Plugin, SystemPrompt, tool
from harnessed.events import ToolCallFinishedEvent
from harnessed.kernel import hook


class Calculator(Plugin):
    def instructions(self) -> SystemPrompt:
        return SystemPrompt("Use add for arithmetic instead of calculating mentally.")

    @tool(readonly=True)
    async def add(self, a: int, b: int) -> int:
        """Add two integers."""
        return a + b

    @hook(ToolCallFinishedEvent)
    def on_result(self, event: ToolCallFinishedEvent) -> None:
        print(f"{event.call.name}: {event.result.status}")


calculator = Calculator()
agent = Agent(
    model="deepseek:deepseek-chat",  # DEEPSEEK_API_KEY
    plugins=[calculator],
    instructions="You are a helpful assistant. Keep answers concise.",
)


async def main() -> None:
    result = await agent.run("What is 19 + 23?")
    print(result.text)


asyncio.run(main())

One plugin colocates the tool, its model-facing instructions and its event hook. @tool derives the input schema from Python types; the method docstring describes the tool. @hook observes the selected event type across the session. The agent appends each plugin's instruction block to its own instructions, in plugin-list order; print(agent.prompt) shows every section and its origin.

Agent is reusable configuration. agent.run() opens a session for one turn; use agent.session() when several turns should share a conversation.

Select a model with a provider:model string, such as Agent(model="openai-responses:gpt-6.1-terra") (OPENAI_API_KEY). Harnessed configures the PydanticAI adapter automatically. Use an explicit model object when you need generation defaults or native provider configuration; see model configuration.

Keep a conversation open

Use one session for shared history and typed streaming events:

from harnessed.events import TextDeltaEvent


async def conversation() -> None:
    async with agent.session() as session:
        async with session.stream("What is 19 + 23?") as run:
            async for event in run:
                if isinstance(event, TextDeltaEvent):
                    print(event.text, end="", flush=True)
            result = await run.result()

        follow_up = await session.run("Add 8 to that result.")
        print(follow_up.text)

Sessions own live plugin resources and conversation state. Export result.state for application-owned persistence, or configure a session store to save automatically. See sessions and streaming for restoration, cancellation and approvals.

Explore the SDK

Task Guide
Configure providers and generation settings Models
Compose packs, inject services or mount temporary tools Plugins
Define tools, deadlines and policies Tools
Validate typed answers Structured output
Test without credentials Testing
Connect MCP, subagents, sandboxes or tracing Documentation index

The SDK reference covers the public API; executable examples show complete offline compositions. The standalone harnessed.kernel uses only the standard library.

Harnessed 0.x is alpha software. Read the compatibility policy and changelog before upgrading. For contributions and release checks, see development.

Inspired by DeepSeek Harness and Cordis. Released under the MIT License.

Metadata

Release files for harnessed 0.20.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for harnessed 0.20.0
File Size Uploaded Provenance Actions
harnessed-0.20.0.tar.gz 245.4 kB With provenance Details for harnessed-0.20.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for harnessed 0.20.0
File Interpreter ABI Platform Actions
harnessed-0.20.0-py3-none-any.whl Python 3 none any Details for harnessed-0.20.0-py3-none-any.whl

Total release size: 548.4 kB

Release files / harnessed-0.20.0.tar.gz

Download URL harnessed-0.20.0.tar.gz
Size 245.4 kB
Tags Source
SHA-256 checksum
How to use checksums
22fef3e259b768ba5f7ef74f2f0ae9640942df8605e36f16c7b75d1de1b638f0
BLAKE2b-256 checksum
How to use checksums
e65cc06915e5f40e1c9070b704d7f31e3b314b723249b93266b1daf522580a9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Release files / harnessed-0.20.0-py3-none-any.whl

Download URL harnessed-0.20.0-py3-none-any.whl
Size 303.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5b7253376c2d5cbe1b75b9f14e40b23db9d3a7eebcb91685ed04c7260b6e9f8
BLAKE2b-256 checksum
How to use checksums
d0a863aea480dad17044cdf100046f0918dcee3cac20409ce5cda1f7be4c5f37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Security for harnessed 0.20.0

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.

Select from 2 files

Attestation for harnessed-0.20.0.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 Nov 19, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page