Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: "3.12"
cache: pip
- run: python -m pip install "pisama-core @ git+https://github.com/Pisama-AI/pisama-core.git@v1.8.2"
- run: python -m pip install -e ".[dev,mcp]"
- run: python -m pip install -e ".[dev,mcp,auto]"
- run: ruff check src tests
- run: mypy src/pisama
- run: pytest -q --cov=pisama --cov-report=term --cov-fail-under=60
Expand All @@ -37,7 +37,7 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: pip
- run: python -m pip install "pisama-core @ git+https://github.com/Pisama-AI/pisama-core.git@v1.8.2"
- run: python -m pip install -e ".[dev,mcp]"
- run: python -m pip install -e ".[dev,mcp,auto]"
- run: pytest -q

distribution:
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ All notable changes to the `pisama` meta-package are documented here. The packag

## [Unreleased]

## [0.6.0] - 2026-07-29

### Added

- `pisama.auto` -- consolidated in-package original of the standalone
`pisama-auto` distribution (zero-code auto-instrumentation for the
Anthropic/OpenAI SDKs, tracing to either the Pisama platform or a
self-hosted OTLP collector). New `auto` extra:
`pip install "pisama[auto]"`.
- `pisama.agents` -- consolidated in-package original of the standalone
`pisama-agent-sdk` distribution (real-time hooks, tools, and a
`pisama-openhands-monitor` console script for Claude Agent SDK / Harbor
integrations). New `agents` and `telemetry` extras:
`pip install "pisama[agents]"`.
- `pisama.agents.__version__`, aliased to `pisama.__version__` since this
code no longer releases independently.

Both submodules keep publishing as standalone distributions
(`pisama-auto`, `pisama-agent-sdk`) for this release; those packages become
thin shims re-exporting this module in a later release. A bare
`pip install pisama` pulls in no new required dependencies -- `pisama.auto`
and `pisama.agents` stay behind their respective extras.

## [0.5.7] - 2026-07-29

### Changed
Expand Down
39 changes: 37 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "pisama"
version = "0.5.7"
version = "0.6.0"
description = "Multi-agent failure detection for production AI systems"
readme = "README.md"
license = "MIT"
Expand Down Expand Up @@ -46,8 +46,33 @@ dependencies = [
# server.py:138 with AttributeError: 'Server' object has no attribute
# 'list_tools'. Lift this only once the server is ported to the 2.x API.
mcp = ["mcp>=1.0.0,<2"]
auto = ["pisama-auto>=0.1.0", "opentelemetry-api>=1.20.0", "opentelemetry-sdk>=1.20.0"]
# pisama.auto is now original code inside this package (see src/pisama/auto/),
# not an import of the standalone pisama-auto distribution -- pisama-auto stays
# published separately and, in a later release, becomes a thin shim re-exporting
# this module. wrapt is the function-wrapping library pisama.auto's patches
# submodule needs to monkeypatch the anthropic/openai clients.
auto = [
"opentelemetry-api>=1.20.0",
"opentelemetry-sdk>=1.20.0",
"opentelemetry-exporter-otlp-proto-http>=1.20.0",
"wrapt>=1.15.0",
]
langgraph = ["langgraph>=0.2.0", "langchain-core>=0.3.0"]
# pisama.agents mirrors pisama-agent-sdk's own optional-extra split: httpx is
# only needed for the HTTP-backed calls (analyze_atif, PisamaEvaluator), and
# posthog only for opt-in SDK-side telemetry in DetectionBridge. Neither is
# imported at module load time (see pisama/agents/atif.py, evaluator.py,
# bridge.py) so `import pisama` and `import pisama.agents` both work without
# either installed; only the specific calls that need them raise ImportError
# with a `pip install pisama[agents]` hint until the extra is added. httpx is
# already a hard dependency of the base `pisama` install (see `dependencies`
# above) for unrelated reasons, so this extra is declared for documentation
# and for behavioral parity with pisama-agent-sdk's `evaluator` extra, not
# because it changes what a bare `pip install pisama` pulls in today.
agents = ["httpx>=0.24"]
# Pass-through of pisama-agent-sdk's own `telemetry` extra (opt-in PostHog
# telemetry in pisama.agents.bridge.DetectionBridge).
telemetry = ["posthog>=3.0"]
dev = [
"build>=1.2",
"mypy>=1.10",
Expand All @@ -56,10 +81,20 @@ dev = [
"pytest-cov>=5.0",
"ruff>=0.4",
"twine>=5.0",
# Test-only: tests/test_auto_sdk_instrumentation.py patches these SDK
# clients directly. Carried over from pisama-auto's own `dev` extra;
# not a runtime dependency of the `auto` extra itself, since users
# bring their own anthropic/openai client.
"anthropic>=0.40",
"openai>=1.50",
]

[project.scripts]
pisama = "pisama.cli.main:main"
# From pisama-agent-sdk: batch analysis of a completed OpenHands /
# Harbor-on-OpenHands session directory. Needs the `agents` extra installed
# to reach the network call inside analyze_atif(); `--help` works bare.
pisama-openhands-monitor = "pisama.agents.cli.openhands_monitor:main"

[project.urls]
Homepage = "https://pisama.ai"
Expand Down
2 changes: 1 addition & 1 deletion src/pisama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

__version__ = _pkg_version("pisama")
except PackageNotFoundError: # running from a source checkout without an install
__version__ = "0.5.7"
__version__ = "0.6.0"

from pisama._analyze import AnalyzeResult, Issue, analyze, async_analyze
from pisama._http import PisamaAuthError
Expand Down
212 changes: 212 additions & 0 deletions src/pisama/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
"""Pisama Agents -- real-time hooks and tools for agent runtimes.

Optional submodule of the ``pisama`` package (extra: ``pisama[agents]``).
Provides hooks and tools for Claude Agent SDK that connect to Pisama's
detection infrastructure for real-time failure prevention.

Mirrors the standalone ``pisama-agent-sdk`` distribution's public API.
That package keeps shipping independently; this module is the
consolidated, in-package original (not a re-export or a dependency on
the standalone package -- see the module-level docstrings for the
per-symbol origin).

Quick Start (passive monitoring):
from pisama.agents import pre_tool_use_hook, post_tool_use_hook

agent.hooks.pre_tool_use = pre_tool_use_hook
agent.hooks.post_tool_use = post_tool_use_hook

Agent Self-Check (active verification):
from pisama.agents import check

result = await check(
output="The server is healthy based on the metrics.",
context={"query": "Is auth-service down?", "sources": [...]}
)
if not result["passed"]:
# Revise output based on result["issues"]

Claude Agent SDK Custom Tool:
from pisama.agents import create_check_tool
from claude_agent_sdk import ClaudeAgentOptions

options = ClaudeAgentOptions(
custom_tools=[create_check_tool()],
)
"""

# This code no longer releases independently (it shipped standalone as
# pisama-agent-sdk through 0.3.2), so __version__ tracks the installed
# base-package version rather than a separate hardcoded number.
from pisama import __version__

# Hook functions (primary API)
# ATIF (Harbor) trajectory analysis
from pisama.agents.atif import (
AtifAnalyzeResult,
AtifDetection,
analyze_atif,
analyze_atif_batch,
)

# Auto-verify was never mirrored here: pisama-agent-sdk removed it in 0.3.0
# because it vendored private backend verification primitives into an MIT
# package. Verification stays a hosted-service concern.
# Configuration
# Bridge (for advanced use)
from pisama.agents.bridge import DetectionBridge, configure_bridge, create_bridge, get_bridge

# Chaos engineering (SDK-level failure injection)
from pisama.agents.chaos import (
ChaosConfig,
ContextTruncation,
ErrorInjection,
LatencyInjection,
OutputCorruption,
ToolFailure,
)

# Agent self-check
from pisama.agents.check import check, configure_check

# Specification compliance (beta, gated by PISAMA_ENABLE_CHECK_COMPLIANCE)
from pisama.agents.check_compliance import (
BehavioralRule,
ComplianceResult,
PisamaFeatureNotEnabledError,
Violation,
check_compliance,
)

# Clarification primitive -- pause/ask/resume for entity_confusion etc.
from pisama.agents.clarification import (
ClarificationPrimitive,
ClarificationRequest,
register_clarification_builder,
)
from pisama.agents.clarification import (
Resolution as ClarificationResolution,
)
from pisama.agents.config import BridgeConfig, load_config

# Evaluator client (Pisama-as-evaluator for multi-agent harnesses)
from pisama.agents.evaluator import EvalFailure, EvalResult, PisamaEvaluator

# In-loop healing
from pisama.agents.heal import HealingResult, heal_now

# Matchers
from pisama.agents.hooks.matchers import (
AGENT_TOOLS,
ALL_TOOLS,
DANGEROUS_COMMANDS,
FILE_TOOLS,
SHELL_TOOLS,
HookMatcher,
create_matcher,
)
from pisama.agents.hooks.post_tool_use import PostToolUseHook, post_tool_use_hook
from pisama.agents.hooks.pre_tool_use import PreToolUseHook, pre_tool_use_hook

# Indication channel -- out-of-band signal for the developer running the
# agent. Wire on_indication(callable) to receive structured notifications
# on every healing outcome.
from pisama.agents.indication import (
SDKIndication,
clear_indication_callbacks,
on_indication,
)

# OpenHands event-stream adapter
from pisama.agents.openhands_adapter import (
OpenHandsEventStreamAdapter,
StreamingCallback,
StreamingDetection,
)

# Session management
from pisama.agents.session import SessionManager, session_manager

# Custom tools for Claude Agent SDK
from pisama.agents.tools import create_check_tool, pisama_check_handler

# Types
from pisama.agents.types import BridgeResult, HookContext, HookInput, HookJSONOutput

__all__ = [
"__version__",
# Hook functions
"pre_tool_use_hook",
"post_tool_use_hook",
# Hook classes
"PreToolUseHook",
"PostToolUseHook",
# Configuration
"configure_bridge",
"create_bridge",
"get_bridge",
"BridgeConfig",
"load_config",
# Bridge
"DetectionBridge",
# Types
"BridgeResult",
"HookInput",
"HookContext",
"HookJSONOutput",
# Matchers
"HookMatcher",
"ALL_TOOLS",
"FILE_TOOLS",
"SHELL_TOOLS",
"DANGEROUS_COMMANDS",
"AGENT_TOOLS",
"create_matcher",
# Session
"SessionManager",
"session_manager",
# Agent self-check
"check",
"configure_check",
# In-loop healing
"heal_now",
"HealingResult",
# Clarification primitive
"ClarificationPrimitive",
"ClarificationRequest",
"ClarificationResolution",
"register_clarification_builder",
# Specification compliance (beta)
"check_compliance",
"ComplianceResult",
"BehavioralRule",
"Violation",
"PisamaFeatureNotEnabledError",
# Indication channel
"SDKIndication",
"on_indication",
"clear_indication_callbacks",
# Custom tools
"create_check_tool",
"pisama_check_handler",
# Evaluator
"PisamaEvaluator",
"EvalResult",
"EvalFailure",
# ATIF (Harbor) trajectory analysis
"analyze_atif",
"analyze_atif_batch",
"AtifAnalyzeResult",
"AtifDetection",
# OpenHands event-stream adapter
"OpenHandsEventStreamAdapter",
"StreamingDetection",
"StreamingCallback",
# Chaos engineering
"ChaosConfig",
"ToolFailure",
"LatencyInjection",
"ErrorInjection",
"OutputCorruption",
"ContextTruncation",
]
Loading
Loading