actshield 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- actshield/__init__.py +439 -0
- actshield/__main__.py +46 -0
- actshield/agents/__init__.py +12 -0
- actshield/agents/agent.py +200 -0
- actshield/agents/identity.py +114 -0
- actshield/api/__init__.py +34 -0
- actshield/api/models.py +198 -0
- actshield/api/server.py +669 -0
- actshield/api/service.py +599 -0
- actshield/approval/__init__.py +15 -0
- actshield/approval/approval.py +164 -0
- actshield/cli/__init__.py +8 -0
- actshield/cli/graph.py +49 -0
- actshield/cli/main.py +802 -0
- actshield/cli/shell.py +406 -0
- actshield/cli/theme.py +110 -0
- actshield/client.py +757 -0
- actshield/config.py +88 -0
- actshield/context/__init__.py +14 -0
- actshield/context/context.py +161 -0
- actshield/context/provenance.py +108 -0
- actshield/context/taint.py +48 -0
- actshield/decisions/decision.py +74 -0
- actshield/delegation/__init__.py +11 -0
- actshield/delegation/authority.py +63 -0
- actshield/delegation/delegation.py +180 -0
- actshield/demo.py +139 -0
- actshield/doctor.py +94 -0
- actshield/drift/__init__.py +27 -0
- actshield/drift/drift_engine.py +149 -0
- actshield/drift/drift_models.py +63 -0
- actshield/evaluation/__init__.py +1 -0
- actshield/evaluation/cases/__init__.py +1 -0
- actshield/evaluation/eval_suite.py +254 -0
- actshield/forensics/__init__.py +53 -0
- actshield/forensics/access_graph.py +216 -0
- actshield/forensics/authority_graph.py +186 -0
- actshield/forensics/delegation_graph.py +119 -0
- actshield/forensics/explanation.py +254 -0
- actshield/forensics/models.py +488 -0
- actshield/forensics/queries.py +367 -0
- actshield/forensics/serializers.py +68 -0
- actshield/forensics/service.py +310 -0
- actshield/forensics/snapshots.py +174 -0
- actshield/gates/__init__.py +13 -0
- actshield/gates/gate_models.py +46 -0
- actshield/gates/security_gate.py +191 -0
- actshield/gateway/__init__.py +13 -0
- actshield/gateway/http.py +191 -0
- actshield/gateway/mcp.py +292 -0
- actshield/incidents/__init__.py +25 -0
- actshield/incidents/incident.py +94 -0
- actshield/incidents/incident_engine.py +163 -0
- actshield/incidents/incident_rules.py +116 -0
- actshield/incidents/incident_state.py +58 -0
- actshield/integrations/__init__.py +24 -0
- actshield/integrations/ai_secura.py +169 -0
- actshield/integrations/ai_secura_analysis.py +236 -0
- actshield/integrations/apiris.py +122 -0
- actshield/integrations/few_shot.py +104 -0
- actshield/integrations/ollama_adapter.py +538 -0
- actshield/integrations/prompts/__init__.py +1 -0
- actshield/integrations/prompts/examples/__init__.py +1 -0
- actshield/integrations/security_packet.py +82 -0
- actshield/llm_config.py +89 -0
- actshield/offensive/__init__.py +95 -0
- actshield/offensive/adaptive/__init__.py +22 -0
- actshield/offensive/adaptive/adaptive_engine.py +165 -0
- actshield/offensive/adaptive/attack_selector.py +51 -0
- actshield/offensive/adaptive/boundary_search.py +99 -0
- actshield/offensive/adaptive/campaign_memory.py +123 -0
- actshield/offensive/adaptive/feedback.py +84 -0
- actshield/offensive/adaptive/mutation_planner.py +57 -0
- actshield/offensive/attack.py +78 -0
- actshield/offensive/campaign.py +219 -0
- actshield/offensive/corpus.py +155 -0
- actshield/offensive/engine.py +466 -0
- actshield/offensive/evaluator.py +116 -0
- actshield/offensive/evidence.py +63 -0
- actshield/offensive/generator.py +128 -0
- actshield/offensive/mutation.py +101 -0
- actshield/offensive/results.py +77 -0
- actshield/offensive/safety.py +80 -0
- actshield/offensive/strategies/__init__.py +22 -0
- actshield/offensive/strategies/authority_escalation.py +100 -0
- actshield/offensive/strategies/base.py +34 -0
- actshield/offensive/strategies/context_manipulation.py +100 -0
- actshield/offensive/strategies/data_exfiltration.py +100 -0
- actshield/offensive/strategies/delegation_attacks.py +100 -0
- actshield/offensive/strategies/mcp_attacks.py +100 -0
- actshield/offensive/strategies/prompt_injection.py +100 -0
- actshield/offensive/strategies/tool_poisoning.py +100 -0
- actshield/offensive/target.py +113 -0
- actshield/offensive/vulnerable_target.py +121 -0
- actshield/persistence/__init__.py +18 -0
- actshield/persistence/siem.py +102 -0
- actshield/persistence/storage.py +240 -0
- actshield/policy/__init__.py +12 -0
- actshield/policy/evaluator.py +294 -0
- actshield/policy/intent.py +113 -0
- actshield/policy/policy.py +48 -0
- actshield/posture/__init__.py +26 -0
- actshield/posture/posture_engine.py +186 -0
- actshield/posture/posture_models.py +152 -0
- actshield/posture/posture_rules.py +137 -0
- actshield/providers/__init__.py +32 -0
- actshield/providers/anthropic_provider.py +146 -0
- actshield/providers/base.py +160 -0
- actshield/providers/gemini_provider.py +133 -0
- actshield/providers/null_provider.py +40 -0
- actshield/providers/ollama_provider.py +135 -0
- actshield/providers/openai_provider.py +142 -0
- actshield/providers/registry.py +244 -0
- actshield/py.typed +0 -0
- actshield/response/__init__.py +14 -0
- actshield/response/response_actions.py +39 -0
- actshield/response/response_audit.py +32 -0
- actshield/response/response_engine.py +139 -0
- actshield/risk/models.py +104 -0
- actshield/serve.py +117 -0
- actshield/static/404.html +1 -0
- actshield/static/__next.__PAGE__.txt +24 -0
- actshield/static/__next._full.txt +20 -0
- actshield/static/__next._tree.txt +4 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_buildManifest.js +11 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_clientMiddlewareManifest.js +1 -0
- actshield/static/_next/static/Yp_swxN-C9UoCRNOwkYnY/_ssgManifest.js +1 -0
- actshield/static/_next/static/chunks/09kny2eqjc2or.js +1 -0
- actshield/static/_next/static/chunks/0c1zba1u9whdp.js +1 -0
- actshield/static/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
- actshield/static/_next/static/chunks/0dbjjeg01x25o.js +1 -0
- actshield/static/_next/static/chunks/0duobs55ne238.js +1 -0
- actshield/static/_next/static/chunks/0iaz41l6068e4.js +1 -0
- actshield/static/_next/static/chunks/0mjhyv72x2idp.js +1 -0
- actshield/static/_next/static/chunks/0nelpqfu_ciq6.js +1 -0
- actshield/static/_next/static/chunks/0p1bci9ch797v.js +1 -0
- actshield/static/_next/static/chunks/0tld_ygho5tgm.js +1 -0
- actshield/static/_next/static/chunks/0w1-y7oni66j9.js +1 -0
- actshield/static/_next/static/chunks/10537zyl427zj.js +1 -0
- actshield/static/_next/static/chunks/11pc_jkl3aggn.js +1 -0
- actshield/static/_next/static/chunks/16k7nw0b3t8ys.js +1 -0
- actshield/static/_next/static/chunks/19mx3mg6lkumu.js +1 -0
- actshield/static/_next/static/chunks/1_8p47b-kxg2a.js +1 -0
- actshield/static/_next/static/chunks/1dszjozwfqegx.js +1 -0
- actshield/static/_next/static/chunks/1h43jcb90-m2r.js +22 -0
- actshield/static/_next/static/chunks/1ly04cvt_wh_j.js +1 -0
- actshield/static/_next/static/chunks/1odxrypuwuwp_.js +1 -0
- actshield/static/_next/static/chunks/1oes4c35qz5ku.js +1 -0
- actshield/static/_next/static/chunks/1ow883jl4ln-r.js +16 -0
- actshield/static/_next/static/chunks/1po7bna1as8tc.js +1 -0
- actshield/static/_next/static/chunks/1rsh0og8ifkzx.js +1 -0
- actshield/static/_next/static/chunks/1v0lwzv-859z_.js +1 -0
- actshield/static/_next/static/chunks/25iat2epwx25a.js +1 -0
- actshield/static/_next/static/chunks/25uvt4s2f39a4.js +1 -0
- actshield/static/_next/static/chunks/27t_qfc-3_lzs.js +1 -0
- actshield/static/_next/static/chunks/28bkmy8mez7gm.js +1 -0
- actshield/static/_next/static/chunks/2b6brmw_drw1p.js +1 -0
- actshield/static/_next/static/chunks/2fnhtxi4j6vge.js +1 -0
- actshield/static/_next/static/chunks/2p087eftxemg4.js +6 -0
- actshield/static/_next/static/chunks/2s8pao_z8pgtq.js +1 -0
- actshield/static/_next/static/chunks/2yj7ooc2c-zpg.js +1 -0
- actshield/static/_next/static/chunks/3-mrrr8udt5tk.js +1 -0
- actshield/static/_next/static/chunks/310vm2bl3xxpt.js +31 -0
- actshield/static/_next/static/chunks/35mvsv251jx1r.css +3 -0
- actshield/static/_next/static/chunks/370vf0oetlsx9.js +1 -0
- actshield/static/_next/static/chunks/3e-2m72tyo556.js +1 -0
- actshield/static/_next/static/chunks/3fntmmi971322.js +1 -0
- actshield/static/_next/static/chunks/3fzw-g0hycl2c.js +1 -0
- actshield/static/_next/static/chunks/3lopq3lhmcjxg.js +129 -0
- actshield/static/_next/static/chunks/3mpe2jejel0v2.css +1 -0
- actshield/static/_next/static/chunks/3t8o4f2lzr2sf.js +1 -0
- actshield/static/_next/static/chunks/3y-v1neyllne5.js +1 -0
- actshield/static/_next/static/chunks/43oiwy8mx6cs1.js +1 -0
- actshield/static/_next/static/chunks/turbopack-23wzuebcy_lxm.js +1 -0
- actshield/static/_next/static/media/1bffadaabf893a1e-s.3-6t-g6q0vh0a.woff2 +0 -0
- actshield/static/_next/static/media/2bbe8d2671613f1f-s.0k62hbripvv8p.woff2 +0 -0
- actshield/static/_next/static/media/2c55a0e60120577a-s.0-dom-5bn10r2.woff2 +0 -0
- actshield/static/_next/static/media/5476f68d60460930-s.2uwcyprjm3xu3.woff2 +0 -0
- actshield/static/_next/static/media/83afe278b6a6bb3c-s.p.2bn3s6zvc0dyp.woff2 +0 -0
- actshield/static/_next/static/media/9c72aa0f40e4eef8-s.1y4-pdgsjb-pw.woff2 +0 -0
- actshield/static/_next/static/media/ad66f9afd8947f86-s.3lvt2whj97whp.woff2 +0 -0
- actshield/static/_next/static/media/favicon.2vob68tjqpejf.ico +0 -0
- actshield/static/_not-found/__next._full.txt +17 -0
- actshield/static/_not-found/__next._not-found/__PAGE__.txt +23 -0
- actshield/static/_not-found/__next._tree.txt +3 -0
- actshield/static/_not-found.html +1 -0
- actshield/static/_not-found.txt +17 -0
- actshield/static/access/matrix/__next._full.txt +24 -0
- actshield/static/access/matrix/__next._tree.txt +4 -0
- actshield/static/access/matrix/__next.access/matrix/__PAGE__.txt +30 -0
- actshield/static/access/matrix.html +1 -0
- actshield/static/access/matrix.txt +24 -0
- actshield/static/activity/__next._full.txt +22 -0
- actshield/static/activity/__next._tree.txt +4 -0
- actshield/static/activity/__next.activity/__PAGE__.txt +27 -0
- actshield/static/activity.html +1 -0
- actshield/static/activity.txt +22 -0
- actshield/static/agents/__next._full.txt +22 -0
- actshield/static/agents/__next._tree.txt +4 -0
- actshield/static/agents/__next.agents/__PAGE__.txt +27 -0
- actshield/static/agents.html +1 -0
- actshield/static/agents.txt +22 -0
- actshield/static/ai-secura/__next._full.txt +22 -0
- actshield/static/ai-secura/__next._tree.txt +4 -0
- actshield/static/ai-secura/__next.ai-secura/__PAGE__.txt +27 -0
- actshield/static/ai-secura.html +1 -0
- actshield/static/ai-secura.txt +22 -0
- actshield/static/api/__next._full.txt +22 -0
- actshield/static/api/__next._tree.txt +4 -0
- actshield/static/api/__next.api/__PAGE__.txt +27 -0
- actshield/static/api.html +15 -0
- actshield/static/api.txt +22 -0
- actshield/static/apiris/__next._full.txt +22 -0
- actshield/static/apiris/__next._tree.txt +4 -0
- actshield/static/apiris/__next.apiris/__PAGE__.txt +27 -0
- actshield/static/apiris.html +1 -0
- actshield/static/apiris.txt +22 -0
- actshield/static/attack-graph/__next._full.txt +23 -0
- actshield/static/attack-graph/__next._tree.txt +5 -0
- actshield/static/attack-graph/__next.attack-graph/__PAGE__.txt +28 -0
- actshield/static/attack-graph.html +2 -0
- actshield/static/attack-graph.txt +23 -0
- actshield/static/campaigns/__next._full.txt +22 -0
- actshield/static/campaigns/__next._tree.txt +4 -0
- actshield/static/campaigns/__next.campaigns/__PAGE__.txt +27 -0
- actshield/static/campaigns.html +1 -0
- actshield/static/campaigns.txt +22 -0
- actshield/static/context/__next._full.txt +22 -0
- actshield/static/context/__next._tree.txt +4 -0
- actshield/static/context/__next.context/__PAGE__.txt +27 -0
- actshield/static/context.html +1 -0
- actshield/static/context.txt +22 -0
- actshield/static/dashboard/__next._full.txt +22 -0
- actshield/static/dashboard/__next._tree.txt +4 -0
- actshield/static/dashboard/__next.dashboard/__PAGE__.txt +27 -0
- actshield/static/dashboard.html +1 -0
- actshield/static/dashboard.txt +22 -0
- actshield/static/delegations/__next._full.txt +22 -0
- actshield/static/delegations/__next._tree.txt +4 -0
- actshield/static/delegations/__next.delegations/__PAGE__.txt +27 -0
- actshield/static/delegations.html +1 -0
- actshield/static/delegations.txt +22 -0
- actshield/static/demo/__next._full.txt +22 -0
- actshield/static/demo/__next._tree.txt +4 -0
- actshield/static/demo/__next.demo/__PAGE__.txt +27 -0
- actshield/static/demo.html +1 -0
- actshield/static/demo.txt +22 -0
- actshield/static/drift/__next._full.txt +22 -0
- actshield/static/drift/__next._tree.txt +4 -0
- actshield/static/drift/__next.drift/__PAGE__.txt +27 -0
- actshield/static/drift.html +1 -0
- actshield/static/drift.txt +22 -0
- actshield/static/favicon.ico +0 -0
- actshield/static/file.svg +1 -0
- actshield/static/forensics/__next._full.txt +22 -0
- actshield/static/forensics/__next._tree.txt +4 -0
- actshield/static/forensics/__next.forensics/__PAGE__.txt +27 -0
- actshield/static/forensics.html +1 -0
- actshield/static/forensics.txt +22 -0
- actshield/static/globe.svg +1 -0
- actshield/static/incidents/__next._full.txt +22 -0
- actshield/static/incidents/__next._tree.txt +4 -0
- actshield/static/incidents/__next.incidents/__PAGE__.txt +27 -0
- actshield/static/incidents.html +1 -0
- actshield/static/incidents.txt +22 -0
- actshield/static/index.html +3 -0
- actshield/static/index.txt +20 -0
- actshield/static/logo.png +0 -0
- actshield/static/metrics/__next._full.txt +22 -0
- actshield/static/metrics/__next._tree.txt +4 -0
- actshield/static/metrics/__next.metrics/__PAGE__.txt +27 -0
- actshield/static/metrics.html +1 -0
- actshield/static/metrics.txt +22 -0
- actshield/static/next.svg +1 -0
- actshield/static/offensive/__next._full.txt +22 -0
- actshield/static/offensive/__next._tree.txt +4 -0
- actshield/static/offensive/__next.offensive/__PAGE__.txt +27 -0
- actshield/static/offensive.html +1 -0
- actshield/static/offensive.txt +22 -0
- actshield/static/policies/__next._full.txt +22 -0
- actshield/static/policies/__next._tree.txt +4 -0
- actshield/static/policies/__next.policies/__PAGE__.txt +27 -0
- actshield/static/policies.html +1 -0
- actshield/static/policies.txt +22 -0
- actshield/static/posture/__next._full.txt +22 -0
- actshield/static/posture/__next._tree.txt +4 -0
- actshield/static/posture/__next.posture/__PAGE__.txt +27 -0
- actshield/static/posture.html +1 -0
- actshield/static/posture.txt +22 -0
- actshield/static/regressions/__next._full.txt +22 -0
- actshield/static/regressions/__next._tree.txt +4 -0
- actshield/static/regressions/__next.regressions/__PAGE__.txt +27 -0
- actshield/static/regressions.html +1 -0
- actshield/static/regressions.txt +22 -0
- actshield/static/reports/__next._full.txt +22 -0
- actshield/static/reports/__next._tree.txt +4 -0
- actshield/static/reports/__next.reports/__PAGE__.txt +27 -0
- actshield/static/reports.html +1 -0
- actshield/static/reports.txt +22 -0
- actshield/static/resources/__next._full.txt +22 -0
- actshield/static/resources/__next._tree.txt +4 -0
- actshield/static/resources/__next.resources/__PAGE__.txt +27 -0
- actshield/static/resources.html +1 -0
- actshield/static/resources.txt +22 -0
- actshield/static/security-gates/__next._full.txt +22 -0
- actshield/static/security-gates/__next._tree.txt +4 -0
- actshield/static/security-gates/__next.security-gates/__PAGE__.txt +27 -0
- actshield/static/security-gates.html +1 -0
- actshield/static/security-gates.txt +22 -0
- actshield/static/settings/__next._full.txt +22 -0
- actshield/static/settings/__next._tree.txt +4 -0
- actshield/static/settings/__next.settings/__PAGE__.txt +27 -0
- actshield/static/settings.html +1 -0
- actshield/static/settings.txt +22 -0
- actshield/static/tasks/__next._full.txt +22 -0
- actshield/static/tasks/__next._tree.txt +4 -0
- actshield/static/tasks/__next.tasks/__PAGE__.txt +27 -0
- actshield/static/tasks.html +1 -0
- actshield/static/tasks.txt +22 -0
- actshield/static/threats/__next._full.txt +22 -0
- actshield/static/threats/__next._tree.txt +4 -0
- actshield/static/threats/__next.threats/__PAGE__.txt +27 -0
- actshield/static/threats.html +1 -0
- actshield/static/threats.txt +22 -0
- actshield/static/tools/__next._full.txt +22 -0
- actshield/static/tools/__next._tree.txt +4 -0
- actshield/static/tools/__next.tools/__PAGE__.txt +27 -0
- actshield/static/tools.html +1 -0
- actshield/static/tools.txt +22 -0
- actshield/static/traces/__next._full.txt +22 -0
- actshield/static/traces/__next._tree.txt +4 -0
- actshield/static/traces/__next.traces/__PAGE__.txt +27 -0
- actshield/static/traces.html +1 -0
- actshield/static/traces.txt +22 -0
- actshield/static/vercel.svg +1 -0
- actshield/static/window.svg +1 -0
- actshield/tasks/__init__.py +6 -0
- actshield/tasks/task.py +143 -0
- actshield/threatmodel/__init__.py +70 -0
- actshield/threatmodel/actors.py +210 -0
- actshield/threatmodel/analyzer.py +131 -0
- actshield/threatmodel/assets.py +167 -0
- actshield/threatmodel/boundaries.py +165 -0
- actshield/threatmodel/exporters.py +49 -0
- actshield/threatmodel/mitigations.py +209 -0
- actshield/threatmodel/models.py +80 -0
- actshield/threatmodel/report.py +341 -0
- actshield/threatmodel/scenarios.py +212 -0
- actshield/threatmodel/scoring.py +66 -0
- actshield/threatmodel/threats.py +387 -0
- actshield/tools/__init__.py +20 -0
- actshield/tools/interceptor.py +256 -0
- actshield/tools/tool.py +71 -0
- actshield/tracing/__init__.py +38 -0
- actshield/tracing/correlation.py +173 -0
- actshield/tracing/events.py +75 -0
- actshield/tracing/tracer.py +305 -0
- actshield/watch.py +129 -0
- actshield-0.9.0.dist-info/METADATA +57 -0
- actshield-0.9.0.dist-info/RECORD +366 -0
- actshield-0.9.0.dist-info/WHEEL +5 -0
- actshield-0.9.0.dist-info/entry_points.txt +4 -0
- actshield-0.9.0.dist-info/top_level.txt +2 -0
- agentguard/__init__.py +39 -0
- agentguard/__main__.py +8 -0
- agentguard/py.typed +1 -0
actshield/__init__.py
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
"""ActShield: Security Control Plane SDK for Autonomous and Multi-Agent AI Systems.
|
|
2
|
+
|
|
3
|
+
Quick start::
|
|
4
|
+
|
|
5
|
+
from actshield import ActShield
|
|
6
|
+
|
|
7
|
+
guard = ActShield(mode="strict")
|
|
8
|
+
|
|
9
|
+
@guard.protect(tool="customer_db.read", sensitivity="critical")
|
|
10
|
+
async def read_customer_data():
|
|
11
|
+
...
|
|
12
|
+
|
|
13
|
+
# Threat modeling
|
|
14
|
+
from actshield.threatmodel import ThreatAnalyzer
|
|
15
|
+
analyzer = ThreatAnalyzer()
|
|
16
|
+
result = analyzer.analyze()
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from actshield.agents.agent import Agent
|
|
20
|
+
from actshield.agents.identity import AgentCapability, AgentIdentity, AgentStatus, AgentTrustLevel
|
|
21
|
+
from actshield.client import ActShield
|
|
22
|
+
from actshield.config import ActShieldConfig
|
|
23
|
+
from actshield.context.context import Context
|
|
24
|
+
from actshield.context.provenance import ContextSource, ContextTrustLevel, Provenance, ProvenanceHop, SanitizationRecord
|
|
25
|
+
from actshield.context.taint import TaintState
|
|
26
|
+
from actshield.decisions.decision import DecisionAction, SecurityDecision
|
|
27
|
+
from actshield.delegation.authority import AuthorityGrant
|
|
28
|
+
from actshield.delegation.delegation import Delegation, DelegationScope
|
|
29
|
+
from actshield.approval.approval import (
|
|
30
|
+
ApprovalManager,
|
|
31
|
+
ApprovalRequest,
|
|
32
|
+
ApprovalStatus,
|
|
33
|
+
)
|
|
34
|
+
from actshield.gateway.http import HTTPGateway, HTTPInterceptedResponse
|
|
35
|
+
from actshield.gateway.mcp import MCPGateway, MCPMessage
|
|
36
|
+
|
|
37
|
+
from actshield.integrations.ai_secura import (
|
|
38
|
+
AISecuraClient,
|
|
39
|
+
LocalAISecuraAdapter,
|
|
40
|
+
SecurityAnalysis,
|
|
41
|
+
SecurityContext,
|
|
42
|
+
SecurityReasoner,
|
|
43
|
+
)
|
|
44
|
+
from actshield.providers.base import (
|
|
45
|
+
AnalysisResult,
|
|
46
|
+
HealthReport,
|
|
47
|
+
SecurityAIProvider,
|
|
48
|
+
)
|
|
49
|
+
from actshield.providers.registry import (
|
|
50
|
+
ProviderRegistry,
|
|
51
|
+
get_provider_registry,
|
|
52
|
+
)
|
|
53
|
+
from actshield.integrations.ai_secura_analysis import (
|
|
54
|
+
AISecuraAnalysis,
|
|
55
|
+
ThreatSeverity,
|
|
56
|
+
IntentAlignment,
|
|
57
|
+
AIRecommendation,
|
|
58
|
+
AttackTechnique,
|
|
59
|
+
EvidenceTriad,
|
|
60
|
+
AuthorityAnalysis,
|
|
61
|
+
TaintAnalysis,
|
|
62
|
+
)
|
|
63
|
+
from actshield.integrations.ollama_adapter import OllamaAISecuraAdapter
|
|
64
|
+
from actshield.llm_config import LLMConfig
|
|
65
|
+
from actshield.offensive import (
|
|
66
|
+
AttackCase,
|
|
67
|
+
AttackType,
|
|
68
|
+
ExpectedBehavior,
|
|
69
|
+
SafetyClass,
|
|
70
|
+
AttackTarget,
|
|
71
|
+
TargetEnvironment,
|
|
72
|
+
TargetRegistry,
|
|
73
|
+
target_registry,
|
|
74
|
+
SafetyValidationResult,
|
|
75
|
+
SafetyValidator,
|
|
76
|
+
safety_validator,
|
|
77
|
+
AttackStatus,
|
|
78
|
+
ExecutionEvidence,
|
|
79
|
+
OffensiveAttackResult,
|
|
80
|
+
AttackEvaluator,
|
|
81
|
+
MutationEngine,
|
|
82
|
+
MutationStrategy,
|
|
83
|
+
AttackCampaign,
|
|
84
|
+
CampaignSummary,
|
|
85
|
+
AttackCorpus,
|
|
86
|
+
attack_corpus,
|
|
87
|
+
AIAttackGenerator,
|
|
88
|
+
VulnerableDemoTarget,
|
|
89
|
+
OffensiveEngine,
|
|
90
|
+
SecurityAnalysisEvidence,
|
|
91
|
+
AdaptiveEngine,
|
|
92
|
+
CampaignMemory,
|
|
93
|
+
)
|
|
94
|
+
from actshield.integrations.apiris import (
|
|
95
|
+
APIAnalysis,
|
|
96
|
+
APIIntelligence,
|
|
97
|
+
APIRISClient,
|
|
98
|
+
LocalAPIRISAdapter,
|
|
99
|
+
)
|
|
100
|
+
from actshield.persistence.siem import SIEMExporter, SIEMFormat
|
|
101
|
+
from actshield.persistence.storage import (
|
|
102
|
+
PostgresStorage,
|
|
103
|
+
SQLiteStorage,
|
|
104
|
+
StorageBackend,
|
|
105
|
+
)
|
|
106
|
+
from actshield.policy.evaluator import PolicyEvaluator
|
|
107
|
+
from actshield.policy.intent import (
|
|
108
|
+
DeterministicIntentAnalyzer,
|
|
109
|
+
IntentAlignmentResult,
|
|
110
|
+
IntentAlignmentStatus,
|
|
111
|
+
IntentAnalyzer,
|
|
112
|
+
)
|
|
113
|
+
from actshield.policy.policy import Policy, PolicyRule, RuleCondition
|
|
114
|
+
from actshield.risk.models import RiskAssessment, RiskFactorBreakdown, RiskLevel, RiskSignal
|
|
115
|
+
from actshield.tasks.task import Task, TaskContext, TaskStatus
|
|
116
|
+
from actshield.tools.interceptor import protected_tool
|
|
117
|
+
from actshield.tools.tool import (
|
|
118
|
+
Resource,
|
|
119
|
+
SensitivityLevel,
|
|
120
|
+
ToolDefinition,
|
|
121
|
+
ToolRequest,
|
|
122
|
+
ToolResult,
|
|
123
|
+
)
|
|
124
|
+
from actshield.tracing.correlation import (
|
|
125
|
+
CorrelationContext,
|
|
126
|
+
SpanScope,
|
|
127
|
+
generate_id,
|
|
128
|
+
get_current_agent_id,
|
|
129
|
+
get_current_context,
|
|
130
|
+
get_current_delegation_id,
|
|
131
|
+
get_current_span_id,
|
|
132
|
+
get_current_task_id,
|
|
133
|
+
get_current_trace_id,
|
|
134
|
+
)
|
|
135
|
+
from actshield.tracing.events import EventType, SecurityEvent
|
|
136
|
+
from actshield.tracing.tracer import CausalEdge, CausalGraph, CausalNode, TraceManager
|
|
137
|
+
|
|
138
|
+
__version__ = "0.9.0"
|
|
139
|
+
|
|
140
|
+
# Phase 6.5 — Forensic Intelligence + Product API
|
|
141
|
+
from actshield.forensics.service import ForensicService
|
|
142
|
+
from actshield.forensics.queries import ForensicQueryEngine
|
|
143
|
+
from actshield.forensics.models import (
|
|
144
|
+
AgentAccessProfile,
|
|
145
|
+
ResourceAccessProfile,
|
|
146
|
+
AccessAttempt,
|
|
147
|
+
ActualAccess,
|
|
148
|
+
AccessSnapshot,
|
|
149
|
+
AccessDiff,
|
|
150
|
+
ForensicExplanation,
|
|
151
|
+
AttackForensicReport,
|
|
152
|
+
ForensicIncident,
|
|
153
|
+
IncidentType,
|
|
154
|
+
IncidentSeverity,
|
|
155
|
+
AccessMatrix,
|
|
156
|
+
)
|
|
157
|
+
from actshield.api.service import ApiService, SecurityPrincipal
|
|
158
|
+
from actshield.api.models import (
|
|
159
|
+
AgentAccessResponse,
|
|
160
|
+
ResourceAccessResponse,
|
|
161
|
+
AccessMatrixResponse,
|
|
162
|
+
OverviewResponse,
|
|
163
|
+
AttackForensicsResponse,
|
|
164
|
+
IncidentResponse,
|
|
165
|
+
ErrorResponse,
|
|
166
|
+
HealthResponse,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
# Phase 9 — Continuous Security Control Plane
|
|
170
|
+
from actshield.posture import (
|
|
171
|
+
SecurityPostureSnapshot,
|
|
172
|
+
PostureRating,
|
|
173
|
+
FindingSeverity,
|
|
174
|
+
PostureFinding,
|
|
175
|
+
PostureDimensionMetrics,
|
|
176
|
+
PostureDiff,
|
|
177
|
+
PostureEngine,
|
|
178
|
+
PostureDiffEngine,
|
|
179
|
+
PostureRuleEvaluator,
|
|
180
|
+
)
|
|
181
|
+
from actshield.incidents import (
|
|
182
|
+
SecurityIncident,
|
|
183
|
+
IncidentState,
|
|
184
|
+
IncidentStateMachine,
|
|
185
|
+
IncidentTimelineEntry,
|
|
186
|
+
IncidentEngine,
|
|
187
|
+
IncidentCreationRule,
|
|
188
|
+
)
|
|
189
|
+
from actshield.response import (
|
|
190
|
+
ResponseActionType,
|
|
191
|
+
ResponseActionRecord,
|
|
192
|
+
AuthorityChangeEvent,
|
|
193
|
+
ResponseEngine,
|
|
194
|
+
)
|
|
195
|
+
from actshield.drift import (
|
|
196
|
+
DriftCategory,
|
|
197
|
+
DriftSeverity,
|
|
198
|
+
DriftEvent,
|
|
199
|
+
AgentBehaviorBaseline,
|
|
200
|
+
BehavioralBaselineTracker,
|
|
201
|
+
AuthorityDriftDetector,
|
|
202
|
+
AccessDriftDetector,
|
|
203
|
+
ContextDriftDetector,
|
|
204
|
+
)
|
|
205
|
+
from actshield.gates import (
|
|
206
|
+
GateStatus,
|
|
207
|
+
GateCheckRule,
|
|
208
|
+
SecurityGateResult,
|
|
209
|
+
SecurityGateEvaluator,
|
|
210
|
+
security_gate,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# Threat Modeling
|
|
214
|
+
from actshield.threatmodel import (
|
|
215
|
+
ThreatAnalyzer,
|
|
216
|
+
ThreatReportRenderer,
|
|
217
|
+
ThreatModelExporter,
|
|
218
|
+
ThreatModel,
|
|
219
|
+
AnalysisResult as ThreatAnalysisResult,
|
|
220
|
+
ThreatSeverity,
|
|
221
|
+
ThreatCategory,
|
|
222
|
+
Asset,
|
|
223
|
+
AssetSensitivity,
|
|
224
|
+
ThreatActor,
|
|
225
|
+
ActorType,
|
|
226
|
+
TrustBoundary,
|
|
227
|
+
BoundaryType,
|
|
228
|
+
Threat,
|
|
229
|
+
AttackScenario,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
__all__ = [
|
|
233
|
+
"ActShield",
|
|
234
|
+
"ActShieldConfig",
|
|
235
|
+
"Agent",
|
|
236
|
+
"AgentIdentity",
|
|
237
|
+
"AgentCapability",
|
|
238
|
+
"AgentTrustLevel",
|
|
239
|
+
"AgentStatus",
|
|
240
|
+
"Task",
|
|
241
|
+
"TaskContext",
|
|
242
|
+
"TaskStatus",
|
|
243
|
+
"Delegation",
|
|
244
|
+
"DelegationScope",
|
|
245
|
+
"AuthorityGrant",
|
|
246
|
+
"Context",
|
|
247
|
+
"ContextSource",
|
|
248
|
+
"ContextTrustLevel",
|
|
249
|
+
"Provenance",
|
|
250
|
+
"ProvenanceHop",
|
|
251
|
+
"SanitizationRecord",
|
|
252
|
+
"TaintState",
|
|
253
|
+
"ToolDefinition",
|
|
254
|
+
"Resource",
|
|
255
|
+
"SensitivityLevel",
|
|
256
|
+
"ToolRequest",
|
|
257
|
+
"ToolResult",
|
|
258
|
+
"protected_tool",
|
|
259
|
+
"Policy",
|
|
260
|
+
"PolicyRule",
|
|
261
|
+
"RuleCondition",
|
|
262
|
+
"PolicyEvaluator",
|
|
263
|
+
"IntentAnalyzer",
|
|
264
|
+
"DeterministicIntentAnalyzer",
|
|
265
|
+
"IntentAlignmentStatus",
|
|
266
|
+
"IntentAlignmentResult",
|
|
267
|
+
"RiskLevel",
|
|
268
|
+
"RiskSignal",
|
|
269
|
+
"RiskAssessment",
|
|
270
|
+
"RiskFactorBreakdown",
|
|
271
|
+
"DecisionAction",
|
|
272
|
+
"SecurityDecision",
|
|
273
|
+
"EventType",
|
|
274
|
+
"SecurityEvent",
|
|
275
|
+
"CorrelationContext",
|
|
276
|
+
"SpanScope",
|
|
277
|
+
"generate_id",
|
|
278
|
+
"get_current_context",
|
|
279
|
+
"get_current_trace_id",
|
|
280
|
+
"get_current_span_id",
|
|
281
|
+
"get_current_agent_id",
|
|
282
|
+
"get_current_task_id",
|
|
283
|
+
"get_current_delegation_id",
|
|
284
|
+
"CausalNode",
|
|
285
|
+
"CausalEdge",
|
|
286
|
+
"CausalGraph",
|
|
287
|
+
"TraceManager",
|
|
288
|
+
"SecurityReasoner",
|
|
289
|
+
"SecurityContext",
|
|
290
|
+
"SecurityAnalysis",
|
|
291
|
+
"SecurityAIProvider",
|
|
292
|
+
"AnalysisResult",
|
|
293
|
+
"HealthReport",
|
|
294
|
+
"ProviderRegistry",
|
|
295
|
+
"get_provider_registry",
|
|
296
|
+
"AISecuraClient",
|
|
297
|
+
"LocalAISecuraAdapter",
|
|
298
|
+
"APIIntelligence",
|
|
299
|
+
"APIAnalysis",
|
|
300
|
+
"APIRISClient",
|
|
301
|
+
"LocalAPIRISAdapter",
|
|
302
|
+
"MCPGateway",
|
|
303
|
+
"MCPMessage",
|
|
304
|
+
"HTTPGateway",
|
|
305
|
+
"HTTPInterceptedResponse",
|
|
306
|
+
"ApprovalManager",
|
|
307
|
+
"ApprovalRequest",
|
|
308
|
+
"ApprovalStatus",
|
|
309
|
+
"StorageBackend",
|
|
310
|
+
"SQLiteStorage",
|
|
311
|
+
"PostgresStorage",
|
|
312
|
+
"SIEMExporter",
|
|
313
|
+
"SIEMFormat",
|
|
314
|
+
"OllamaAISecuraAdapter",
|
|
315
|
+
"AISecuraAnalysis",
|
|
316
|
+
"ThreatSeverity",
|
|
317
|
+
"IntentAlignment",
|
|
318
|
+
"AIRecommendation",
|
|
319
|
+
"AttackTechnique",
|
|
320
|
+
"EvidenceTriad",
|
|
321
|
+
"AuthorityAnalysis",
|
|
322
|
+
"LLMConfig",
|
|
323
|
+
# Phase 4 Offensive Validation Engine
|
|
324
|
+
"AttackCase",
|
|
325
|
+
"AttackType",
|
|
326
|
+
"ExpectedBehavior",
|
|
327
|
+
"SafetyClass",
|
|
328
|
+
"AttackTarget",
|
|
329
|
+
"TargetEnvironment",
|
|
330
|
+
"TargetRegistry",
|
|
331
|
+
"target_registry",
|
|
332
|
+
"SafetyValidator",
|
|
333
|
+
"SafetyValidationResult",
|
|
334
|
+
"safety_validator",
|
|
335
|
+
"AttackStatus",
|
|
336
|
+
"ExecutionEvidence",
|
|
337
|
+
"OffensiveAttackResult",
|
|
338
|
+
"AttackEvaluator",
|
|
339
|
+
"MutationEngine",
|
|
340
|
+
"MutationStrategy",
|
|
341
|
+
"AttackCampaign",
|
|
342
|
+
"CampaignSummary",
|
|
343
|
+
"AttackCorpus",
|
|
344
|
+
"attack_corpus",
|
|
345
|
+
"AIAttackGenerator",
|
|
346
|
+
"VulnerableDemoTarget",
|
|
347
|
+
"OffensiveEngine",
|
|
348
|
+
# Phase 5 Adaptive Offensive Security Validation
|
|
349
|
+
"SecurityAnalysisEvidence",
|
|
350
|
+
"AdaptiveEngine",
|
|
351
|
+
"CampaignMemory",
|
|
352
|
+
# Phase 6.5 — Forensic Intelligence + Product API
|
|
353
|
+
"ForensicService",
|
|
354
|
+
"ForensicQueryEngine",
|
|
355
|
+
"AgentAccessProfile",
|
|
356
|
+
"ResourceAccessProfile",
|
|
357
|
+
"AccessAttempt",
|
|
358
|
+
"ActualAccess",
|
|
359
|
+
"AccessSnapshot",
|
|
360
|
+
"AccessDiff",
|
|
361
|
+
"ForensicExplanation",
|
|
362
|
+
"AttackForensicReport",
|
|
363
|
+
"ForensicIncident",
|
|
364
|
+
"IncidentType",
|
|
365
|
+
"IncidentSeverity",
|
|
366
|
+
"AccessMatrix",
|
|
367
|
+
"ApiService",
|
|
368
|
+
"SecurityPrincipal",
|
|
369
|
+
"AgentAccessResponse",
|
|
370
|
+
"ResourceAccessResponse",
|
|
371
|
+
"AccessMatrixResponse",
|
|
372
|
+
"OverviewResponse",
|
|
373
|
+
"AttackForensicsResponse",
|
|
374
|
+
"IncidentResponse",
|
|
375
|
+
"ErrorResponse",
|
|
376
|
+
"HealthResponse",
|
|
377
|
+
# Phase 9 — Continuous Security Control Plane
|
|
378
|
+
"SecurityPostureSnapshot",
|
|
379
|
+
"PostureRating",
|
|
380
|
+
"FindingSeverity",
|
|
381
|
+
"PostureFinding",
|
|
382
|
+
"PostureDimensionMetrics",
|
|
383
|
+
"PostureDiff",
|
|
384
|
+
"PostureEngine",
|
|
385
|
+
"PostureDiffEngine",
|
|
386
|
+
"PostureRuleEvaluator",
|
|
387
|
+
"SecurityIncident",
|
|
388
|
+
"IncidentState",
|
|
389
|
+
"IncidentStateMachine",
|
|
390
|
+
"IncidentTimelineEntry",
|
|
391
|
+
"IncidentEngine",
|
|
392
|
+
"IncidentCreationRule",
|
|
393
|
+
"ResponseActionType",
|
|
394
|
+
"ResponseActionRecord",
|
|
395
|
+
"AuthorityChangeEvent",
|
|
396
|
+
"ResponseEngine",
|
|
397
|
+
"DriftCategory",
|
|
398
|
+
"DriftSeverity",
|
|
399
|
+
"DriftEvent",
|
|
400
|
+
"AgentBehaviorBaseline",
|
|
401
|
+
"BehavioralBaselineTracker",
|
|
402
|
+
"AuthorityDriftDetector",
|
|
403
|
+
"AccessDriftDetector",
|
|
404
|
+
"ContextDriftDetector",
|
|
405
|
+
"GateStatus",
|
|
406
|
+
"GateCheckRule",
|
|
407
|
+
"SecurityGateResult",
|
|
408
|
+
"SecurityGateEvaluator",
|
|
409
|
+
"security_gate",
|
|
410
|
+
# Threat Modeling
|
|
411
|
+
"ThreatAnalyzer",
|
|
412
|
+
"ThreatReportRenderer",
|
|
413
|
+
"ThreatModelExporter",
|
|
414
|
+
"ThreatModel",
|
|
415
|
+
"ThreatAnalysisResult",
|
|
416
|
+
"ThreatSeverity",
|
|
417
|
+
"ThreatCategory",
|
|
418
|
+
"Asset",
|
|
419
|
+
"AssetSensitivity",
|
|
420
|
+
"ThreatActor",
|
|
421
|
+
"ActorType",
|
|
422
|
+
"TrustBoundary",
|
|
423
|
+
"BoundaryType",
|
|
424
|
+
"Threat",
|
|
425
|
+
"AttackScenario",
|
|
426
|
+
# Backward Compatibility Aliases
|
|
427
|
+
"AgentGuard",
|
|
428
|
+
"AgentGuardConfig",
|
|
429
|
+
]
|
|
430
|
+
|
|
431
|
+
# Backward compatibility aliases
|
|
432
|
+
AgentGuard = ActShield
|
|
433
|
+
AgentGuardConfig = ActShieldConfig
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
actshield/__main__.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""ActShield package __main__ entrypoint."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, Optional
|
|
5
|
+
from actshield.cli.main import app, main
|
|
6
|
+
from actshield.offensive import attack_corpus, OffensiveEngine
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def cli_attack_list() -> int:
|
|
10
|
+
"""Compatibility handler for Phase 4 test suite."""
|
|
11
|
+
attacks = attack_corpus.get_all_attacks()
|
|
12
|
+
return 0 if len(attacks) > 0 else 1
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def cli_attack_run(args: Any) -> int:
|
|
16
|
+
"""Compatibility handler for running attack cases."""
|
|
17
|
+
engine = OffensiveEngine()
|
|
18
|
+
limit = getattr(args, "limit", 5) or 5
|
|
19
|
+
atype = getattr(args, "type", None)
|
|
20
|
+
attacks = attack_corpus.get_all_attacks()
|
|
21
|
+
if atype:
|
|
22
|
+
attacks = [c for c in attacks if c.attack_type.value == atype or c.attack_type == atype]
|
|
23
|
+
attacks = attacks[:limit]
|
|
24
|
+
for c in attacks:
|
|
25
|
+
engine.execute_attack(c)
|
|
26
|
+
return 0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def cli_attack_replay(attack_id: str) -> int:
|
|
30
|
+
"""Compatibility handler for attack replay."""
|
|
31
|
+
engine = OffensiveEngine()
|
|
32
|
+
case = attack_corpus.get_attack(attack_id)
|
|
33
|
+
if case:
|
|
34
|
+
engine.execute_attack(case)
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def cli_attack_report() -> int:
|
|
39
|
+
"""Compatibility handler for attack reporting."""
|
|
40
|
+
return 0
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
main()
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Agents package exposing Agent, AgentIdentity, AgentCapability, and AgentTrustLevel."""
|
|
2
|
+
|
|
3
|
+
from actshield.agents.agent import Agent
|
|
4
|
+
from actshield.agents.identity import AgentCapability, AgentIdentity, AgentTrustLevel
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"Agent",
|
|
8
|
+
"AgentIdentity",
|
|
9
|
+
"AgentCapability",
|
|
10
|
+
"AgentTrustLevel",
|
|
11
|
+
]
|
|
12
|
+
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Agent runtime instance and orchestration interface."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
import inspect
|
|
6
|
+
from actshield.agents.identity import AgentCapability, AgentIdentity, AgentStatus, AgentTrustLevel
|
|
7
|
+
from actshield.tracing.events import EventType
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from actshield.client import ActShield
|
|
11
|
+
from actshield.delegation.delegation import DelegationScope
|
|
12
|
+
from actshield.tracing.correlation import SpanScope
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Agent:
|
|
16
|
+
"""Represents a registered AI Agent within the ActShield platform."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, identity: AgentIdentity, guard: Optional["ActShield"] = None) -> None:
|
|
19
|
+
self.identity = identity
|
|
20
|
+
self.guard = guard
|
|
21
|
+
now_iso = datetime.now(timezone.utc).isoformat()
|
|
22
|
+
if not self.identity.created_at:
|
|
23
|
+
self.identity.created_at = now_iso
|
|
24
|
+
if not self.identity.last_seen:
|
|
25
|
+
self.identity.last_seen = now_iso
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def agent_id(self) -> str:
|
|
29
|
+
return self.identity.agent_id
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def name(self) -> str:
|
|
33
|
+
return self.identity.name
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def framework(self) -> str:
|
|
37
|
+
return self.identity.framework
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def version(self) -> str:
|
|
41
|
+
return self.identity.version
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def status(self) -> AgentStatus:
|
|
45
|
+
return self.identity.status
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def trust_level(self) -> AgentTrustLevel:
|
|
49
|
+
return self.identity.trust_level
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def capabilities(self) -> List[AgentCapability]:
|
|
53
|
+
return self.identity.capabilities
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def parent_agent_id(self) -> Optional[str]:
|
|
57
|
+
return self.identity.parent_agent_id
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def current_task(self) -> Optional[str]:
|
|
61
|
+
return self.identity.current_task
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def owner_context(self) -> Optional[str]:
|
|
65
|
+
return self.identity.owner_context
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def created_at(self) -> Optional[str]:
|
|
69
|
+
return self.identity.created_at
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def last_seen(self) -> Optional[str]:
|
|
73
|
+
return self.identity.last_seen
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def metadata(self) -> Dict[str, Any]:
|
|
77
|
+
return self.identity.metadata
|
|
78
|
+
|
|
79
|
+
def set_status(self, status: Union[str, AgentStatus]) -> None:
|
|
80
|
+
"""Update agent operational status."""
|
|
81
|
+
if isinstance(status, str):
|
|
82
|
+
status = AgentStatus(status.lower())
|
|
83
|
+
self.identity.status = status
|
|
84
|
+
self.touch()
|
|
85
|
+
if self.guard:
|
|
86
|
+
self.guard.emit_event(
|
|
87
|
+
event_type=EventType.SECURITY_ALERT,
|
|
88
|
+
agent_id=self.agent_id,
|
|
89
|
+
payload={"action": "agent_status_change", "status": status.value},
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def touch(self) -> None:
|
|
93
|
+
"""Update last seen timestamp."""
|
|
94
|
+
self.identity.last_seen = datetime.now(timezone.utc).isoformat()
|
|
95
|
+
|
|
96
|
+
def set_task(self, task_name_or_id: Optional[str]) -> None:
|
|
97
|
+
"""Set active task."""
|
|
98
|
+
self.identity.current_task = task_name_or_id
|
|
99
|
+
self.touch()
|
|
100
|
+
|
|
101
|
+
def has_capability(self, capability_name: str) -> bool:
|
|
102
|
+
"""Check if this agent holds the specified capability."""
|
|
103
|
+
return self.identity.has_capability(capability_name)
|
|
104
|
+
|
|
105
|
+
def capability_names(self) -> List[str]:
|
|
106
|
+
"""Return list of declared capability names."""
|
|
107
|
+
return self.identity.capability_names()
|
|
108
|
+
|
|
109
|
+
def delegate(
|
|
110
|
+
self,
|
|
111
|
+
delegate: Optional["Agent"] = None,
|
|
112
|
+
capabilities: Optional[List[Union[str, AgentCapability]]] = None,
|
|
113
|
+
constraints: Optional[Dict[str, Any]] = None,
|
|
114
|
+
to_agent: Optional["Agent"] = None,
|
|
115
|
+
) -> "DelegationScope":
|
|
116
|
+
"""Delegate a subset of authority/capabilities to a target agent within a scoped context."""
|
|
117
|
+
target = delegate or to_agent
|
|
118
|
+
if target is None:
|
|
119
|
+
raise ValueError("Target delegate agent must be provided to delegate().")
|
|
120
|
+
if self.guard is None:
|
|
121
|
+
raise RuntimeError("Agent is not attached to an ActShield instance.")
|
|
122
|
+
|
|
123
|
+
self.touch()
|
|
124
|
+
return self.guard._create_delegation_scope(
|
|
125
|
+
delegator=self,
|
|
126
|
+
delegate=target,
|
|
127
|
+
capabilities=capabilities,
|
|
128
|
+
constraints=constraints,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
def invoke(self, fn: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
|
|
132
|
+
"""Invoke a synchronous function within this agent's execution context."""
|
|
133
|
+
self.touch()
|
|
134
|
+
if self.guard is None:
|
|
135
|
+
return fn(*args, **kwargs)
|
|
136
|
+
|
|
137
|
+
with self.guard.span(name=f"agent_invoke:{self.name}", agent_id=self.agent_id):
|
|
138
|
+
self.guard.emit_event(
|
|
139
|
+
event_type=EventType.AGENT_INVOKED,
|
|
140
|
+
agent_id=self.agent_id,
|
|
141
|
+
payload={
|
|
142
|
+
"agent_name": self.name,
|
|
143
|
+
"function": getattr(fn, "__name__", str(fn)),
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
return fn(*args, **kwargs)
|
|
147
|
+
|
|
148
|
+
async def ainvoke(self, fn: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
|
|
149
|
+
"""Invoke an asynchronous function within this agent's execution context."""
|
|
150
|
+
self.touch()
|
|
151
|
+
if self.guard is None:
|
|
152
|
+
if inspect.iscoroutinefunction(fn):
|
|
153
|
+
return await fn(*args, **kwargs)
|
|
154
|
+
return fn(*args, **kwargs)
|
|
155
|
+
|
|
156
|
+
with self.guard.span(name=f"agent_ainvoke:{self.name}", agent_id=self.agent_id):
|
|
157
|
+
self.guard.emit_event(
|
|
158
|
+
event_type=EventType.AGENT_INVOKED,
|
|
159
|
+
agent_id=self.agent_id,
|
|
160
|
+
payload={
|
|
161
|
+
"agent_name": self.name,
|
|
162
|
+
"function": getattr(fn, "__name__", str(fn)),
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
if inspect.iscoroutinefunction(fn):
|
|
166
|
+
return await fn(*args, **kwargs)
|
|
167
|
+
return fn(*args, **kwargs)
|
|
168
|
+
|
|
169
|
+
def __call__(self, fn: Callable[..., Any]) -> Callable[..., Any]:
|
|
170
|
+
"""Allow Agent instance to be used directly as a decorator."""
|
|
171
|
+
import functools
|
|
172
|
+
@functools.wraps(fn)
|
|
173
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
174
|
+
if self.guard:
|
|
175
|
+
with self.guard.agent_context(self.agent_id):
|
|
176
|
+
if inspect.iscoroutinefunction(fn):
|
|
177
|
+
return self.ainvoke(fn, *args, **kwargs)
|
|
178
|
+
return self.invoke(fn, *args, **kwargs)
|
|
179
|
+
else:
|
|
180
|
+
if inspect.iscoroutinefunction(fn):
|
|
181
|
+
return fn(*args, **kwargs)
|
|
182
|
+
return fn(*args, **kwargs)
|
|
183
|
+
wrapper.agent = self # type: ignore
|
|
184
|
+
return wrapper
|
|
185
|
+
|
|
186
|
+
def __enter__(self) -> "Agent":
|
|
187
|
+
if self.guard:
|
|
188
|
+
self._scope = self.guard.span(name=f"agent_scope:{self.name}", agent_id=self.agent_id)
|
|
189
|
+
self._scope.__enter__()
|
|
190
|
+
self.touch()
|
|
191
|
+
return self
|
|
192
|
+
|
|
193
|
+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
194
|
+
if hasattr(self, "_scope") and self._scope:
|
|
195
|
+
self._scope.__exit__(exc_type, exc_val, exc_tb)
|
|
196
|
+
|
|
197
|
+
def __repr__(self) -> str:
|
|
198
|
+
return f"<Agent id='{self.agent_id}' name='{self.name}' status='{self.status.value}' trust='{self.trust_level.value}'>"
|
|
199
|
+
|
|
200
|
+
|