Metadata-Version: 2.4
Name: harness-framework
Version: 0.1.0
Summary: Secure, fast, and economical agent harness for Microsoft Ecosystem.
Author: Nguyễn Trường Lâu
Maintainer: octopusai
License-Expression: Apache-2.0
Keywords: agents,agent-harness,llm,tool-calling,approval,openai,security
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: pydantic<3,>=2.14
Requires-Dist: opentelemetry-api<2,>=1.39
Requires-Dist: regex>=2024.11.6
Provides-Extra: mcp
Requires-Dist: mcp<3,>=2.3; extra == "mcp"
Requires-Dist: jsonschema<5,>=4.26; extra == "mcp"
Requires-Dist: anyio<5,>=4.11; extra == "mcp"
Requires-Dist: httpx2<3,>=2.16; extra == "mcp"
Requires-Dist: mcp-types<3,>=2.3; extra == "mcp"
Requires-Dist: referencing<1,>=0.36; extra == "mcp"
Provides-Extra: openai
Requires-Dist: openai<4,>=2.25; extra == "openai"
Provides-Extra: redis
Requires-Dist: redis<8,>=6.4; extra == "redis"
Dynamic: license-file

# Harness Framework

[![PyPI](https://img.shields.io/badge/pypi-harness--framework-blue)](https://pypi.org/project/harness-framework/)
![Python](https://img.shields.io/badge/python-3.12%2B-blue)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue)](https://www.apache.org/licenses/LICENSE-2.0)
![Typed](https://img.shields.io/badge/typing-typed-success)

**Secure, fast, and economical agent harness for Microsoft Ecosystem.**

One call, `create_harness_agent()`, gives an agent planning, memory, files,
skills, shell, web search and background agents, with bounded tool execution,
human approval and serializable session state. Use `Agent.as_tool()` for
synchronous delegation and the optional MCP provider for tools from configured
servers.

- 🧰 **Complete harness:** every piece is configurable and replaceable through
  extension points.
- 🔒 **Secure:** disk, network and process access are off until you enable
  them, and tools with side effects require approval by default.
- ⚡ **Fast:** async end to end, with three core dependencies and low
  per-turn overhead.
- 💰 **Economical:** compaction, token budgets and hard call limits keep cost
  predictable.

## Installation

```bash
pip install harness-framework                   # core
pip install "harness-framework[openai]"          # + OpenAI, Azure OpenAI and Foundry
pip install "harness-framework[redis]"           # + Redis-backed history
pip install "harness-framework[mcp]"             # + stdio and streamable HTTP MCP tools
```

Requires Python 3.12+. The import package is `harness_framework`.

## Quick start

Runs offline. A scripted client drives the real tool loop.

```python
import asyncio

from harness_framework import create_harness_agent, tool
from harness_framework.testing import ScriptedChatClient, function_call


@tool(side_effects=False)
def team_name() -> str:
    """Return the sample team name."""
    return "Platform"


async def main() -> None:
    client = ScriptedChatClient(
        [
            function_call("team_name"),
            lambda messages, _: f"The team is {messages[-1].contents[0].result}.",
        ]
    )
    agent = create_harness_agent(client, tools=[team_name])
    response = await agent.run("Which team is this?")
    print(response.text)  # The team is Platform.


asyncio.run(main())
```

## Azure OpenAI with Microsoft Entra ID

`DefaultAzureCredential` uses `az login` locally and managed or workload
identity in Azure, so no API key is stored.

```bash
pip install "harness-framework[openai]" azure-identity
```

```python
import asyncio

from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import AsyncOpenAI

from harness_framework import create_harness_agent
from harness_framework.openai import OpenAIResponsesClient


async def main() -> None:
    credential = DefaultAzureCredential()
    get_token = get_bearer_token_provider(
        credential, "https://cognitiveservices.azure.com/.default"
    )

    async def entra_token() -> str:
        return await asyncio.to_thread(get_token)  # fresh token per request

    sdk = AsyncOpenAI(
        api_key=entra_token,
        base_url="https://<resource>.openai.azure.com/openai/v1/",
        max_retries=0,  # Harness Framework retries
    )
    try:
        agent = create_harness_agent(OpenAIResponsesClient(model="<deployment>", async_client=sdk))
        response = await agent.run("Say hello from Azure in five words.")
        print(response.text)
    finally:
        await sdk.close()
        credential.close()


asyncio.run(main())
```

The identity needs the **Cognitive Services OpenAI User** role. For OpenAI,
pass `AsyncOpenAI()` as `async_client` instead.

## Harness

| Capability | Default | Boundary |
| --- | --- | --- |
| Todos and plan/execute modes | On | A model-initiated mode change can only narrow tool access |
| File memory | On, in memory | No model writes to built-in stores after the turn is tainted |
| History and compaction | In memory | Bring a `HistoryProvider` (Redis or your own) |
| Tool approval | Required for side effects | Single-use, expiring, bound to the validated arguments |
| File access | Off | Confined workspace, bounded path globs and staged unified text patches |
| Skills | Off | Reviewed local paths; scripts need a runner |
| Shell | Off | `ShellExecutor` run in a host-isolated environment |
| Web search | Off | Taints the turn; `max_searches` caps calls per response |
| Background agents | Off | Inherit the parent's tool grant, taint and limits |
| Agent as a tool | Explicit `Agent.as_tool()` | Fresh child session, approval and inherited limits |
| MCP tools | Off | Explicit server and tool selection, fresh human approval and untrusted results |

**Security.** Approval rule errors fail closed. Untrusted tool output and
injected messages taint the turn and suppress automatic approval. Offering
web search or MCP tools with offer taint enabled also taints the turn.
Telemetry carries operation metadata.

**Cost and speed.** Every run has finite iteration, call, retry, timeout,
output and token limits. Configure a context budget to compact the transcript
and stop oversized requests. Responses API requests use `store=False` by default.
Synchronous tools and callbacks run in worker threads, so the event loop stays
responsive.

## Security

Report vulnerabilities privately to the maintainers, not in a public issue.

## License

Apache License 2.0. Copyright 2026 Nguyễn Trường Lâu and octopusai. See
`LICENSE` and `NOTICE`.
