SDK Reference

PhronEdge()

Python
from phronedge import PhronEdge

pe = PhronEdge(
    api_key="pe_live_...",          # or set PHRONEDGE_API_KEY env var
    gateway_url="https://...",       # default: api.phronedge.com/api/v1
    timeout=30,                      # request timeout in seconds
    raise_on_block=False,            # raise GovernanceError on block
)

Parameters

ParameterTypeDefaultDescription
api_keystrPHRONEDGE_API_KEY env varYour API key from the console
gateway_urlstrapi.phronedge.com/api/v1Gateway endpoint
timeoutint30Request timeout in seconds
raise_on_blockboolFalseRaise exception instead of returning block info

Example

Python
# Minimal (reads API key from env)
pe = PhronEdge()

# Explicit
pe = PhronEdge(
    api_key="pe_live_4178c0c2db3641efb66c81f9",
    raise_on_block=True,
)

@pe.govern(tool_name)

Decorator that wraps a function with constitutional governance. Every call is intercepted, validated against 7 checkpoints, and either allowed or blocked before the function body executes.

Python
@pe.govern("tool_name")
def my_tool(params):
    return result

Parameters

ParameterTypeDescription
tool_namestrMust match a tool in the signed policy's permitted_tools

Behavior

  • Allowed: Returns the original function's return value. The function executes normally.
  • Blocked (raise_on_block=False): Returns a dict with block details.
  • Blocked (raise_on_block=True): Raises GovernanceError.

Block response format

Python
{
    "blocked": True,
    "reason": "Agent clearance PUB does not meet PII_HEALTH requirement",
    "checkpoint": "Data Classification",
    "regulation": "GDPR Art. 9 Special Categories",
    "retry": True,
    "message": "Tool call blocked by PhronEdge governance."
}

Example: multiple tools

Python
pe = PhronEdge()

@pe.govern("read_database")
def read_database(query):
    return db.read(query)

@pe.govern("write_database")
def write_database(table, data):
    return db.write(table, data)

@pe.govern("delete_record")
def delete_record(table, record_id):
    return db.delete(table, record_id)

# Each tool is independently governed.
# An agent might be allowed to read but blocked from writing or deleting.

GovernanceError

Raised when a tool call is blocked and raise_on_block=True.

Python
from phronedge import PhronEdge, GovernanceError

pe = PhronEdge(raise_on_block=True)

@pe.govern("sensitive_operation")
def sensitive_operation(data):
    return process(data)

try:
    result = sensitive_operation({"patient_id": "P-123"})
except GovernanceError as e:
    print(e.checkpoint)    # "PII Detector"
    print(e.regulation)    # "GDPR Art. 9"
    print(e.reason)        # "PII detected in input: patient_id"
    print(e.blocked)       # True
    print(e.retry)         # True (can retry with sanitized input)

pe.scan(path)

Scan agent code for governance vulnerabilities before deployment.

Python
results = pe.scan("path/to/agent.py")

for vuln in results.vulnerabilities:
    print(f"{vuln.severity}: {vuln.description}")
    print(f"  Fix: {vuln.recommendation}")

pe.status(agent_id)

Check real-time governance status of a deployed agent.

Python
status = pe.status("claims-investigator")

print(status.state)          # "active" | "quarantined" | "killed"
print(status.calls_today)    # 1,234
print(status.blocks_today)   # 3
print(status.last_event)     # last governance event details

pe.export(format)

Export the active policy from your credential.

Python
# Export as OPA Rego
rego = pe.export("rego")
with open("policy.rego", "w") as f:
    f.write(rego)

# Export as YAML
yaml_policy = pe.export("yaml")

# Export as JSON
json_policy = pe.export("json")

Data classifications

Agents are credentialed with specific data clearance levels:

LevelCodeDescription
PublicPUBNo restrictions
InternalINTCompany internal data
ConfidentialCONFSensitive business data
PersonalPIIPersonally identifiable information
HealthPII_HEALTHProtected health information
FinancialPII_FINANCIALFinancial records, payment data
RestrictedRESTRICTEDMaximum classification

An agent with INT clearance cannot access PII_HEALTH data. The gateway blocks it at the Data Classification checkpoint.

Agent tiers

TierDescriptionTypical use
T0Read-only, public dataReport generators, summary agents
T1Single-domain accessMedical reviewer, financial auditor
T2Multi-domain accessCross-functional analysts
T3Orchestrator, can delegateLead agents, pipeline coordinators

Environment variables

VariableRequiredDescription
PHRONEDGE_API_KEYYesAPI key from the console
PHRONEDGE_GATEWAY_URLNoOverride gateway URL
Previous
Quickstart
Next
Framework Guides