substrate-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.
- substrate_sdk-0.1.0/PKG-INFO +112 -0
- substrate_sdk-0.1.0/README.md +97 -0
- substrate_sdk-0.1.0/pyproject.toml +25 -0
- substrate_sdk-0.1.0/setup.cfg +4 -0
- substrate_sdk-0.1.0/setup.py +4 -0
- substrate_sdk-0.1.0/src/substrate/__init__.py +57 -0
- substrate_sdk-0.1.0/src/substrate/environment.py +2405 -0
- substrate_sdk-0.1.0/src/substrate_sdk.egg-info/PKG-INFO +112 -0
- substrate_sdk-0.1.0/src/substrate_sdk.egg-info/SOURCES.txt +10 -0
- substrate_sdk-0.1.0/src/substrate_sdk.egg-info/dependency_links.txt +1 -0
- substrate_sdk-0.1.0/src/substrate_sdk.egg-info/top_level.txt +2 -0
- substrate_sdk-0.1.0/tests/test_environment.py +3845 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: substrate-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the Substrate agent execution environment
|
|
5
|
+
Author: Substrate
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: agents,sandbox,tools,substrate
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# substrate
|
|
17
|
+
|
|
18
|
+
Python SDK for the Substrate agent execution environment.
|
|
19
|
+
|
|
20
|
+
Install:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install substrate-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The package is pure Python. It does not compile Rust during install. For local
|
|
27
|
+
managed execution, the SDK discovers a prebuilt `executioner` runtime from a
|
|
28
|
+
`binary_path` / `EXECUTIONER_BIN` override, an installed `substrate-runtime`
|
|
29
|
+
package, or `executioner` on `PATH`. Remote-host usage does not need a local
|
|
30
|
+
runtime.
|
|
31
|
+
|
|
32
|
+
The public API separates environment lifetime from session lifetime:
|
|
33
|
+
|
|
34
|
+
```py
|
|
35
|
+
from substrate import Environment
|
|
36
|
+
|
|
37
|
+
with Environment.create(workspace={"kind": "new"}, policy={"process": {"allowExec": True, "allowedCommands": ["ls"]}}) as env:
|
|
38
|
+
session = env.create_session()
|
|
39
|
+
session.write("hello.txt", "hello")
|
|
40
|
+
print(session.read("hello.txt"))
|
|
41
|
+
|
|
42
|
+
session.edit({
|
|
43
|
+
"path": "hello.txt",
|
|
44
|
+
"oldString": "hello",
|
|
45
|
+
"newString": "hello from Substrate",
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
print(session.bash("ls /workspace"))
|
|
49
|
+
files = session.list()
|
|
50
|
+
artifact = env.export_workspace()
|
|
51
|
+
env.materialize_workspace_artifact(artifact, "/tmp/restored-workspace")
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To join an environment created by another process or client, attach to it. An
|
|
55
|
+
attached handle can create sessions and submit tool calls, but it does not close
|
|
56
|
+
or destroy the environment when the handle is closed:
|
|
57
|
+
|
|
58
|
+
```py
|
|
59
|
+
env = Environment.attach(
|
|
60
|
+
host={"kind": "http", "baseUrl": "http://127.0.0.1:8765/"},
|
|
61
|
+
environmentId="env_shared",
|
|
62
|
+
)
|
|
63
|
+
try:
|
|
64
|
+
session = env.create_session()
|
|
65
|
+
session.write("client-a.txt", "hello")
|
|
66
|
+
finally:
|
|
67
|
+
env.close()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For an agent loop, pass Substrate's schemas into the model request, then execute
|
|
71
|
+
matching tool-use blocks directly:
|
|
72
|
+
|
|
73
|
+
```py
|
|
74
|
+
from anthropic import Anthropic
|
|
75
|
+
from substrate import Environment, tool_schemas
|
|
76
|
+
|
|
77
|
+
client = Anthropic()
|
|
78
|
+
messages = [{"role": "user", "content": "Create notes.txt and read it back."}]
|
|
79
|
+
|
|
80
|
+
with Environment.create(
|
|
81
|
+
workspace={"kind": "new"},
|
|
82
|
+
policy={"process": {"allowExec": True, "allowedCommands": ["python", "pytest"]}},
|
|
83
|
+
) as env:
|
|
84
|
+
session = env.create_session()
|
|
85
|
+
response = client.messages.create(
|
|
86
|
+
model="...",
|
|
87
|
+
max_tokens=1024,
|
|
88
|
+
tools=tool_schemas(),
|
|
89
|
+
messages=messages,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
for block in response.content:
|
|
93
|
+
if block.type == "tool_use":
|
|
94
|
+
result = session.execute({
|
|
95
|
+
"id": block.id,
|
|
96
|
+
"name": block.name,
|
|
97
|
+
"input": block.input,
|
|
98
|
+
})
|
|
99
|
+
messages.append({
|
|
100
|
+
"role": "user",
|
|
101
|
+
"content": [{
|
|
102
|
+
"type": "tool_result",
|
|
103
|
+
"tool_use_id": block.id,
|
|
104
|
+
"content": result.output,
|
|
105
|
+
}],
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The package hides the file-backed queue and worker transport, but keeps
|
|
110
|
+
environment and session lifecycles explicit. Multiple sessions can attach to the
|
|
111
|
+
same environment. The host serializes tool execution per environment so those
|
|
112
|
+
sessions share one mutable workspace through an ordered stream.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# substrate
|
|
2
|
+
|
|
3
|
+
Python SDK for the Substrate agent execution environment.
|
|
4
|
+
|
|
5
|
+
Install:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install substrate-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package is pure Python. It does not compile Rust during install. For local
|
|
12
|
+
managed execution, the SDK discovers a prebuilt `executioner` runtime from a
|
|
13
|
+
`binary_path` / `EXECUTIONER_BIN` override, an installed `substrate-runtime`
|
|
14
|
+
package, or `executioner` on `PATH`. Remote-host usage does not need a local
|
|
15
|
+
runtime.
|
|
16
|
+
|
|
17
|
+
The public API separates environment lifetime from session lifetime:
|
|
18
|
+
|
|
19
|
+
```py
|
|
20
|
+
from substrate import Environment
|
|
21
|
+
|
|
22
|
+
with Environment.create(workspace={"kind": "new"}, policy={"process": {"allowExec": True, "allowedCommands": ["ls"]}}) as env:
|
|
23
|
+
session = env.create_session()
|
|
24
|
+
session.write("hello.txt", "hello")
|
|
25
|
+
print(session.read("hello.txt"))
|
|
26
|
+
|
|
27
|
+
session.edit({
|
|
28
|
+
"path": "hello.txt",
|
|
29
|
+
"oldString": "hello",
|
|
30
|
+
"newString": "hello from Substrate",
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
print(session.bash("ls /workspace"))
|
|
34
|
+
files = session.list()
|
|
35
|
+
artifact = env.export_workspace()
|
|
36
|
+
env.materialize_workspace_artifact(artifact, "/tmp/restored-workspace")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
To join an environment created by another process or client, attach to it. An
|
|
40
|
+
attached handle can create sessions and submit tool calls, but it does not close
|
|
41
|
+
or destroy the environment when the handle is closed:
|
|
42
|
+
|
|
43
|
+
```py
|
|
44
|
+
env = Environment.attach(
|
|
45
|
+
host={"kind": "http", "baseUrl": "http://127.0.0.1:8765/"},
|
|
46
|
+
environmentId="env_shared",
|
|
47
|
+
)
|
|
48
|
+
try:
|
|
49
|
+
session = env.create_session()
|
|
50
|
+
session.write("client-a.txt", "hello")
|
|
51
|
+
finally:
|
|
52
|
+
env.close()
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For an agent loop, pass Substrate's schemas into the model request, then execute
|
|
56
|
+
matching tool-use blocks directly:
|
|
57
|
+
|
|
58
|
+
```py
|
|
59
|
+
from anthropic import Anthropic
|
|
60
|
+
from substrate import Environment, tool_schemas
|
|
61
|
+
|
|
62
|
+
client = Anthropic()
|
|
63
|
+
messages = [{"role": "user", "content": "Create notes.txt and read it back."}]
|
|
64
|
+
|
|
65
|
+
with Environment.create(
|
|
66
|
+
workspace={"kind": "new"},
|
|
67
|
+
policy={"process": {"allowExec": True, "allowedCommands": ["python", "pytest"]}},
|
|
68
|
+
) as env:
|
|
69
|
+
session = env.create_session()
|
|
70
|
+
response = client.messages.create(
|
|
71
|
+
model="...",
|
|
72
|
+
max_tokens=1024,
|
|
73
|
+
tools=tool_schemas(),
|
|
74
|
+
messages=messages,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
for block in response.content:
|
|
78
|
+
if block.type == "tool_use":
|
|
79
|
+
result = session.execute({
|
|
80
|
+
"id": block.id,
|
|
81
|
+
"name": block.name,
|
|
82
|
+
"input": block.input,
|
|
83
|
+
})
|
|
84
|
+
messages.append({
|
|
85
|
+
"role": "user",
|
|
86
|
+
"content": [{
|
|
87
|
+
"type": "tool_result",
|
|
88
|
+
"tool_use_id": block.id,
|
|
89
|
+
"content": result.output,
|
|
90
|
+
}],
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The package hides the file-backed queue and worker transport, but keeps
|
|
95
|
+
environment and session lifecycles explicit. Multiple sessions can attach to the
|
|
96
|
+
same environment. The host serializes tool execution per environment so those
|
|
97
|
+
sessions share one mutable workspace through an ordered stream.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "substrate-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for the Substrate agent execution environment"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Substrate" },
|
|
13
|
+
]
|
|
14
|
+
license = "MIT"
|
|
15
|
+
keywords = ["agents", "sandbox", "tools", "substrate"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from .environment import (
|
|
2
|
+
AttachedEnvironmentConfig,
|
|
3
|
+
AttachedHostConfig,
|
|
4
|
+
BackendConfig,
|
|
5
|
+
EditToolArguments,
|
|
6
|
+
EnvironmentInfo,
|
|
7
|
+
Environment,
|
|
8
|
+
Session,
|
|
9
|
+
HostConfig,
|
|
10
|
+
LifecycleConfig,
|
|
11
|
+
NetworkPolicyConfig,
|
|
12
|
+
PolicyConfig,
|
|
13
|
+
ProcessPolicyConfig,
|
|
14
|
+
ResourceRef,
|
|
15
|
+
SessionInfo,
|
|
16
|
+
StateEffect,
|
|
17
|
+
SubmitResult,
|
|
18
|
+
ToolCall,
|
|
19
|
+
ToolSchema,
|
|
20
|
+
ToolSubmitOptions,
|
|
21
|
+
WorkerConfig,
|
|
22
|
+
WorkspaceArtifact,
|
|
23
|
+
WorkspaceArtifactEntry,
|
|
24
|
+
WorkspaceConfig,
|
|
25
|
+
materialize_workspace_artifact,
|
|
26
|
+
tool,
|
|
27
|
+
tool_schemas,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"BackendConfig",
|
|
32
|
+
"AttachedEnvironmentConfig",
|
|
33
|
+
"AttachedHostConfig",
|
|
34
|
+
"EditToolArguments",
|
|
35
|
+
"EnvironmentInfo",
|
|
36
|
+
"Environment",
|
|
37
|
+
"Session",
|
|
38
|
+
"HostConfig",
|
|
39
|
+
"LifecycleConfig",
|
|
40
|
+
"NetworkPolicyConfig",
|
|
41
|
+
"PolicyConfig",
|
|
42
|
+
"ProcessPolicyConfig",
|
|
43
|
+
"ResourceRef",
|
|
44
|
+
"SessionInfo",
|
|
45
|
+
"StateEffect",
|
|
46
|
+
"SubmitResult",
|
|
47
|
+
"ToolCall",
|
|
48
|
+
"ToolSchema",
|
|
49
|
+
"ToolSubmitOptions",
|
|
50
|
+
"WorkerConfig",
|
|
51
|
+
"WorkspaceArtifact",
|
|
52
|
+
"WorkspaceArtifactEntry",
|
|
53
|
+
"WorkspaceConfig",
|
|
54
|
+
"materialize_workspace_artifact",
|
|
55
|
+
"tool",
|
|
56
|
+
"tool_schemas",
|
|
57
|
+
]
|