agentmesh-platform 1.0.0a1__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.
agentmesh/__init__.py ADDED
@@ -0,0 +1,119 @@
1
+ """
2
+ AgentMesh - The Secure Nervous System for Cloud-Native Agent Ecosystems
3
+
4
+ Identity ยท Trust ยท Reward ยท Governance
5
+
6
+ AgentMesh is the platform built for the Governed Agent Mesh - the cloud-native,
7
+ multi-vendor network of AI agents that will define enterprise operations.
8
+
9
+ Version: 1.0.0-alpha
10
+ """
11
+
12
+ __version__ = "1.0.0-alpha"
13
+
14
+ # Layer 1: Identity & Zero-Trust Core
15
+ from .identity import (
16
+ AgentIdentity,
17
+ AgentDID,
18
+ IdentityRegistry,
19
+ Credential,
20
+ CredentialManager,
21
+ DelegationChain,
22
+ DelegationLink,
23
+ HumanSponsor,
24
+ SponsorRegistry,
25
+ RiskScorer,
26
+ RiskScore,
27
+ SPIFFEIdentity,
28
+ )
29
+
30
+ # Layer 2: Trust & Protocol Bridge
31
+ from .trust import (
32
+ TrustBridge,
33
+ ProtocolBridge,
34
+ A2AAdapter,
35
+ MCPAdapter,
36
+ TrustHandshake,
37
+ HandshakeResult,
38
+ CapabilityScope,
39
+ CapabilityGrant,
40
+ CapabilityRegistry,
41
+ )
42
+
43
+ # Layer 3: Governance & Compliance Plane
44
+ from .governance import (
45
+ PolicyEngine,
46
+ Policy,
47
+ PolicyRule,
48
+ PolicyResult,
49
+ ComplianceEngine,
50
+ ComplianceFramework,
51
+ ComplianceControl,
52
+ AuditLog,
53
+ AuditEntry,
54
+ MerkleAuditChain,
55
+ ShadowMode,
56
+ ShadowResult,
57
+ )
58
+
59
+ # Layer 4: Reward & Learning Engine
60
+ from .reward import (
61
+ RewardEngine,
62
+ TrustScore,
63
+ RewardDimension,
64
+ RewardSignal,
65
+ AdaptiveLearner,
66
+ WeightOptimizer,
67
+ )
68
+
69
+ __all__ = [
70
+ # Version
71
+ "__version__",
72
+
73
+ # Layer 1: Identity
74
+ "AgentIdentity",
75
+ "AgentDID",
76
+ "IdentityRegistry",
77
+ "Credential",
78
+ "CredentialManager",
79
+ "DelegationChain",
80
+ "DelegationLink",
81
+ "HumanSponsor",
82
+ "SponsorRegistry",
83
+ "RiskScorer",
84
+ "RiskScore",
85
+ "SPIFFEIdentity",
86
+
87
+ # Layer 2: Trust
88
+ "TrustBridge",
89
+ "ProtocolBridge",
90
+ "A2AAdapter",
91
+ "MCPAdapter",
92
+ "TrustHandshake",
93
+ "HandshakeResult",
94
+ "CapabilityScope",
95
+ "CapabilityGrant",
96
+ "CapabilityRegistry",
97
+
98
+ # Layer 3: Governance
99
+ "PolicyEngine",
100
+ "Policy",
101
+ "PolicyRule",
102
+ "PolicyResult",
103
+ "ComplianceEngine",
104
+ "ComplianceFramework",
105
+ "ComplianceControl",
106
+ "AuditLog",
107
+ "AuditEntry",
108
+ "MerkleAuditChain",
109
+ "ShadowMode",
110
+ "ShadowResult",
111
+
112
+ # Layer 4: Reward
113
+ "RewardEngine",
114
+ "TrustScore",
115
+ "RewardDimension",
116
+ "RewardSignal",
117
+ "AdaptiveLearner",
118
+ "WeightOptimizer",
119
+ ]
@@ -0,0 +1,10 @@
1
+ """
2
+ AgentMesh CLI
3
+
4
+ Command-line interface for AgentMesh.
5
+ Single CLI command: agentmesh init โ€” scaffolds a governed agent in 30 seconds.
6
+ """
7
+
8
+ from .main import app, main
9
+
10
+ __all__ = ["app", "main"]
agentmesh/cli/main.py ADDED
@@ -0,0 +1,405 @@
1
+ """
2
+ AgentMesh CLI - Main Entry Point
3
+
4
+ Commands:
5
+ - init: Scaffold a governed agent in 30 seconds
6
+ - register: Register an agent with AgentMesh
7
+ - run: Run a governed agent
8
+ - status: Check agent status and trust score
9
+ - audit: View audit logs
10
+ - policy: Manage policies
11
+ """
12
+
13
+ import click
14
+ from rich.console import Console
15
+ from rich.table import Table
16
+ from rich.panel import Panel
17
+ from rich import box
18
+ from pathlib import Path
19
+ import json
20
+ import yaml
21
+ import os
22
+
23
+ console = Console()
24
+
25
+
26
+ @click.group()
27
+ @click.version_option(version="1.0.0-alpha")
28
+ def app():
29
+ """
30
+ AgentMesh - The Secure Nervous System for Cloud-Native Agent Ecosystems
31
+
32
+ Identity ยท Trust ยท Reward ยท Governance
33
+ """
34
+ pass
35
+
36
+
37
+ @app.command()
38
+ @click.option("--name", "-n", prompt="Agent name", help="Name of the agent")
39
+ @click.option("--sponsor", "-s", prompt="Sponsor email", help="Human sponsor email")
40
+ @click.option("--output", "-o", default=".", help="Output directory")
41
+ def init(name: str, sponsor: str, output: str):
42
+ """
43
+ Initialize a new governed agent in 30 seconds.
44
+
45
+ Creates the scaffolding for a governed agent with identity, trust, and audit built in.
46
+ """
47
+ output_path = Path(output)
48
+ agent_dir = output_path / name
49
+
50
+ console.print(f"\n[bold blue]๐Ÿš€ Initializing governed agent: {name}[/bold blue]\n")
51
+
52
+ # Create directory structure
53
+ dirs = [
54
+ agent_dir,
55
+ agent_dir / "src",
56
+ agent_dir / "policies",
57
+ agent_dir / "tests",
58
+ ]
59
+
60
+ for d in dirs:
61
+ d.mkdir(parents=True, exist_ok=True)
62
+ console.print(f" [green]โœ“[/green] Created {d}")
63
+
64
+ # Create agent manifest
65
+ manifest = {
66
+ "agent": {
67
+ "name": name,
68
+ "version": "0.1.0",
69
+ "did": f"did:agentmesh:{name}",
70
+ },
71
+ "sponsor": {
72
+ "email": sponsor,
73
+ },
74
+ "identity": {
75
+ "ttl_minutes": 15,
76
+ "auto_rotate": True,
77
+ },
78
+ "trust": {
79
+ "protocols": ["a2a", "mcp", "iatp"],
80
+ "min_peer_score": 500,
81
+ },
82
+ "governance": {
83
+ "policies_dir": "policies/",
84
+ "audit_enabled": True,
85
+ },
86
+ "reward": {
87
+ "dimensions": {
88
+ "policy_compliance": 0.25,
89
+ "resource_efficiency": 0.15,
90
+ "output_quality": 0.20,
91
+ "security_posture": 0.25,
92
+ "collaboration_health": 0.15,
93
+ },
94
+ },
95
+ }
96
+
97
+ manifest_path = agent_dir / "agentmesh.yaml"
98
+ with open(manifest_path, "w") as f:
99
+ yaml.dump(manifest, f, default_flow_style=False)
100
+ console.print(f" [green]โœ“[/green] Created {manifest_path}")
101
+
102
+ # Create default policy
103
+ default_policy = {
104
+ "policies": [
105
+ {
106
+ "id": "default-security",
107
+ "name": "Default Security Policy",
108
+ "enabled": True,
109
+ "rules": [
110
+ {
111
+ "id": "no-secrets-in-output",
112
+ "action": "block",
113
+ "conditions": [
114
+ "output contains 'password'",
115
+ "output contains 'api_key'",
116
+ "output contains 'secret'",
117
+ ],
118
+ "message": "Potential secret detected in output",
119
+ },
120
+ {
121
+ "id": "require-peer-trust",
122
+ "action": "block",
123
+ "conditions": ["peer_trust_score < 500"],
124
+ "message": "Peer trust score below threshold",
125
+ },
126
+ ],
127
+ }
128
+ ]
129
+ }
130
+
131
+ policy_path = agent_dir / "policies" / "default.yaml"
132
+ with open(policy_path, "w") as f:
133
+ yaml.dump(default_policy, f, default_flow_style=False)
134
+ console.print(f" [green]โœ“[/green] Created {policy_path}")
135
+
136
+ # Create main agent file
137
+ agent_code = f'''"""
138
+ {name} - A Governed Agent
139
+
140
+ This agent is secured by AgentMesh with:
141
+ - Cryptographic identity
142
+ - Trust scoring
143
+ - Policy enforcement
144
+ - Audit logging
145
+ """
146
+
147
+ from agentmesh import AgentMesh, AgentIdentity, PolicyEngine
148
+
149
+ # Initialize AgentMesh
150
+ mesh = AgentMesh.from_config("agentmesh.yaml")
151
+
152
+ # Create identity
153
+ identity = mesh.create_identity()
154
+ print(f"Agent DID: {{identity.did}}")
155
+
156
+ # Load policies
157
+ policies = mesh.load_policies()
158
+ print(f"Loaded {{len(policies)}} policies")
159
+
160
+ # Start the agent
161
+ async def main():
162
+ """Main agent loop."""
163
+ async with mesh.run(identity) as agent:
164
+ # Your agent logic here
165
+ print(f"Agent {{identity.name}} is running with trust score: {{agent.trust_score}}")
166
+
167
+ # Example: Register capabilities
168
+ await agent.register_capabilities([
169
+ "text_processing",
170
+ "data_analysis",
171
+ ])
172
+
173
+ # Example: Handle incoming requests
174
+ async for request in agent.requests():
175
+ # Policy is automatically enforced
176
+ # Audit is automatically logged
177
+ response = await agent.process(request)
178
+ await agent.respond(response)
179
+
180
+
181
+ if __name__ == "__main__":
182
+ import asyncio
183
+ asyncio.run(main())
184
+ '''
185
+
186
+ main_path = agent_dir / "src" / "main.py"
187
+ with open(main_path, "w") as f:
188
+ f.write(agent_code)
189
+ console.print(f" [green]โœ“[/green] Created {main_path}")
190
+
191
+ # Create pyproject.toml
192
+ pyproject = f'''[project]
193
+ name = "{name}"
194
+ version = "0.1.0"
195
+ description = "A governed agent secured by AgentMesh"
196
+ requires-python = ">=3.11"
197
+ dependencies = [
198
+ "agentmesh>=1.0.0",
199
+ ]
200
+
201
+ [build-system]
202
+ requires = ["hatchling"]
203
+ build-backend = "hatchling.build"
204
+ '''
205
+
206
+ pyproject_path = agent_dir / "pyproject.toml"
207
+ with open(pyproject_path, "w") as f:
208
+ f.write(pyproject)
209
+ console.print(f" [green]โœ“[/green] Created {pyproject_path}")
210
+
211
+ # Summary
212
+ console.print()
213
+ console.print(Panel(
214
+ f"""[bold green]Agent initialized successfully![/bold green]
215
+
216
+ [bold]Next steps:[/bold]
217
+ 1. cd {agent_dir}
218
+ 2. pip install -e .
219
+ 3. python src/main.py
220
+
221
+ [bold]Configuration:[/bold]
222
+ - Edit agentmesh.yaml for agent settings
223
+ - Add policies to policies/ directory
224
+ - Customize src/main.py with your agent logic
225
+
226
+ [bold]Security:[/bold]
227
+ - Identity TTL: 15 minutes (auto-rotate)
228
+ - Min peer trust score: 500
229
+ - Audit logging: enabled""",
230
+ title="๐Ÿ›ก๏ธ AgentMesh",
231
+ border_style="green",
232
+ ))
233
+
234
+
235
+ @app.command()
236
+ @click.argument("agent_dir", type=click.Path(exists=True))
237
+ @click.option("--name", "-n", help="Override agent name")
238
+ def register(agent_dir: str, name: str = None):
239
+ """Register an agent with AgentMesh."""
240
+ agent_path = Path(agent_dir)
241
+ manifest_path = agent_path / "agentmesh.yaml"
242
+
243
+ if not manifest_path.exists():
244
+ console.print("[red]Error: agentmesh.yaml not found. Run 'agentmesh init' first.[/red]")
245
+ return
246
+
247
+ with open(manifest_path) as f:
248
+ manifest = yaml.safe_load(f)
249
+
250
+ agent_name = name or manifest["agent"]["name"]
251
+
252
+ console.print(f"\n[bold blue]๐Ÿ“ Registering agent: {agent_name}[/bold blue]\n")
253
+
254
+ # Simulate registration
255
+ from agentmesh.identity import AgentIdentity
256
+ identity = AgentIdentity.create(agent_name)
257
+
258
+ console.print(f" [green]โœ“[/green] Generated identity: {identity.did}")
259
+ console.print(f" [green]โœ“[/green] Public key: {identity.public_key[:32]}...")
260
+ console.print(f" [green]โœ“[/green] Registered with AgentMesh CA")
261
+ console.print()
262
+
263
+ # Save identity
264
+ identity_file = agent_path / ".agentmesh" / "identity.json"
265
+ identity_file.parent.mkdir(parents=True, exist_ok=True)
266
+
267
+ with open(identity_file, "w") as f:
268
+ json.dump({
269
+ "did": identity.did,
270
+ "public_key": identity.public_key,
271
+ "created_at": identity.created_at.isoformat(),
272
+ }, f, indent=2)
273
+
274
+ console.print(f"[green]Identity saved to {identity_file}[/green]")
275
+
276
+
277
+ @app.command()
278
+ @click.argument("agent_dir", type=click.Path(exists=True), default=".")
279
+ def status(agent_dir: str):
280
+ """Check agent status and trust score."""
281
+ agent_path = Path(agent_dir)
282
+ manifest_path = agent_path / "agentmesh.yaml"
283
+ identity_path = agent_path / ".agentmesh" / "identity.json"
284
+
285
+ console.print(f"\n[bold blue]๐Ÿ“Š Agent Status[/bold blue]\n")
286
+
287
+ # Load manifest
288
+ if manifest_path.exists():
289
+ with open(manifest_path) as f:
290
+ manifest = yaml.safe_load(f)
291
+
292
+ console.print(f" Agent: [bold]{manifest['agent']['name']}[/bold]")
293
+ console.print(f" Version: {manifest['agent']['version']}")
294
+ console.print(f" Sponsor: {manifest['sponsor']['email']}")
295
+ else:
296
+ console.print(" [yellow]No manifest found[/yellow]")
297
+
298
+ console.print()
299
+
300
+ # Load identity
301
+ if identity_path.exists():
302
+ with open(identity_path) as f:
303
+ identity = json.load(f)
304
+
305
+ console.print(f" [green]โœ“[/green] Identity: Registered")
306
+ console.print(f" DID: {identity['did']}")
307
+ else:
308
+ console.print(f" [yellow]โ—‹[/yellow] Identity: Not registered")
309
+
310
+ console.print()
311
+
312
+ # Trust score (simulated)
313
+ table = Table(title="Trust Score", box=box.ROUNDED)
314
+ table.add_column("Dimension", style="cyan")
315
+ table.add_column("Score", justify="right")
316
+ table.add_column("Trend")
317
+
318
+ table.add_row("Policy Compliance", "85/100", "[green]โ†‘[/green]")
319
+ table.add_row("Resource Efficiency", "72/100", "[white]โ†’[/white]")
320
+ table.add_row("Output Quality", "91/100", "[green]โ†‘[/green]")
321
+ table.add_row("Security Posture", "88/100", "[white]โ†’[/white]")
322
+ table.add_row("Collaboration Health", "79/100", "[green]โ†‘[/green]")
323
+ table.add_row("[bold]Total", "[bold]820/1000", "[bold green]Trusted")
324
+
325
+ console.print(table)
326
+
327
+
328
+ @app.command()
329
+ @click.argument("policy_file", type=click.Path(exists=True))
330
+ @click.option("--validate", is_flag=True, help="Validate policy only")
331
+ def policy(policy_file: str, validate: bool):
332
+ """Load and validate a policy file."""
333
+ console.print(f"\n[bold blue]๐Ÿ“œ Policy: {policy_file}[/bold blue]\n")
334
+
335
+ try:
336
+ with open(policy_file) as f:
337
+ if policy_file.endswith(".yaml") or policy_file.endswith(".yml"):
338
+ policy_data = yaml.safe_load(f)
339
+ else:
340
+ policy_data = json.load(f)
341
+
342
+ from agentmesh.governance import PolicyEngine
343
+ engine = PolicyEngine()
344
+
345
+ policies = policy_data.get("policies", [])
346
+ for p in policies:
347
+ engine.load_policy(p)
348
+ console.print(f" [green]โœ“[/green] Loaded: {p['name']} ({len(p.get('rules', []))} rules)")
349
+
350
+ console.print(f"\n[green]Successfully loaded {len(policies)} policies[/green]")
351
+
352
+ except Exception as e:
353
+ console.print(f"[red]Error: {e}[/red]")
354
+
355
+
356
+ @app.command()
357
+ @click.option("--agent", "-a", help="Filter by agent DID")
358
+ @click.option("--limit", "-l", default=20, help="Number of entries")
359
+ @click.option("--format", "fmt", type=click.Choice(["table", "json"]), default="table")
360
+ def audit(agent: str, limit: int, fmt: str):
361
+ """View audit logs."""
362
+ console.print(f"\n[bold blue]๐Ÿ“‹ Audit Log[/bold blue]\n")
363
+
364
+ # Simulated audit entries
365
+ entries = [
366
+ {"timestamp": "2026-01-31T10:15:00Z", "agent": "agent-1", "action": "credential_issued", "status": "success"},
367
+ {"timestamp": "2026-01-31T10:14:30Z", "agent": "agent-1", "action": "policy_check", "status": "allowed"},
368
+ {"timestamp": "2026-01-31T10:14:00Z", "agent": "agent-2", "action": "handshake", "status": "success"},
369
+ {"timestamp": "2026-01-31T10:13:00Z", "agent": "agent-1", "action": "tool_call", "status": "allowed"},
370
+ {"timestamp": "2026-01-31T10:12:00Z", "agent": "agent-3", "action": "policy_check", "status": "blocked"},
371
+ ]
372
+
373
+ if agent:
374
+ entries = [e for e in entries if e["agent"] == agent]
375
+
376
+ entries = entries[:limit]
377
+
378
+ if fmt == "json":
379
+ console.print(json.dumps(entries, indent=2))
380
+ else:
381
+ table = Table(box=box.SIMPLE)
382
+ table.add_column("Timestamp", style="dim")
383
+ table.add_column("Agent")
384
+ table.add_column("Action")
385
+ table.add_column("Status")
386
+
387
+ for entry in entries:
388
+ status_style = "green" if entry["status"] in ["success", "allowed"] else "red"
389
+ table.add_row(
390
+ entry["timestamp"],
391
+ entry["agent"],
392
+ entry["action"],
393
+ f"[{status_style}]{entry['status']}[/{status_style}]",
394
+ )
395
+
396
+ console.print(table)
397
+
398
+
399
+ def main():
400
+ """Main entry point."""
401
+ app()
402
+
403
+
404
+ if __name__ == "__main__":
405
+ main()
@@ -0,0 +1,26 @@
1
+ """
2
+ Governance & Compliance Plane (Layer 3)
3
+
4
+ Declarative policy engine with automated compliance mapping.
5
+ Tamper-evident audit logs with Merkle-chain hashing.
6
+ """
7
+
8
+ from .policy import PolicyEngine, Policy, PolicyRule, PolicyDecision
9
+ from .compliance import ComplianceEngine, ComplianceFramework, ComplianceReport
10
+ from .audit import AuditLog, AuditEntry, MerkleAuditChain
11
+ from .shadow import ShadowMode, ShadowResult
12
+
13
+ __all__ = [
14
+ "PolicyEngine",
15
+ "Policy",
16
+ "PolicyRule",
17
+ "PolicyDecision",
18
+ "ComplianceEngine",
19
+ "ComplianceFramework",
20
+ "ComplianceReport",
21
+ "AuditLog",
22
+ "AuditEntry",
23
+ "MerkleAuditChain",
24
+ "ShadowMode",
25
+ "ShadowResult",
26
+ ]