levain-sdk 0.1.0__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 (63) hide show
  1. levain_sdk-0.1.0/.gitignore +119 -0
  2. levain_sdk-0.1.0/LICENSE +202 -0
  3. levain_sdk-0.1.0/PKG-INFO +64 -0
  4. levain_sdk-0.1.0/README.md +45 -0
  5. levain_sdk-0.1.0/pyproject.toml +47 -0
  6. levain_sdk-0.1.0/src/levain_sdk/__init__.py +21 -0
  7. levain_sdk-0.1.0/src/levain_sdk/_mcp.py +30 -0
  8. levain_sdk-0.1.0/src/levain_sdk/agents_tools/__init__.py +20 -0
  9. levain_sdk-0.1.0/src/levain_sdk/agents_tools/mcp.py +119 -0
  10. levain_sdk-0.1.0/src/levain_sdk/app_data/__init__.py +1 -0
  11. levain_sdk-0.1.0/src/levain_sdk/app_data/mcp.py +225 -0
  12. levain_sdk-0.1.0/src/levain_sdk/app_data/query.py +339 -0
  13. levain_sdk-0.1.0/src/levain_sdk/artifacts/__init__.py +21 -0
  14. levain_sdk-0.1.0/src/levain_sdk/artifacts/_publish_raw_source.py +86 -0
  15. levain_sdk-0.1.0/src/levain_sdk/artifacts/_staging.py +194 -0
  16. levain_sdk-0.1.0/src/levain_sdk/artifacts/mcp.py +302 -0
  17. levain_sdk-0.1.0/src/levain_sdk/catalog.py +21 -0
  18. levain_sdk-0.1.0/src/levain_sdk/claude.py +1238 -0
  19. levain_sdk-0.1.0/src/levain_sdk/crawler/__init__.py +971 -0
  20. levain_sdk-0.1.0/src/levain_sdk/errors.py +53 -0
  21. levain_sdk-0.1.0/src/levain_sdk/formatting.py +40 -0
  22. levain_sdk-0.1.0/src/levain_sdk/git.py +608 -0
  23. levain_sdk-0.1.0/src/levain_sdk/github_tools/__init__.py +5 -0
  24. levain_sdk-0.1.0/src/levain_sdk/github_tools/mcp.py +628 -0
  25. levain_sdk-0.1.0/src/levain_sdk/handlers.py +198 -0
  26. levain_sdk-0.1.0/src/levain_sdk/hermes.py +590 -0
  27. levain_sdk-0.1.0/src/levain_sdk/hermes_driver.py +231 -0
  28. levain_sdk-0.1.0/src/levain_sdk/hermes_memory.py +169 -0
  29. levain_sdk-0.1.0/src/levain_sdk/image_tools/__init__.py +1 -0
  30. levain_sdk-0.1.0/src/levain_sdk/image_tools/mcp.py +85 -0
  31. levain_sdk-0.1.0/src/levain_sdk/integrations.py +283 -0
  32. levain_sdk-0.1.0/src/levain_sdk/mcp_registry.py +284 -0
  33. levain_sdk-0.1.0/src/levain_sdk/mcp_stdio.py +103 -0
  34. levain_sdk-0.1.0/src/levain_sdk/memory.py +48 -0
  35. levain_sdk-0.1.0/src/levain_sdk/memory_tools/__init__.py +13 -0
  36. levain_sdk-0.1.0/src/levain_sdk/memory_tools/mcp.py +403 -0
  37. levain_sdk-0.1.0/src/levain_sdk/messages.py +151 -0
  38. levain_sdk-0.1.0/src/levain_sdk/models.py +645 -0
  39. levain_sdk-0.1.0/src/levain_sdk/models_catalog.md +205 -0
  40. levain_sdk-0.1.0/src/levain_sdk/platform_actions/__init__.py +39 -0
  41. levain_sdk-0.1.0/src/levain_sdk/platform_actions/google_ads.py +235 -0
  42. levain_sdk-0.1.0/src/levain_sdk/platform_actions/meta_ads.py +102 -0
  43. levain_sdk-0.1.0/src/levain_sdk/platform_actions/shopify.py +147 -0
  44. levain_sdk-0.1.0/src/levain_sdk/platform_actions/stripe.py +137 -0
  45. levain_sdk-0.1.0/src/levain_sdk/progress_tools/__init__.py +1 -0
  46. levain_sdk-0.1.0/src/levain_sdk/progress_tools/mcp.py +81 -0
  47. levain_sdk-0.1.0/src/levain_sdk/prompts.py +31 -0
  48. levain_sdk-0.1.0/src/levain_sdk/py.typed +0 -0
  49. levain_sdk-0.1.0/src/levain_sdk/reducers.py +69 -0
  50. levain_sdk-0.1.0/src/levain_sdk/review/__init__.py +0 -0
  51. levain_sdk-0.1.0/src/levain_sdk/review/github.py +730 -0
  52. levain_sdk-0.1.0/src/levain_sdk/review/mcp.py +602 -0
  53. levain_sdk-0.1.0/src/levain_sdk/review/store.py +905 -0
  54. levain_sdk-0.1.0/src/levain_sdk/sandbox_api.py +69 -0
  55. levain_sdk-0.1.0/src/levain_sdk/sessions_tools/__init__.py +0 -0
  56. levain_sdk-0.1.0/src/levain_sdk/sessions_tools/mcp.py +88 -0
  57. levain_sdk-0.1.0/src/levain_sdk/shell.py +156 -0
  58. levain_sdk-0.1.0/src/levain_sdk/slack/__init__.py +1 -0
  59. levain_sdk-0.1.0/src/levain_sdk/slack/mcp.py +274 -0
  60. levain_sdk-0.1.0/src/levain_sdk/wiki/__init__.py +15 -0
  61. levain_sdk-0.1.0/src/levain_sdk/wiki/index.py +366 -0
  62. levain_sdk-0.1.0/src/levain_sdk/wiki/mcp.py +424 -0
  63. levain_sdk-0.1.0/src/levain_sdk/wiki/scoring.py +173 -0
@@ -0,0 +1,119 @@
1
+ # Local secrets
2
+ .secrets
3
+
4
+ # Dependencies
5
+ node_modules/
6
+
7
+ # Terraform
8
+ .terraform/
9
+ terraform.tfstate
10
+ terraform.tfstate.backup
11
+ *.tfvars
12
+ *.tfvars.json
13
+ .terraform.tfstate.lock.info
14
+
15
+ # Built code
16
+ dist/
17
+ build/
18
+ !**/platform_agents/build/
19
+ !**/src/build/
20
+
21
+ # Binaries
22
+ bin/
23
+
24
+ # Packaged code
25
+ *.tgz
26
+ *.zip
27
+ *.tar
28
+ *.tar.gz
29
+
30
+ # Environments
31
+ .env
32
+ *.env
33
+ .venv
34
+
35
+ # Misc
36
+ .DS_Store
37
+ *.log
38
+
39
+ # Python bytecode
40
+ __pycache__/
41
+ *.py[cod]
42
+ *.egg-info/
43
+
44
+ # Test coverage
45
+ .coverage
46
+ .coverage.*
47
+ .pytest_cache/
48
+ htmlcov/
49
+
50
+ # Ruff / MyPy caches
51
+ .ruff_cache/
52
+ .mypy_cache/
53
+
54
+ # VS Code (enable sharing settings)
55
+ !.vscode
56
+
57
+ # Claude Code local settings
58
+ .claude/settings.local.json
59
+ .claude/worktrees/
60
+
61
+ # Skills tooling installed locally via `hyperframes skills` (keep the repo's own skills, e.g. check-pr)
62
+ .agents/
63
+ skills-lock.json
64
+ .claude/skills/*
65
+ !.claude/skills/check-pr/
66
+
67
+ # Knead orchestrator state
68
+ .knead/
69
+
70
+ # Local-mode harness session state (per-session workspace +
71
+ # Claude session map, bind-mounted into the harness + sandbox
72
+ # containers). Path is referenced from local_sandbox.py and
73
+ # docker-compose.yaml; safe to delete to wipe local sessions.
74
+ .levain-cache/
75
+
76
+ # Full-stack marker written by ``./levain init --all``.
77
+ .levain-full
78
+
79
+ # Nested repos (legacy, from old multi-repo setup)
80
+ repos/
81
+
82
+ # Local kubeconfig (legacy path — kubeconfig now lives in
83
+ # ~/.levain/proxy/<env>/kubeconfig). Kept ignored to clean up stale
84
+ # files from older checkouts.
85
+ .kube/
86
+
87
+ # Legacy proxy state (SSH keypair, PIDs). Superseded by
88
+ # ~/.levain/proxy/<env>/. Kept ignored so `git add .` on existing
89
+ # checkouts can't accidentally commit the private key.
90
+ .proxy/
91
+
92
+ # Next.js
93
+ .next/
94
+ next-env.d.ts
95
+
96
+ # Vite
97
+ .vite/
98
+
99
+ # Generated workspace file
100
+ levain.code-workspace
101
+ .gstack/
102
+ .env.local
103
+ .env.development.local
104
+ *.tsbuildinfo
105
+ .eslintcache
106
+ .playwright-mcp/
107
+
108
+ # issue2pr recipe→monitor IPC outcome file (transient, never committed —
109
+ # a tracked copy breaks every other branch's rebase via detach-HEAD conflicts)
110
+ .issue2pr/
111
+
112
+ # Generated PlusCal specs (scratch/example output)
113
+ specs/
114
+ .claude/scheduled_tasks.lock
115
+ .claude/worktrees/
116
+ kubeconfig
117
+
118
+ # Local TLC toolchain drop-in (CI extracts it from the ghcr carrier)
119
+ tools/tla2tools.jar
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.5
2
+ Name: levain-sdk
3
+ Version: 0.1.0
4
+ Summary: SDK for building Levain agent recipes
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.12
8
+ Requires-Dist: claude-agent-sdk==0.2.135
9
+ Requires-Dist: langchain-core==1.5.6
10
+ Provides-Extra: crawler
11
+ Requires-Dist: trafilatura==2.1.0; extra == 'crawler'
12
+ Provides-Extra: models
13
+ Requires-Dist: langchain-anthropic==1.4.3; extra == 'models'
14
+ Requires-Dist: langchain-openai==1.2.2; extra == 'models'
15
+ Provides-Extra: review
16
+ Requires-Dist: fastmcp==3.4.7; extra == 'review'
17
+ Requires-Dist: githubkit==0.16.0; extra == 'review'
18
+ Description-Content-Type: text/markdown
19
+
20
+ # levain-sdk
21
+
22
+ The Python interface that [Levain](https://levainlabs.com) agent
23
+ recipes are written against: node helpers, the agentic engine, state
24
+ reducers, and tool annotations.
25
+
26
+ A recipe's node functions import from `levain_sdk`, so this package is
27
+ what makes a cloned recipe installable and readable in your editor —
28
+ type checking, completion, and `uv sync` all resolve against it.
29
+ Agents execute on the Levain platform; this package defines the
30
+ contract, it does not run them.
31
+
32
+ ## Install
33
+
34
+ Recipe packages already declare `levain-sdk`, so inside a cloned
35
+ recipe:
36
+
37
+ ```
38
+ uv sync
39
+ ```
40
+
41
+ Or directly:
42
+
43
+ ```
44
+ pip install levain-sdk
45
+ ```
46
+
47
+ ### Extras
48
+
49
+ - `models` — direct (non-agentic) LLM calls via `levain_sdk.models`.
50
+ - `review` — helpers used by review-oriented recipes.
51
+ - `crawler` — main-content extraction for crawling recipes.
52
+
53
+ Most recipes need none of these; the error message will name the
54
+ extra if a module you import requires one.
55
+
56
+ ## Authoring recipes
57
+
58
+ Validation and code generation live in the companion tool,
59
+ [levain-cli](https://pypi.org/project/levain-cli/). The full authoring
60
+ guide is at [docs.levainlabs.com](https://docs.levainlabs.com).
61
+
62
+ ## License
63
+
64
+ Apache-2.0.
@@ -0,0 +1,45 @@
1
+ # levain-sdk
2
+
3
+ The Python interface that [Levain](https://levainlabs.com) agent
4
+ recipes are written against: node helpers, the agentic engine, state
5
+ reducers, and tool annotations.
6
+
7
+ A recipe's node functions import from `levain_sdk`, so this package is
8
+ what makes a cloned recipe installable and readable in your editor —
9
+ type checking, completion, and `uv sync` all resolve against it.
10
+ Agents execute on the Levain platform; this package defines the
11
+ contract, it does not run them.
12
+
13
+ ## Install
14
+
15
+ Recipe packages already declare `levain-sdk`, so inside a cloned
16
+ recipe:
17
+
18
+ ```
19
+ uv sync
20
+ ```
21
+
22
+ Or directly:
23
+
24
+ ```
25
+ pip install levain-sdk
26
+ ```
27
+
28
+ ### Extras
29
+
30
+ - `models` — direct (non-agentic) LLM calls via `levain_sdk.models`.
31
+ - `review` — helpers used by review-oriented recipes.
32
+ - `crawler` — main-content extraction for crawling recipes.
33
+
34
+ Most recipes need none of these; the error message will name the
35
+ extra if a module you import requires one.
36
+
37
+ ## Authoring recipes
38
+
39
+ Validation and code generation live in the companion tool,
40
+ [levain-cli](https://pypi.org/project/levain-cli/). The full authoring
41
+ guide is at [docs.levainlabs.com](https://docs.levainlabs.com).
42
+
43
+ ## License
44
+
45
+ Apache-2.0.
@@ -0,0 +1,47 @@
1
+ [project]
2
+ name = "levain-sdk"
3
+ version = "0.1.0"
4
+ description = "SDK for building Levain agent recipes"
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ # Kept to what a *recipe* needs to import, since a recipe's
10
+ # pyproject declares ``levain-sdk`` and nothing else. Recipe code
11
+ # imports ``levain_sdk`` and ``langchain_core`` (the node signature's
12
+ # RunnableConfig); everything heavier is an extra.
13
+ #
14
+ # Pre-PyPI TODO: relax the exact pins to ranges; ``==`` matches
15
+ # the repo's pin convention meanwhile.
16
+ dependencies = [
17
+ # levain_sdk.claude — the agentic node engine most recipes use.
18
+ "claude-agent-sdk==0.2.135",
19
+ # RunnableConfig is the recipe node signature contract, imported
20
+ # directly by recipe node code.
21
+ "langchain-core==1.5.6",
22
+ ]
23
+
24
+ [project.optional-dependencies]
25
+ # Direct (non-agentic) LLM calls — ``levain_sdk.models.call_chat`` and
26
+ # friends. An extra because 2 of 33 recipes call them, while the
27
+ # tree (anthropic, openai, tiktoken, …) is ~10 packages every recipe
28
+ # would otherwise install to author locally.
29
+ # (langchain-openai 1.2.2 is the newest line accepting the
30
+ # harness-pinned langchain-core; 1.3.0+ wants core>=1.4.3.)
31
+ models = ["langchain-anthropic==1.4.3", "langchain-openai==1.2.2"]
32
+ review = ["fastmcp==3.4.7", "githubkit==0.16.0"]
33
+ # ``crawler`` adds main-content extraction + HTML-to-Markdown for
34
+ # :mod:`levain_sdk.crawler`. Heavyweight (pulls lxml), so it stays
35
+ # opt-in — only the crawler platform agent needs it at runtime.
36
+ crawler = ["trafilatura==2.1.0"]
37
+
38
+ [build-system]
39
+ requires = ["hatchling"]
40
+ build-backend = "hatchling.build"
41
+
42
+ [tool.hatch.build.targets.wheel]
43
+ packages = ["src/levain_sdk"]
44
+
45
+ [tool.hatch.build.targets.sdist]
46
+ # Internal contributor docs stay out of the published sdist.
47
+ exclude = ["CLAUDE.md"]
@@ -0,0 +1,21 @@
1
+ """Levain Recipe SDK — helpers for recipe node functions.
2
+
3
+ Zero dependency on levain. Levain depends on the SDK,
4
+ not the other way around.
5
+ """
6
+
7
+ from .errors import (
8
+ AgentError,
9
+ GitHubAPIError,
10
+ KneadError,
11
+ OperationTimeoutError,
12
+ )
13
+ from .shell import run_checks
14
+
15
+ __all__ = [
16
+ "AgentError",
17
+ "GitHubAPIError",
18
+ "KneadError",
19
+ "OperationTimeoutError",
20
+ "run_checks",
21
+ ]
@@ -0,0 +1,30 @@
1
+ """Shared helper for FastMCP → ClaudeAgentOptions config.
2
+
3
+ Every platform MCP server (``levain-build``, ``knead-review``)
4
+ needs the same dance: pull the FastMCP
5
+ instance's private ``_mcp_server`` attribute and wrap it in the
6
+ ``McpSdkServerConfig`` shape the SDK expects. Kept central so a
7
+ FastMCP API change is patched in one place, not three.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Any
13
+
14
+
15
+ def sdk_mcp_config(mcp_instance: Any, server_name: str) -> dict[str, Any]:
16
+ """Return an in-process MCP server config for ``ClaudeAgentOptions``.
17
+
18
+ ``_mcp_server`` is a private attribute of FastMCP; re-verify
19
+ it exists when bumping the ``fastmcp`` pin (tested against
20
+ 3.1.1). A missing attribute means the FastMCP internals
21
+ moved and the caller needs to track the new shape.
22
+ """
23
+ server = getattr(mcp_instance, "_mcp_server", None)
24
+ if server is None or not hasattr(server, "run"):
25
+ raise RuntimeError(
26
+ f"FastMCP internal API changed — _mcp_server no longer "
27
+ f"exists or changed type (server={server_name!r}). Pin "
28
+ f"fastmcp to the version this was tested against."
29
+ )
30
+ return {"type": "sdk", "name": server_name, "instance": server}
@@ -0,0 +1,20 @@
1
+ """Agent-to-agent calling tools (the ``levain-agents`` MCP).
2
+
3
+ The ``call_agent`` tool lets an agent delegate a task to one of the
4
+ workspace's other agents. The tool only *signals* the request; the
5
+ recipe's worker-side ``CallAgent`` node performs the dispatch via
6
+ the harness A2A machinery (:mod:`levain.agent.harness.a2a`), so the
7
+ untrusted sandbox never reaches dispatch directly.
8
+
9
+ Lives in the customer SDK (moved from ``platform_sdk`` so it works on
10
+ the customer image — the managed Levain assistant is the first
11
+ consumer there, and A2A is a customer-facing capability anyway). The
12
+ worker still gates who may actually be called: dispatch authorizes
13
+ from the caller run's own context, never from the sandbox's claims.
14
+ """
15
+
16
+ # Env var the harness injects per turn with the JSON list of agents
17
+ # the Levain agent may call (base64). Read by the recipe's Respond
18
+ # node to render the choices into the prompt — discovery is
19
+ # prompt-side, not a tool round-trip.
20
+ ENV_CALLABLE_AGENTS = "LEVAIN_CALLABLE_AGENTS_B64"
@@ -0,0 +1,119 @@
1
+ """FastMCP server exposing the agent-to-agent ``call_agent`` tool.
2
+
3
+ Runs in-process inside the sandbox via stdio. Lets an agent
4
+ delegate a task to one of the workspace's other agents.
5
+
6
+ This is a *signal* tool, not an RPC client: calling it only records
7
+ the requested ``(agent, request)`` in a signal file. The Levain
8
+ recipe's ``Respond`` node reads that signal after the agent's SDK
9
+ session returns (:func:`consume_call`), routes the graph to a
10
+ ``CallAgent`` node, and that node — running in the **trusted
11
+ worker** — performs the dispatch via the harness A2A machinery and
12
+ feeds the result back into the next ``Respond`` turn. The untrusted
13
+ sandbox never reaches dispatch directly and never supplies the
14
+ caller's identity; the worker authorizes from the caller run's own
15
+ context. The tool call itself only records a module-level signal
16
+ that the node wrapper consumes after the agent returns.
17
+
18
+ Discovery is prompt-side: the worker injects the callable-agents
19
+ list into the ``Respond`` prompt, so there's no ``list_agents``
20
+ tool here.
21
+ """
22
+
23
+ from __future__ import annotations
24
+
25
+ import json
26
+ import logging
27
+ from dataclasses import dataclass
28
+ from pathlib import Path
29
+ from typing import Any
30
+
31
+ from fastmcp import FastMCP
32
+
33
+ from levain_sdk._mcp import sdk_mcp_config
34
+
35
+ log = logging.getLogger("knead")
36
+
37
+ mcp = FastMCP("levain-agents")
38
+
39
+
40
+ @dataclass
41
+ class _AgentCall:
42
+ """A delegation the Levain agent requested this turn."""
43
+
44
+ slug: str
45
+ request: str
46
+
47
+
48
+ # File-backed signal, written by ``call_agent`` and reset by ``init``
49
+ # on each Respond dispatch so a stale request can't leak across
50
+ # turns. Single-slot: the tool's contract is "call it, then wrap up",
51
+ # so at most one delegation per session (the recipe loops for more).
52
+ # A file rather than a module global because the server doesn't
53
+ # always share a process with the node that reads the signal: the
54
+ # Claude engine runs it in-process, but the Hermes engine runs it as
55
+ # a stdio subprocess (``levain_sdk.mcp_stdio``). Same pattern as the
56
+ # ``levain-memory`` queue.
57
+ _SIGNAL_PATH = Path("/tmp/levain-agents/call.json")
58
+
59
+
60
+ def init(repo_root: str = "", branch: str = "", iteration: int = 0) -> None:
61
+ """Reset the pending-call signal for this Respond dispatch."""
62
+ del repo_root, branch, iteration
63
+ _SIGNAL_PATH.unlink(missing_ok=True)
64
+
65
+
66
+ def consume_call() -> _AgentCall | None:
67
+ """Return the captured delegation, if any, and clear it."""
68
+ try:
69
+ raw = _SIGNAL_PATH.read_text(encoding="utf-8")
70
+ except FileNotFoundError:
71
+ return None
72
+ _SIGNAL_PATH.unlink(missing_ok=True)
73
+ try:
74
+ record = json.loads(raw)
75
+ except ValueError:
76
+ log.warning("CALL_AGENT unparseable signal file; ignoring")
77
+ return None
78
+ return _AgentCall(
79
+ slug=str(record.get("slug") or ""),
80
+ request=str(record.get("request") or ""),
81
+ )
82
+
83
+
84
+ @mcp.tool
85
+ async def call_agent(agent: str, request: str) -> dict[str, Any]:
86
+ """Hand a task to one of the workspace's other agents.
87
+
88
+ Use the ``agent`` slug from the list of available agents in your
89
+ instructions. ``request`` is what you want that agent to do, in
90
+ plain language — it's delivered as the agent's prompt.
91
+
92
+ Calling this **ends your current turn**: the agent runs and you
93
+ are re-invoked with its result, which you then use to answer.
94
+ The agent may take several minutes depending on the task, so
95
+ close your turn with a short note telling the user what you
96
+ handed off and that the answer is coming — don't also answer
97
+ the question yourself.
98
+ Call it only when an available agent clearly fits the task; do
99
+ not invent a slug.
100
+ """
101
+ slug = (agent or "").strip()
102
+ record = {"slug": slug, "request": (request or "").strip()}
103
+ _SIGNAL_PATH.parent.mkdir(parents=True, exist_ok=True)
104
+ _SIGNAL_PATH.write_text(json.dumps(record), encoding="utf-8")
105
+ log.info("CALL_AGENT delegation requested (agent=%r)", slug)
106
+ return {
107
+ "ok": True,
108
+ "message": (
109
+ f"Delegating to {slug!r}. Stop here — you'll be re-invoked "
110
+ "with the agent's result, which can take several minutes. "
111
+ "End your turn with a one-line heads-up that you've handed "
112
+ "this off; don't answer the question yourself."
113
+ ),
114
+ }
115
+
116
+
117
+ def create_agents_mcp_server() -> dict[str, Any]:
118
+ """Return an in-process MCP server config for ClaudeAgentOptions."""
119
+ return sdk_mcp_config(mcp, "levain-agents")
@@ -0,0 +1 @@
1
+ """Synced platform data — workspace-scoped query tools for agents."""