semanticembed 0.1.0__tar.gz → 0.2.1__tar.gz

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.
Files changed (46) hide show
  1. semanticembed-0.2.1/.claude/skills/analyze/SKILL.md +95 -0
  2. semanticembed-0.1.0/README.md → semanticembed-0.2.1/PKG-INFO +136 -2
  3. semanticembed-0.1.0/PKG-INFO → semanticembed-0.2.1/README.md +100 -26
  4. semanticembed-0.2.1/agent/README.md +172 -0
  5. semanticembed-0.2.1/agent/__init__.py +3 -0
  6. semanticembed-0.2.1/agent/__main__.py +4 -0
  7. semanticembed-0.2.1/agent/agent.py +368 -0
  8. semanticembed-0.2.1/agent/gemini_agent.py +406 -0
  9. {semanticembed-0.1.0 → semanticembed-0.2.1}/dimensions.md +5 -4
  10. {semanticembed-0.1.0 → semanticembed-0.2.1}/docs/api_reference.md +93 -1
  11. {semanticembed-0.1.0 → semanticembed-0.2.1}/docs/dimensions.md +5 -4
  12. {semanticembed-0.1.0 → semanticembed-0.2.1}/docs/getting_started.md +41 -3
  13. semanticembed-0.2.1/docs/input_format.md +98 -0
  14. {semanticembed-0.1.0 → semanticembed-0.2.1}/docs/license_keys.md +2 -2
  15. semanticembed-0.2.1/notebooks/08_qwen_compression.ipynb +1028 -0
  16. semanticembed-0.2.1/notebooks/qwen_compression_cookbook.py +512 -0
  17. {semanticembed-0.1.0 → semanticembed-0.2.1}/pyproject.toml +7 -1
  18. semanticembed-0.2.1/skill/SETUP.md +59 -0
  19. semanticembed-0.2.1/skill/SKILL.md +164 -0
  20. semanticembed-0.2.1/skill/analyze.py +338 -0
  21. {semanticembed-0.1.0 → semanticembed-0.2.1}/src/semanticembed/__init__.py +8 -2
  22. {semanticembed-0.1.0 → semanticembed-0.2.1}/src/semanticembed/client.py +59 -7
  23. semanticembed-0.2.1/src/semanticembed/explain.py +275 -0
  24. semanticembed-0.2.1/src/semanticembed/extract.py +647 -0
  25. {semanticembed-0.1.0 → semanticembed-0.2.1}/src/semanticembed/models.py +59 -0
  26. semanticembed-0.1.0/docs/input_format.md +0 -71
  27. {semanticembed-0.1.0 → semanticembed-0.2.1}/.gitignore +0 -0
  28. {semanticembed-0.1.0 → semanticembed-0.2.1}/LICENSE +0 -0
  29. {semanticembed-0.1.0 → semanticembed-0.2.1}/docs/output_format.md +0 -0
  30. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/ai_agent_pipeline.json +0 -0
  31. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/cicd_pipeline.json +0 -0
  32. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/google_online_boutique.json +0 -0
  33. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/react/README.md +0 -0
  34. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/react/RadarChart.tsx +0 -0
  35. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/react/RiskTable.tsx +0 -0
  36. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/react/TopologySummary.tsx +0 -0
  37. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/react/useSemanticEmbed.ts +0 -0
  38. {semanticembed-0.1.0 → semanticembed-0.2.1}/examples/weaveworks_sock_shop.json +0 -0
  39. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/01_quickstart.ipynb +0 -0
  40. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/02_dimensions.ipynb +0 -0
  41. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/03_drift_detection.ipynb +0 -0
  42. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/04_bring_your_own.ipynb +0 -0
  43. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/05_ai_agent_pipelines.ipynb +0 -0
  44. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/06_cicd_pipelines.ipynb +0 -0
  45. {semanticembed-0.1.0 → semanticembed-0.2.1}/notebooks/07_opentelemetry.ipynb +0 -0
  46. {semanticembed-0.1.0 → semanticembed-0.2.1}/src/semanticembed/exceptions.py +0 -0
@@ -0,0 +1,95 @@
1
+ ---
2
+ name: analyze
3
+ description: Scan a repo for infrastructure files (docker-compose, k8s, terraform, GitHub Actions), extract edges, and run 6D structural risk analysis via SemanticEmbed.
4
+ allowed-tools: Bash Read Glob
5
+ ---
6
+
7
+ # /analyze — Structural Risk Analysis
8
+
9
+ Scan the current repository (or a given path) for infrastructure files, extract service dependencies, encode them with SemanticEmbed, and report structural risks.
10
+
11
+ ## Steps
12
+
13
+ 1. **Detect infrastructure and code files** in the repo. Look for:
14
+ - `docker-compose.yml` / `docker-compose.yaml` / `compose.yml` / `compose.yaml`
15
+ - Kubernetes YAML in `k8s/`, `kubernetes/`, `manifests/`, `deploy/`, or any directory with Service/Deployment resources
16
+ - `.github/workflows/*.yml` (GitHub Actions)
17
+ - `*.tf` files (Terraform)
18
+ - `*.py` files (Python module imports)
19
+ - `package.json` files (Node.js monorepo workspace dependencies)
20
+
21
+ 2. **Run the extract + encode script** using the Python snippet below. If the user provided a specific path as an argument, pass it to `from_directory()`. Otherwise use the current directory.
22
+
23
+ 3. **Present the results** clearly:
24
+ - How many edges were found and from which sources
25
+ - The full structural risk report
26
+ - The top 5 most critical nodes with their 6D vectors
27
+ - Specific actionable recommendations based on the risks found
28
+
29
+ 4. **If no infrastructure files are found**, tell the user they can:
30
+ - Point to a specific file: `/analyze path/to/docker-compose.yml`
31
+ - Pass edges manually: `se.encode([("A","B"), ("B","C")])`
32
+ - Use one of the example notebooks
33
+
34
+ ## Python Script
35
+
36
+ ```python
37
+ import semanticembed as se
38
+
39
+ # Auto-detect and extract edges
40
+ edges, sources = se.extract.from_directory("TARGET_PATH")
41
+
42
+ if not edges:
43
+ print("No infrastructure files found.")
44
+ else:
45
+ print(f"Found {len(edges)} edges from: {sources}")
46
+ print()
47
+
48
+ # Encode
49
+ result = se.encode(edges)
50
+
51
+ # Risk report
52
+ print(result.table)
53
+ print()
54
+ print(se.report(result))
55
+ ```
56
+
57
+ Replace `TARGET_PATH` with the user's argument or `"."` for current directory.
58
+
59
+ If `se.extract.from_directory` finds nothing but the user pointed to a specific file or directory, use the appropriate parser directly:
60
+ - `.yml`/`.yaml` with `services:` key → `se.extract.from_docker_compose(path)`
61
+ - `.yml`/`.yaml` with `kind:` key → `se.extract.from_kubernetes(path)`
62
+ - `.yml`/`.yaml` with `jobs:` key → `se.extract.from_github_actions(path)`
63
+ - `.tf` files → `se.extract.from_terraform(path)`
64
+ - Python directory → `se.extract.from_python_imports(path)`
65
+ - `package.json` → `se.extract.from_package_json(path)` or `se.extract.from_package_json_workspaces(path)`
66
+
67
+ ## Requirements
68
+
69
+ - `pip install git+https://github.com/jmurray10/semanticembed-sdk.git pyyaml`
70
+ - Or if published: `pip install semanticembed pyyaml`
71
+ - Free tier: up to 50 nodes (covers most single-service repos)
72
+
73
+ ## Example Output
74
+
75
+ ```
76
+ Found 8 edges from: {'docker-compose': 8}
77
+
78
+ Node Depth Indep Hier Thru Crit Fan
79
+ ------------------------------------------------------
80
+ api 0.333 0.500 0.500 0.500 0.083 0.750
81
+ auth 0.667 0.000 0.500 0.375 0.056 0.333
82
+ frontend 0.000 0.000 0.500 0.250 0.000 1.000
83
+ postgres 1.000 0.500 0.500 0.375 0.000 0.000
84
+ redis 0.667 1.000 1.000 0.250 0.000 0.000
85
+ worker 0.000 1.000 1.000 0.250 0.000 1.000
86
+
87
+ STRUCTURAL RISK REPORT
88
+ ======================
89
+ SINGLE POINT OF FAILURE:
90
+ - api | criticality=0.083, independence=0.50
91
+ - auth | criticality=0.056, independence=0.00
92
+
93
+ CONVERGENCE SINK:
94
+ - postgres | 3 upstream services, no downstream
95
+ ```
@@ -1,3 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: semanticembed
3
+ Version: 0.2.1
4
+ Summary: 6D structural intelligence for directed graphs. Six numbers per node. Sub-millisecond.
5
+ Project-URL: Homepage, https://github.com/jmurray10/semanticembed-sdk
6
+ Project-URL: Documentation, https://github.com/jmurray10/semanticembed-sdk
7
+ Project-URL: Repository, https://github.com/jmurray10/semanticembed-sdk
8
+ Author-email: Jeff Murray <jeffmurr@seas.upenn.edu>
9
+ License: Proprietary
10
+ License-File: LICENSE
11
+ Keywords: graph,microservices,observability,risk-detection,structural-analysis
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: httpx>=0.24
23
+ Provides-Extra: agent-claude
24
+ Requires-Dist: claude-agent-sdk; extra == 'agent-claude'
25
+ Requires-Dist: pyyaml>=6.0; extra == 'agent-claude'
26
+ Provides-Extra: agent-gemini
27
+ Requires-Dist: google-genai; extra == 'agent-gemini'
28
+ Requires-Dist: pyyaml>=6.0; extra == 'agent-gemini'
29
+ Provides-Extra: all
30
+ Requires-Dist: claude-agent-sdk; extra == 'all'
31
+ Requires-Dist: google-genai; extra == 'all'
32
+ Requires-Dist: pyyaml>=6.0; extra == 'all'
33
+ Provides-Extra: extract
34
+ Requires-Dist: pyyaml>=6.0; extra == 'extract'
35
+ Description-Content-Type: text/markdown
36
+
1
37
  # SemanticEmbed SDK
2
38
 
3
39
  **Structural intelligence for directed graphs. Six numbers per node. Sub-millisecond.**
@@ -15,7 +51,7 @@ Observability tools tell you **what broke**. SemanticEmbed tells you **what will
15
51
  - **No agents, no instrumentation** -- just an edge list
16
52
  - **Sub-millisecond** -- encodes 100+ node graphs in <1ms
17
53
  - **Works on any directed graph** -- microservices, AI agent pipelines, data workflows, CI/CD
18
- - **Mathematically independent axes** -- six dimensions, zero redundancy, each captures structural information no other metric provides
54
+ - **Complementary structural axes** -- six dimensions, each captures risk signals the others cannot
19
55
 
20
56
  ---
21
57
 
@@ -104,7 +140,7 @@ Every node gets six independent structural measurements:
104
140
  | **Criticality** | Fraction of end-to-end paths depending on this node | High criticality = SPOF |
105
141
  | **Fanout** | Broadcaster (1.0) vs aggregator (0.0) | High fanout = amplification risk |
106
142
 
107
- These six properties are mathematically independent -- knowing any five tells you nothing about the sixth.
143
+ These six properties capture complementary structural information. Each dimension provides risk signals the others cannot.
108
144
 
109
145
  See [docs/dimensions.md](docs/dimensions.md) for the full reference.
110
146
 
@@ -135,6 +171,104 @@ Step-by-step Colab notebooks. Click to open, run in your browser.
135
171
  | [05 - AI Agent Pipelines](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/05_ai_agent_pipelines.ipynb) | AI/LLM agents | Vendor concentration, gateway bottlenecks, guardrail SPOFs |
136
172
  | [06 - CI/CD & Data Pipelines](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/06_cicd_pipelines.ipynb) | CI/CD & ETL | Build graph fragility, pipeline bottlenecks, drift gates |
137
173
  | [07 - OpenTelemetry](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/07_opentelemetry.ipynb) | OTel traces | Extract edges from traces, structural analysis, CI/CD gates |
174
+ | [08 - Qwen Compression](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/08_qwen_compression.ipynb) | LLM compression | Structural pruning of Qwen2.5-7B, 10% speedup at Grade A |
175
+
176
+ ---
177
+
178
+ ## Extract Edges from Infrastructure
179
+
180
+ Don't have an edge list? The `extract` module parses common infrastructure files automatically.
181
+
182
+ ```python
183
+ import semanticembed as se
184
+
185
+ # From Docker Compose
186
+ edges = se.extract.from_docker_compose("docker-compose.yml")
187
+
188
+ # From Kubernetes manifests
189
+ edges = se.extract.from_kubernetes("k8s/")
190
+
191
+ # From GitHub Actions workflows
192
+ edges = se.extract.from_github_actions(".github/workflows")
193
+
194
+ # From Terraform
195
+ edges = se.extract.from_terraform("infra/")
196
+
197
+ # From Python imports (module dependency graph)
198
+ edges = se.extract.from_python_imports("src/")
199
+
200
+ # From Node.js monorepo (inter-package dependencies)
201
+ edges = se.extract.from_package_json_workspaces(".")
202
+
203
+ # Auto-detect everything in a directory
204
+ edges, sources = se.extract.from_directory(".")
205
+ print(f"Found {len(edges)} edges from {sources}")
206
+
207
+ # Then encode as usual
208
+ result = se.encode(edges)
209
+ print(result.table)
210
+ ```
211
+
212
+ Requires `pyyaml` for YAML parsing: `pip install pyyaml`
213
+
214
+ ---
215
+
216
+ ## LLM-Powered Analysis
217
+
218
+ Get plain-language explanations and actionable recommendations using your own LLM key.
219
+
220
+ ```python
221
+ import semanticembed as se
222
+
223
+ result = se.encode(edges)
224
+
225
+ # One-shot analysis (OpenAI, Anthropic, or local Ollama)
226
+ print(se.explain(result, model="gpt-4o-mini", api_key="sk-..."))
227
+ print(se.explain(result, model="claude-sonnet-4-5", api_key="sk-ant-..."))
228
+ print(se.explain(result, model="ollama/llama3")) # local, no key needed
229
+
230
+ # Follow-up questions
231
+ answer = se.ask(result, "What happens if the database goes down?",
232
+ model="gpt-4o-mini", api_key="sk-...")
233
+ ```
234
+
235
+ The LLM sees only the encoding output (6D vectors, risk report) -- never the algorithm.
236
+
237
+ ---
238
+
239
+ ## Structural Diff
240
+
241
+ Compare two graph versions in one call:
242
+
243
+ ```python
244
+ changes = se.encode_diff(edges_v1, edges_v2)
245
+ for node, deltas in changes.items():
246
+ for dim, info in deltas.items():
247
+ print(f"{node}.{dim}: {info['before']:.3f} -> {info['after']:.3f}")
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Agent
253
+
254
+ An autonomous agent that scans your repo, extracts edges, encodes, and explains results interactively. Choose your LLM backend:
255
+
256
+ ```bash
257
+ # Claude agent
258
+ pip install claude-agent-sdk
259
+ export ANTHROPIC_API_KEY=sk-ant-...
260
+ python -m agent
261
+
262
+ # Gemini agent
263
+ pip install google-genai
264
+ export GOOGLE_API_KEY=...
265
+ python -m agent.gemini_agent
266
+
267
+ # Single question
268
+ python -m agent --ask "What is my biggest SPOF?"
269
+ ```
270
+
271
+ The agent has 7 tools: scan, extract (docker-compose, k8s, Python imports), encode, diff, and simulate architecture changes. See [agent/README.md](agent/README.md) for full docs.
138
272
 
139
273
  ---
140
274
 
@@ -1,27 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: semanticembed
3
- Version: 0.1.0
4
- Summary: 6D structural intelligence for directed graphs. Six numbers per node. Sub-millisecond.
5
- Project-URL: Homepage, https://github.com/jmurray10/semanticembed-sdk
6
- Project-URL: Documentation, https://github.com/jmurray10/semanticembed-sdk
7
- Project-URL: Repository, https://github.com/jmurray10/semanticembed-sdk
8
- Author-email: Jeff Murray <jeffmurr@seas.upenn.edu>
9
- License: Proprietary
10
- License-File: LICENSE
11
- Keywords: graph,microservices,observability,risk-detection,structural-analysis
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: 3.12
19
- Classifier: Programming Language :: Python :: 3.13
20
- Classifier: Topic :: Software Development :: Libraries
21
- Requires-Python: >=3.9
22
- Requires-Dist: httpx>=0.24
23
- Description-Content-Type: text/markdown
24
-
25
1
  # SemanticEmbed SDK
26
2
 
27
3
  **Structural intelligence for directed graphs. Six numbers per node. Sub-millisecond.**
@@ -39,7 +15,7 @@ Observability tools tell you **what broke**. SemanticEmbed tells you **what will
39
15
  - **No agents, no instrumentation** -- just an edge list
40
16
  - **Sub-millisecond** -- encodes 100+ node graphs in <1ms
41
17
  - **Works on any directed graph** -- microservices, AI agent pipelines, data workflows, CI/CD
42
- - **Mathematically independent axes** -- six dimensions, zero redundancy, each captures structural information no other metric provides
18
+ - **Complementary structural axes** -- six dimensions, each captures risk signals the others cannot
43
19
 
44
20
  ---
45
21
 
@@ -128,7 +104,7 @@ Every node gets six independent structural measurements:
128
104
  | **Criticality** | Fraction of end-to-end paths depending on this node | High criticality = SPOF |
129
105
  | **Fanout** | Broadcaster (1.0) vs aggregator (0.0) | High fanout = amplification risk |
130
106
 
131
- These six properties are mathematically independent -- knowing any five tells you nothing about the sixth.
107
+ These six properties capture complementary structural information. Each dimension provides risk signals the others cannot.
132
108
 
133
109
  See [docs/dimensions.md](docs/dimensions.md) for the full reference.
134
110
 
@@ -159,6 +135,104 @@ Step-by-step Colab notebooks. Click to open, run in your browser.
159
135
  | [05 - AI Agent Pipelines](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/05_ai_agent_pipelines.ipynb) | AI/LLM agents | Vendor concentration, gateway bottlenecks, guardrail SPOFs |
160
136
  | [06 - CI/CD & Data Pipelines](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/06_cicd_pipelines.ipynb) | CI/CD & ETL | Build graph fragility, pipeline bottlenecks, drift gates |
161
137
  | [07 - OpenTelemetry](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/07_opentelemetry.ipynb) | OTel traces | Extract edges from traces, structural analysis, CI/CD gates |
138
+ | [08 - Qwen Compression](https://colab.research.google.com/github/jmurray10/semanticembed-sdk/blob/main/notebooks/08_qwen_compression.ipynb) | LLM compression | Structural pruning of Qwen2.5-7B, 10% speedup at Grade A |
139
+
140
+ ---
141
+
142
+ ## Extract Edges from Infrastructure
143
+
144
+ Don't have an edge list? The `extract` module parses common infrastructure files automatically.
145
+
146
+ ```python
147
+ import semanticembed as se
148
+
149
+ # From Docker Compose
150
+ edges = se.extract.from_docker_compose("docker-compose.yml")
151
+
152
+ # From Kubernetes manifests
153
+ edges = se.extract.from_kubernetes("k8s/")
154
+
155
+ # From GitHub Actions workflows
156
+ edges = se.extract.from_github_actions(".github/workflows")
157
+
158
+ # From Terraform
159
+ edges = se.extract.from_terraform("infra/")
160
+
161
+ # From Python imports (module dependency graph)
162
+ edges = se.extract.from_python_imports("src/")
163
+
164
+ # From Node.js monorepo (inter-package dependencies)
165
+ edges = se.extract.from_package_json_workspaces(".")
166
+
167
+ # Auto-detect everything in a directory
168
+ edges, sources = se.extract.from_directory(".")
169
+ print(f"Found {len(edges)} edges from {sources}")
170
+
171
+ # Then encode as usual
172
+ result = se.encode(edges)
173
+ print(result.table)
174
+ ```
175
+
176
+ Requires `pyyaml` for YAML parsing: `pip install pyyaml`
177
+
178
+ ---
179
+
180
+ ## LLM-Powered Analysis
181
+
182
+ Get plain-language explanations and actionable recommendations using your own LLM key.
183
+
184
+ ```python
185
+ import semanticembed as se
186
+
187
+ result = se.encode(edges)
188
+
189
+ # One-shot analysis (OpenAI, Anthropic, or local Ollama)
190
+ print(se.explain(result, model="gpt-4o-mini", api_key="sk-..."))
191
+ print(se.explain(result, model="claude-sonnet-4-5", api_key="sk-ant-..."))
192
+ print(se.explain(result, model="ollama/llama3")) # local, no key needed
193
+
194
+ # Follow-up questions
195
+ answer = se.ask(result, "What happens if the database goes down?",
196
+ model="gpt-4o-mini", api_key="sk-...")
197
+ ```
198
+
199
+ The LLM sees only the encoding output (6D vectors, risk report) -- never the algorithm.
200
+
201
+ ---
202
+
203
+ ## Structural Diff
204
+
205
+ Compare two graph versions in one call:
206
+
207
+ ```python
208
+ changes = se.encode_diff(edges_v1, edges_v2)
209
+ for node, deltas in changes.items():
210
+ for dim, info in deltas.items():
211
+ print(f"{node}.{dim}: {info['before']:.3f} -> {info['after']:.3f}")
212
+ ```
213
+
214
+ ---
215
+
216
+ ## Agent
217
+
218
+ An autonomous agent that scans your repo, extracts edges, encodes, and explains results interactively. Choose your LLM backend:
219
+
220
+ ```bash
221
+ # Claude agent
222
+ pip install claude-agent-sdk
223
+ export ANTHROPIC_API_KEY=sk-ant-...
224
+ python -m agent
225
+
226
+ # Gemini agent
227
+ pip install google-genai
228
+ export GOOGLE_API_KEY=...
229
+ python -m agent.gemini_agent
230
+
231
+ # Single question
232
+ python -m agent --ask "What is my biggest SPOF?"
233
+ ```
234
+
235
+ The agent has 7 tools: scan, extract (docker-compose, k8s, Python imports), encode, diff, and simulate architecture changes. See [agent/README.md](agent/README.md) for full docs.
162
236
 
163
237
  ---
164
238
 
@@ -0,0 +1,172 @@
1
+ # SemanticEmbed Agent
2
+
3
+ An LLM-powered structural analysis assistant built on the Claude Agent SDK.
4
+
5
+ The agent autonomously scans your codebase, extracts service dependencies, runs 6D structural encoding, and explains the results in plain language. Ask follow-up questions, simulate architecture changes, and get actionable recommendations.
6
+
7
+ ## How It Works
8
+
9
+ ```
10
+ Your Code ──→ Agent scans for infra files (docker-compose, k8s, terraform, Python imports)
11
+ │
12
+ ▼
13
+ Extracts edges automatically
14
+ │
15
+ ▼
16
+ Encodes via SemanticEmbed API (deterministic, server-side)
17
+ │
18
+ ▼
19
+ LLM interprets results (your Anthropic key)
20
+ │
21
+ ▼
22
+ Plain language analysis + actionable recommendations
23
+ ```
24
+
25
+ The 6D encoding is deterministic and proprietary (runs server-side). The LLM only sees the output vectors and risk report — never the algorithm.
26
+
27
+ ## Install
28
+
29
+ Two agent options — pick your LLM provider:
30
+
31
+ ### Claude Agent (Anthropic)
32
+
33
+ ```bash
34
+ pip install semanticembed claude-agent-sdk pyyaml
35
+ export ANTHROPIC_API_KEY=sk-ant-...
36
+ ```
37
+
38
+ ### Gemini Agent (Google)
39
+
40
+ ```bash
41
+ pip install semanticembed google-genai pyyaml
42
+ export GOOGLE_API_KEY=...
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### Claude Agent
48
+
49
+ ```bash
50
+ # Interactive — scans your project, explains risks, answers questions
51
+ python -m agent
52
+
53
+ # Analyze a specific project
54
+ python -m agent /path/to/project
55
+
56
+ # Single question
57
+ python -m agent --ask "What is my biggest single point of failure?"
58
+ ```
59
+
60
+ ### Gemini Agent
61
+
62
+ ```bash
63
+ # Interactive
64
+ python -m agent.gemini_agent
65
+
66
+ # Analyze a specific project
67
+ python -m agent.gemini_agent /path/to/project
68
+
69
+ # Single question
70
+ python -m agent.gemini_agent --ask "What happens if the database goes down?"
71
+
72
+ # Use a different Gemini model
73
+ python -m agent.gemini_agent --model gemini-2.5-pro
74
+ ```
75
+
76
+ Both agents have the same 7 tools and produce equivalent results — just different LLM backends.
77
+
78
+ The agent will:
79
+ 1. Scan for infrastructure files
80
+ 2. Extract edges
81
+ 3. Encode the graph
82
+ 4. Present a structural risk summary
83
+ 5. Wait for your questions
84
+
85
+ ## What the Agent Can Do
86
+
87
+ | Capability | Example |
88
+ |------------|---------|
89
+ | **Auto-scan** | Finds docker-compose, k8s manifests, terraform, Python imports, package.json |
90
+ | **Encode** | Runs 6D structural analysis on extracted edges |
91
+ | **Explain** | "Your api-gateway is on 89% of all paths — if it goes down, everything fails" |
92
+ | **Simulate** | "What if I add a cache between api and database?" → shows structural impact |
93
+ | **Compare** | "Show me the drift between v1 and v2 of this architecture" |
94
+ | **Recommend** | "Add a circuit breaker upstream of order-service to contain cascading failures" |
95
+
96
+ ## Tools
97
+
98
+ The agent has 7 tools it calls autonomously:
99
+
100
+ | Tool | What it does |
101
+ |------|-------------|
102
+ | `scan_directory` | Auto-detect and extract edges from all infrastructure file types |
103
+ | `extract_docker_compose` | Parse a specific docker-compose.yml |
104
+ | `extract_kubernetes` | Parse Kubernetes YAML manifests |
105
+ | `extract_python_imports` | Build module dependency graph from Python imports |
106
+ | `encode_graph` | Run 6D structural encoding on an edge list |
107
+ | `encode_and_diff` | Compare two graph versions and show structural drift |
108
+ | `simulate_change` | Test hypothetical architecture changes (add/remove edges) |
109
+
110
+ ## Example Session
111
+
112
+ ```
113
+ $ python -m agent
114
+
115
+ SemanticEmbed Agent
116
+ ========================================
117
+ Scanning: .
118
+
119
+ Found 8 edges from docker-compose.yml:
120
+ frontend -> api, frontend -> auth, api -> postgres, api -> redis,
121
+ api -> auth, auth -> postgres, worker -> redis, worker -> postgres
122
+
123
+ STRUCTURAL ANALYSIS:
124
+ Your architecture has 3 critical risks:
125
+
126
+ 1. **api** is your biggest SPOF (criticality=0.083, independence=0.50).
127
+ It sits on most end-to-end paths and has limited redundancy.
128
+ → Add a fallback API or load balancer.
129
+
130
+ 2. **auth** is a deep bottleneck (depth=0.67, independence=0.00).
131
+ It's the only authentication path — no fallback.
132
+ → Consider an auth cache or backup auth provider.
133
+
134
+ 3. **postgres** is a convergence sink (3 upstream services, 0 downstream).
135
+ If it goes down, api, auth, and worker all fail.
136
+ → Add a read replica for read-heavy services.
137
+
138
+ > What if I add redis as a cache between api and postgres?
139
+
140
+ SIMULATED CHANGE: +1 edge (api -> redis-cache -> postgres)
141
+
142
+ The change reduces postgres convergence pressure:
143
+ - postgres throughput: 0.375 -> 0.286 (reads shifted to cache)
144
+ - api criticality unchanged (still on most paths)
145
+ - New convergence sink: redis-cache (monitor for saturation)
146
+
147
+ Recommendation: Good change. Reduces database blast radius for reads.
148
+ Add a circuit breaker on the redis-cache connection so API falls back
149
+ to direct postgres if cache is unavailable.
150
+
151
+ > quit
152
+ ```
153
+
154
+ ## Using Programmatically
155
+
156
+ ```python
157
+ import asyncio
158
+ from agent import run_agent
159
+
160
+ # Single query
161
+ asyncio.run(run_agent(
162
+ "What are the structural risks in this project?",
163
+ path="/path/to/project"
164
+ ))
165
+ ```
166
+
167
+ ## Privacy
168
+
169
+ - The 6D encoding runs server-side (SemanticEmbed API) — your topology edges are sent to the encoding server
170
+ - The LLM (Anthropic) sees only the encoding output (6D vectors, risk report) — not your raw code or infrastructure files
171
+ - The encoding algorithm is proprietary — neither you nor the LLM ever sees how it works
172
+ - Use Ollama for fully local LLM inference if needed (modify the model in agent.py)
@@ -0,0 +1,3 @@
1
+ """SemanticEmbed Agent — LLM-powered structural analysis assistant."""
2
+
3
+ from .agent import run_agent, interactive, create_server, main
@@ -0,0 +1,4 @@
1
+ """Allow running the agent with: python -m agent"""
2
+ from .agent import main
3
+
4
+ main()