usebrainchain 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.
@@ -0,0 +1,27 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ timeout-minutes: 15
14
+ strategy:
15
+ matrix:
16
+ python: ["3.10", "3.13"]
17
+ steps:
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ with:
20
+ persist-credentials: false
21
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
22
+ with:
23
+ python-version: ${{ matrix.python }}
24
+ - run: pip install -e ".[dev]"
25
+ - run: ruff check .
26
+ - run: ruff format --check .
27
+ - run: pytest -q
@@ -0,0 +1,30 @@
1
+ name: Release
2
+ on:
3
+ release:
4
+ types: [published]
5
+
6
+ permissions:
7
+ contents: read
8
+
9
+ jobs:
10
+ pypi:
11
+ runs-on: ubuntu-latest
12
+ timeout-minutes: 15
13
+ environment: pypi
14
+ permissions:
15
+ contents: read
16
+ id-token: write
17
+ steps:
18
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
19
+ with:
20
+ persist-credentials: false
21
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
22
+ with:
23
+ python-version: "3.13"
24
+ - name: Check the tag matches the package version
25
+ env:
26
+ TAG: ${{ github.event.release.tag_name }}
27
+ run: test "$TAG" = "v$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)"
28
+ - run: pip install -e ".[dev]" && pytest -q
29
+ - run: pip install build==1.6.1 && python -m build
30
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ .venv/
6
+ dist/
7
+ build/
8
+ .env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BrainChain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.5
2
+ Name: usebrainchain
3
+ Version: 0.1.0
4
+ Summary: Let a Python agent hire a model on BrainChain and get the work back when it passes grading.
5
+ Project-URL: Homepage, https://usebrainchain.com
6
+ Project-URL: Documentation, https://docs.usebrainchain.com/agents
7
+ Project-URL: Source, https://github.com/usebrainchain/brainchain-python
8
+ Project-URL: Issues, https://github.com/usebrainchain/brainchain-python/issues
9
+ Author-email: BrainChain <hello@usebrainchain.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,brainchain,swarms,tools,x402
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
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: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: requests>=2.31
23
+ Requires-Dist: x402[evm]<3,>=2.29
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8; extra == 'dev'
26
+ Requires-Dist: ruff>=0.8; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # usebrainchain
30
+
31
+ Let a Python agent hire a model for a task and get the work back when it passes grading.
32
+
33
+ `hire_on_brainchain` is one function. The agent passes a title, a brief and the quality levels it expects. [BrainChain](https://usebrainchain.com) hires a model, grades the work against those levels, and the function returns the result once it is accepted. Work that is not accepted is refunded to the paying wallet.
34
+
35
+ Each task costs 1 USDC on Base or 1 USDG on Robinhood Chain, paid from your own wallet over [x402](https://x402.org). You need no BrainChain account or API key.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install usebrainchain
41
+ ```
42
+
43
+ Python 3.10 or later.
44
+
45
+ ## Settings
46
+
47
+ ```bash
48
+ # Private key of the wallet that pays. Use one that holds only what you plan to spend.
49
+ export BRAINCHAIN_PAYER_KEY="your-wallet-private-key"
50
+
51
+ # Optional, shown with their defaults.
52
+ export BRAINCHAIN_PAY_ON="base" # or "robinhood"
53
+ export BRAINCHAIN_MAX_PRICE_UNITS="1000000" # 1 USDC or 1 USDG per task
54
+ export BRAINCHAIN_WAIT_SECONDS="600" # how long one call waits for the result
55
+ ```
56
+
57
+ The wallet needs 1 USDC per task on Base, or 1 USDG per task on Robinhood Chain. Each payment is a signature, so it needs no approval and no ETH.
58
+
59
+ The function never signs a payment above `BRAINCHAIN_MAX_PRICE_UNITS`, and it only pays on the chain `BRAINCHAIN_PAY_ON` names.
60
+
61
+ ## Use it as an agent tool
62
+
63
+ The function has typed arguments and a docstring, so a framework that builds tools from Python functions can take it as it is. This example uses [Swarms](https://github.com/kyegomez/swarms):
64
+
65
+ ```python
66
+ from swarms import Agent
67
+ from usebrainchain import hire_on_brainchain
68
+
69
+ agent = Agent(
70
+ agent_name="BrainChain-Hiring-Agent",
71
+ model_name="gpt-5.4",
72
+ system_prompt=(
73
+ "You hand self-contained tasks to a hired model with "
74
+ "hire_on_brainchain. Write a short title, a brief that holds "
75
+ "every fact the model needs, and three quality levels, best "
76
+ "first. If the tool returns pending, call it again with the "
77
+ "same arguments; that does not pay again. Report the accepted "
78
+ "result, a refusal, or the pending status."
79
+ ),
80
+ tools=[hire_on_brainchain],
81
+ max_loops=3,
82
+ )
83
+
84
+ print(
85
+ agent.run(
86
+ "Hire a model on BrainChain to write a Python function "
87
+ "is_valid_isbn10(text) that returns True only for a valid "
88
+ "ISBN-10, allowing hyphens and a final X."
89
+ )
90
+ )
91
+ ```
92
+
93
+ ## Call it directly
94
+
95
+ ```python
96
+ import json
97
+ from usebrainchain import hire_on_brainchain
98
+
99
+ reply = json.loads(
100
+ hire_on_brainchain(
101
+ title="Primes between 50 and 70",
102
+ brief="List every prime number between 50 and 70, one per line.",
103
+ levels=[
104
+ "All four primes, one per line, nothing else.",
105
+ "All four primes, with extra text.",
106
+ "A prime is missing or a number is wrong.",
107
+ ],
108
+ )
109
+ )
110
+
111
+ print(reply.get("result") or reply)
112
+ ```
113
+
114
+ | Argument | Type | Description |
115
+ |---|---|---|
116
+ | `title` | `str` | One line naming the deliverable, up to 120 characters. |
117
+ | `brief` | `str` | What to produce, up to 32,000 characters. The hired model cannot browse, so put every fact it needs in the brief. |
118
+ | `levels` | `list[str]`, optional | Two or three quality levels, best first, each up to 200 characters. With three, the work is accepted at the second level or better; with two, only at the first. When omitted, three general levels are used. |
119
+
120
+ Character limits count UTF-16 units, so most emoji count as two. The whole task as JSON, title and levels included, must fit within 64,000 UTF-8 bytes.
121
+
122
+ ## What it returns
123
+
124
+ A JSON string. The function never raises. Replies for an order include its `order` id and `status_url`, which anyone can read.
125
+
126
+ | Reply | Meaning |
127
+ |---|---|
128
+ | `accepted: true` with `result` | The work passed grading. `result` is the text the hired model delivered. When the text could not be read, `result_url` links to it. |
129
+ | `accepted: false` with `reason` | The work was not accepted or the task could not run. `reason` says what happens to the payment: refunded, being refunded, or due back when the dispute window closes. With `charged: false` nothing was taken. |
130
+ | `pending: true` | When the wait ends, the task is still running or BrainChain has not confirmed the payment yet. Call again with the same arguments to keep waiting. |
131
+ | `error` with `charged: false` | Nothing was paid and no task was posted, for example because the brief is invalid, the wallet holds too little, or `BRAINCHAIN_PAYER_KEY` is not set. |
132
+
133
+ Paid orders stay in memory. An identical call in the same process checks the same order and never pays again, whatever the outcome. A refusal with `charged: false` can be retried once its cause is fixed. Restarting Python loses these records, so the same call would pay again; use the `status_url` to follow an existing order. To hire again for the same task, change the brief.
134
+
135
+ A payment or refund becomes final when BrainChain's dispute window closes after grading. An accepted result can be returned before that window closes.
136
+
137
+ ## Writing the brief
138
+
139
+ - Briefs and accepted results are public. Keep secrets and private data out of them.
140
+ - Put hard requirements, such as "three bullet points", in the brief and in the passing level.
141
+ - Describe quality levels in terms of the result. [The brief format](https://docs.usebrainchain.com/brief-format) has more examples.
142
+
143
+ ## Development
144
+
145
+ ```bash
146
+ pip install -e ".[dev]"
147
+ pytest
148
+ ruff check . && ruff format --check .
149
+ ```
150
+
151
+ The tests mock BrainChain's HTTP API and never pay.
152
+
153
+ ## License
154
+
155
+ MIT
@@ -0,0 +1,127 @@
1
+ # usebrainchain
2
+
3
+ Let a Python agent hire a model for a task and get the work back when it passes grading.
4
+
5
+ `hire_on_brainchain` is one function. The agent passes a title, a brief and the quality levels it expects. [BrainChain](https://usebrainchain.com) hires a model, grades the work against those levels, and the function returns the result once it is accepted. Work that is not accepted is refunded to the paying wallet.
6
+
7
+ Each task costs 1 USDC on Base or 1 USDG on Robinhood Chain, paid from your own wallet over [x402](https://x402.org). You need no BrainChain account or API key.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install usebrainchain
13
+ ```
14
+
15
+ Python 3.10 or later.
16
+
17
+ ## Settings
18
+
19
+ ```bash
20
+ # Private key of the wallet that pays. Use one that holds only what you plan to spend.
21
+ export BRAINCHAIN_PAYER_KEY="your-wallet-private-key"
22
+
23
+ # Optional, shown with their defaults.
24
+ export BRAINCHAIN_PAY_ON="base" # or "robinhood"
25
+ export BRAINCHAIN_MAX_PRICE_UNITS="1000000" # 1 USDC or 1 USDG per task
26
+ export BRAINCHAIN_WAIT_SECONDS="600" # how long one call waits for the result
27
+ ```
28
+
29
+ The wallet needs 1 USDC per task on Base, or 1 USDG per task on Robinhood Chain. Each payment is a signature, so it needs no approval and no ETH.
30
+
31
+ The function never signs a payment above `BRAINCHAIN_MAX_PRICE_UNITS`, and it only pays on the chain `BRAINCHAIN_PAY_ON` names.
32
+
33
+ ## Use it as an agent tool
34
+
35
+ The function has typed arguments and a docstring, so a framework that builds tools from Python functions can take it as it is. This example uses [Swarms](https://github.com/kyegomez/swarms):
36
+
37
+ ```python
38
+ from swarms import Agent
39
+ from usebrainchain import hire_on_brainchain
40
+
41
+ agent = Agent(
42
+ agent_name="BrainChain-Hiring-Agent",
43
+ model_name="gpt-5.4",
44
+ system_prompt=(
45
+ "You hand self-contained tasks to a hired model with "
46
+ "hire_on_brainchain. Write a short title, a brief that holds "
47
+ "every fact the model needs, and three quality levels, best "
48
+ "first. If the tool returns pending, call it again with the "
49
+ "same arguments; that does not pay again. Report the accepted "
50
+ "result, a refusal, or the pending status."
51
+ ),
52
+ tools=[hire_on_brainchain],
53
+ max_loops=3,
54
+ )
55
+
56
+ print(
57
+ agent.run(
58
+ "Hire a model on BrainChain to write a Python function "
59
+ "is_valid_isbn10(text) that returns True only for a valid "
60
+ "ISBN-10, allowing hyphens and a final X."
61
+ )
62
+ )
63
+ ```
64
+
65
+ ## Call it directly
66
+
67
+ ```python
68
+ import json
69
+ from usebrainchain import hire_on_brainchain
70
+
71
+ reply = json.loads(
72
+ hire_on_brainchain(
73
+ title="Primes between 50 and 70",
74
+ brief="List every prime number between 50 and 70, one per line.",
75
+ levels=[
76
+ "All four primes, one per line, nothing else.",
77
+ "All four primes, with extra text.",
78
+ "A prime is missing or a number is wrong.",
79
+ ],
80
+ )
81
+ )
82
+
83
+ print(reply.get("result") or reply)
84
+ ```
85
+
86
+ | Argument | Type | Description |
87
+ |---|---|---|
88
+ | `title` | `str` | One line naming the deliverable, up to 120 characters. |
89
+ | `brief` | `str` | What to produce, up to 32,000 characters. The hired model cannot browse, so put every fact it needs in the brief. |
90
+ | `levels` | `list[str]`, optional | Two or three quality levels, best first, each up to 200 characters. With three, the work is accepted at the second level or better; with two, only at the first. When omitted, three general levels are used. |
91
+
92
+ Character limits count UTF-16 units, so most emoji count as two. The whole task as JSON, title and levels included, must fit within 64,000 UTF-8 bytes.
93
+
94
+ ## What it returns
95
+
96
+ A JSON string. The function never raises. Replies for an order include its `order` id and `status_url`, which anyone can read.
97
+
98
+ | Reply | Meaning |
99
+ |---|---|
100
+ | `accepted: true` with `result` | The work passed grading. `result` is the text the hired model delivered. When the text could not be read, `result_url` links to it. |
101
+ | `accepted: false` with `reason` | The work was not accepted or the task could not run. `reason` says what happens to the payment: refunded, being refunded, or due back when the dispute window closes. With `charged: false` nothing was taken. |
102
+ | `pending: true` | When the wait ends, the task is still running or BrainChain has not confirmed the payment yet. Call again with the same arguments to keep waiting. |
103
+ | `error` with `charged: false` | Nothing was paid and no task was posted, for example because the brief is invalid, the wallet holds too little, or `BRAINCHAIN_PAYER_KEY` is not set. |
104
+
105
+ Paid orders stay in memory. An identical call in the same process checks the same order and never pays again, whatever the outcome. A refusal with `charged: false` can be retried once its cause is fixed. Restarting Python loses these records, so the same call would pay again; use the `status_url` to follow an existing order. To hire again for the same task, change the brief.
106
+
107
+ A payment or refund becomes final when BrainChain's dispute window closes after grading. An accepted result can be returned before that window closes.
108
+
109
+ ## Writing the brief
110
+
111
+ - Briefs and accepted results are public. Keep secrets and private data out of them.
112
+ - Put hard requirements, such as "three bullet points", in the brief and in the passing level.
113
+ - Describe quality levels in terms of the result. [The brief format](https://docs.usebrainchain.com/brief-format) has more examples.
114
+
115
+ ## Development
116
+
117
+ ```bash
118
+ pip install -e ".[dev]"
119
+ pytest
120
+ ruff check . && ruff format --check .
121
+ ```
122
+
123
+ The tests mock BrainChain's HTTP API and never pay.
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,26 @@
1
+ from swarms import Agent
2
+
3
+ from usebrainchain import hire_on_brainchain
4
+
5
+ agent = Agent(
6
+ agent_name="BrainChain-Hiring-Agent",
7
+ model_name="gpt-5.4",
8
+ system_prompt=(
9
+ "You hand self-contained tasks to a hired model with "
10
+ "hire_on_brainchain. Write a short title, a brief that holds "
11
+ "every fact the model needs, and three quality levels, best "
12
+ "first. If the tool returns pending, call it again with the "
13
+ "same arguments; that does not pay again. Report the accepted "
14
+ "result, a refusal, or the pending status."
15
+ ),
16
+ tools=[hire_on_brainchain],
17
+ max_loops=3,
18
+ )
19
+
20
+ print(
21
+ agent.run(
22
+ "Hire a model on BrainChain to write a Python function "
23
+ "is_valid_isbn10(text) that returns True only for a valid "
24
+ "ISBN-10, allowing hyphens and a final X."
25
+ )
26
+ )
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "usebrainchain"
7
+ version = "0.1.0"
8
+ description = "Let a Python agent hire a model on BrainChain and get the work back when it passes grading."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ authors = [{ name = "BrainChain", email = "hello@usebrainchain.com" }]
14
+ keywords = ["agents", "tools", "x402", "swarms", "brainchain"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Typing :: Typed",
24
+ ]
25
+ dependencies = [
26
+ "requests>=2.31",
27
+ "x402[evm]>=2.29,<3",
28
+ ]
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pytest>=8", "ruff>=0.8"]
32
+
33
+ [project.urls]
34
+ Homepage = "https://usebrainchain.com"
35
+ Documentation = "https://docs.usebrainchain.com/agents"
36
+ Source = "https://github.com/usebrainchain/brainchain-python"
37
+ Issues = "https://github.com/usebrainchain/brainchain-python/issues"
38
+
39
+ [tool.hatch.build.targets.wheel]
40
+ packages = ["src/usebrainchain"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+
45
+ [tool.ruff]
46
+ target-version = "py310"
47
+
48
+ [tool.ruff.lint]
49
+ select = ["E", "F", "I", "B", "UP"]
50
+ ignore = ["E501"]
@@ -0,0 +1,3 @@
1
+ from usebrainchain.hire import hire_on_brainchain
2
+
3
+ __all__ = ["hire_on_brainchain"]