Skip to main content

Behavioral monitoring and directive control for AI agents

Project description

SOMA

Behavioral monitoring and guidance system for AI agents.

SOMA observes agent actions in real-time, computes behavioral pressure from vital signals, and injects corrective guidance before problems escalate. A nervous system for AI agents.

Install

pip install soma-ai

or

uv add soma-ai

Python 3.11+

Quick Start

Claude Code hooks (zero-code)

soma install

Sets up pre/post tool-use hooks. Works automatically from that point on — no code changes needed.

SDK wrapper (any LLM client)

import soma
import anthropic

client = soma.wrap(anthropic.Anthropic())

# All API calls are now monitored.
# SOMA injects guidance directly into the message stream.
response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}]
)

How It Works

action → vitals → pressure → guidance → injection

Every agent action flows through the pipeline:

  1. Vitals — uncertainty, drift, error rate, token usage, cost
  2. Pressure — signals aggregate into a 0-1 scalar via z-score + sigmoid
  3. Guidance — pressure maps to response modes: OBSERVE → GUIDE → WARN → BLOCK
  4. Injection — corrective guidance reaches the agent (stdout for hooks, messages for wrap)

Guidance Patterns

SOMA ships 9 guidance patterns, ranked by priority:

# Pattern What it catches
1 cost_spiral Accelerating spend combined with high error rate
2 budget Budget below 20% remaining
3 bash_retry Bash followed by Bash after a failure
4 retry_storm 3+ consecutive same-tool failures
5 error_cascade 3+ consecutive errors across different tools
6 blind_edit Edit/Write without a prior Read of the file
7 entropy_drop Tool tunnel vision (monotool usage), with panic escalation via velocity
8 context Context window more than 80% full
9 drift Behavioral drift from initial tool-use patterns

Healing Transitions

Data-backed tool suggestions injected when patterns are detected:

  • Bash → Read (reduces error rate by 7%)
  • Edit → Read (reduces error rate by 5%)
  • Write → Grep (reduces error rate by 5%)

Cross-Session Lessons

SOMA stores lessons from past sessions and matches them to current situations using trigram similarity. Same error type with a different path still gets caught.

CLI

soma status       # Show current monitoring state
soma install      # Set up Claude Code hooks
soma config       # View/edit configuration
soma analytics    # Query the analytics DB
soma replay       # Replay a recorded session
soma doctor       # Diagnose issues

Interactive TUI dashboard:

soma              # Launches the dashboard

Entry Points

Command Purpose
soma Main CLI and TUI dashboard
soma-hook Hook dispatcher for Claude Code
soma-statusline Status line formatter

License

MIT

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

soma_ai-2026.4.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

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

soma_ai-2026.4.0-py3-none-any.whl (297.6 kB view details)

Uploaded Python 3

File details

Details for the file soma_ai-2026.4.0.tar.gz.

File metadata

  • Download URL: soma_ai-2026.4.0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for soma_ai-2026.4.0.tar.gz
Algorithm Hash digest
SHA256 426cd9cc3fdecd82fc9c27a626d9ab10fb1086da6a1e0280f5fef55847433454
MD5 02ef1cea9e7b69fab4486566e4fef473
BLAKE2b-256 fd477b216902af5edf2b3aabef0f90d6a71e8be81bcdc89d4924a6e6554fbb36

See more details on using hashes here.

File details

Details for the file soma_ai-2026.4.0-py3-none-any.whl.

File metadata

  • Download URL: soma_ai-2026.4.0-py3-none-any.whl
  • Upload date:
  • Size: 297.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for soma_ai-2026.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccebe0c1c31729eace2e21c818dacdd699e618aa7f618189d48b8ed9721c1012
MD5 4bc0a380bd78be4f0379cc4f93f1981e
BLAKE2b-256 22a2d459461c3e4b458bd025fb764bd46fc31247d93cadb0ffb103265f34bda8

See more details on using hashes here.

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