futuresearch-btf 0.5.4__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,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,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: futuresearch-btf
3
+ Version: 0.5.4
4
+ Summary: Offline research tools for BTF-3 open: BM25 search and paged reading over a question's frozen open corpus, an MCP server, a reference agent and a scorer.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://evals.futuresearch.ai/btf3-open
7
+ Project-URL: Repository, https://github.com/futuresearch/futuresearch-btf
8
+ Project-URL: Dataset, https://huggingface.co/datasets/futuresearch-ai/BTF-3-open
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE-code.txt
12
+ Requires-Dist: numpy
13
+ Requires-Dist: pandas>=2.0
14
+ Requires-Dist: pyarrow
15
+ Requires-Dist: tantivy==0.27.0
16
+ Provides-Extra: mcp
17
+ Requires-Dist: mcp>=1.2; extra == "mcp"
18
+ Provides-Extra: agent
19
+ Requires-Dist: litellm>=1.106; extra == "agent"
20
+ Requires-Dist: mcp>=1.2; extra == "agent"
21
+ Dynamic: license-file
22
+
23
+ # futuresearch-btf
24
+
25
+ Run and score a forecasting agent on [BTF-3 open](https://evals.futuresearch.ai/btf3-open) offline. BTF-3 open is
26
+ the open subset of Bench to the Future 3. Its questions have already resolved. Your agent researches each one using
27
+ only web pages captured before the question was asked, so you can score its forecasts straight away instead of
28
+ waiting months for the outcome.
29
+
30
+ `futuresearch-btf` gives your agent BM25 search and paged reading over those pages. It also has an MCP server, a reference
31
+ agent and a scorer. It never touches the live web.
32
+
33
+ The data is on Hugging Face: the questions in
34
+ [futuresearch-ai/BTF-3-open](https://huggingface.co/datasets/futuresearch-ai/BTF-3-open) and the pages in
35
+ [futuresearch-ai/BTF-3-open-corpus](https://huggingface.co/datasets/futuresearch-ai/BTF-3-open-corpus).
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install "futuresearch-btf[agent]"
41
+ ```
42
+
43
+ You need Python 3.11 or newer. The `agent` extra adds the reference agent (through LiteLLM) and the MCP server.
44
+ Use `futuresearch-btf[mcp]` if you only want the MCP server, or plain `futuresearch-btf` for search and scoring.
45
+
46
+ ## Download the data
47
+
48
+ Accept the access form on both dataset pages first, then:
49
+
50
+ ```bash
51
+ pip install -U huggingface_hub
52
+ hf auth login
53
+ hf download futuresearch-ai/BTF-3-open --repo-type dataset --local-dir btf3open
54
+ hf download futuresearch-ai/BTF-3-open-corpus --repo-type dataset --local-dir btf3open/corpus
55
+ ```
56
+
57
+ The download is about 8 GB. The first search builds an index of about 5 GB in a `.btf_index` folder inside the
58
+ download folder, which takes about five minutes. Later searches take about a second.
59
+
60
+ ## Run a model
61
+
62
+ ```bash
63
+ # list the questions, and search the pages one question was allowed to see
64
+ python -m futuresearch_btf questions --data btf3open | head
65
+ python -m futuresearch_btf search --data btf3open --question-id <question_id> "your query"
66
+
67
+ # run the reference agent on two questions and score it
68
+ export ANTHROPIC_API_KEY=...
69
+ python -m futuresearch_btf run --data btf3open --model anthropic/claude-sonnet-5 --question-ids <id1> <id2> --out runs/sonnet.jsonl
70
+ python -m futuresearch_btf score --data btf3open --runs runs/sonnet.jsonl
71
+
72
+ # the same questions with no research, as a baseline
73
+ python -m futuresearch_btf run --data btf3open --model anthropic/claude-sonnet-5 --closed-book --question-ids <id1> <id2> --out runs/sonnet-closed.jsonl
74
+ ```
75
+
76
+ `--model` takes any LiteLLM model string, such as `openai/gpt-6-astra` with `OPENAI_API_KEY` set. Drop
77
+ `--question-ids` to run every question. A rerun with the same `--out` skips the questions already done.
78
+
79
+ Each forecast is a probability that the question resolves YES, scored by its Brier score. Lower is better, and
80
+ forecasting 50% on everything scores 0.25. A research run costs from a few cents to a few dollars a question,
81
+ depending on the model, so try a few questions before running them all.
82
+
83
+ ## Use your own agent
84
+
85
+ - `python -m futuresearch_btf serve --data btf3open --question-id <id> --out forecast.json` starts an MCP server for
86
+ one question, with the tools `get_question`, `search`, `read_page` and `submit_forecast`.
87
+ - `python -m futuresearch_btf serve-http --data btf3open` serves every question over HTTP.
88
+ - [`examples/`](https://github.com/futuresearch/futuresearch-btf/tree/main/examples) has harnesses for the OpenAI and
89
+ Anthropic SDKs.
90
+
91
+ [INTEGRATING.md](https://github.com/futuresearch/futuresearch-btf/blob/main/INTEGRATING.md) says what to show the
92
+ model, what to send back, how forecasts are scored and what to report with a result.
93
+
94
+ ## Licence
95
+
96
+ The code is under Apache-2.0 (`LICENSE-code.txt`). The questions and the pages have their own licences, given on
97
+ each dataset's page. [CHANGELOG.md](https://github.com/futuresearch/futuresearch-btf/blob/main/CHANGELOG.md) lists what
98
+ changed between versions.
@@ -0,0 +1,76 @@
1
+ # futuresearch-btf
2
+
3
+ Run and score a forecasting agent on [BTF-3 open](https://evals.futuresearch.ai/btf3-open) offline. BTF-3 open is
4
+ the open subset of Bench to the Future 3. Its questions have already resolved. Your agent researches each one using
5
+ only web pages captured before the question was asked, so you can score its forecasts straight away instead of
6
+ waiting months for the outcome.
7
+
8
+ `futuresearch-btf` gives your agent BM25 search and paged reading over those pages. It also has an MCP server, a reference
9
+ agent and a scorer. It never touches the live web.
10
+
11
+ The data is on Hugging Face: the questions in
12
+ [futuresearch-ai/BTF-3-open](https://huggingface.co/datasets/futuresearch-ai/BTF-3-open) and the pages in
13
+ [futuresearch-ai/BTF-3-open-corpus](https://huggingface.co/datasets/futuresearch-ai/BTF-3-open-corpus).
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install "futuresearch-btf[agent]"
19
+ ```
20
+
21
+ You need Python 3.11 or newer. The `agent` extra adds the reference agent (through LiteLLM) and the MCP server.
22
+ Use `futuresearch-btf[mcp]` if you only want the MCP server, or plain `futuresearch-btf` for search and scoring.
23
+
24
+ ## Download the data
25
+
26
+ Accept the access form on both dataset pages first, then:
27
+
28
+ ```bash
29
+ pip install -U huggingface_hub
30
+ hf auth login
31
+ hf download futuresearch-ai/BTF-3-open --repo-type dataset --local-dir btf3open
32
+ hf download futuresearch-ai/BTF-3-open-corpus --repo-type dataset --local-dir btf3open/corpus
33
+ ```
34
+
35
+ The download is about 8 GB. The first search builds an index of about 5 GB in a `.btf_index` folder inside the
36
+ download folder, which takes about five minutes. Later searches take about a second.
37
+
38
+ ## Run a model
39
+
40
+ ```bash
41
+ # list the questions, and search the pages one question was allowed to see
42
+ python -m futuresearch_btf questions --data btf3open | head
43
+ python -m futuresearch_btf search --data btf3open --question-id <question_id> "your query"
44
+
45
+ # run the reference agent on two questions and score it
46
+ export ANTHROPIC_API_KEY=...
47
+ python -m futuresearch_btf run --data btf3open --model anthropic/claude-sonnet-5 --question-ids <id1> <id2> --out runs/sonnet.jsonl
48
+ python -m futuresearch_btf score --data btf3open --runs runs/sonnet.jsonl
49
+
50
+ # the same questions with no research, as a baseline
51
+ python -m futuresearch_btf run --data btf3open --model anthropic/claude-sonnet-5 --closed-book --question-ids <id1> <id2> --out runs/sonnet-closed.jsonl
52
+ ```
53
+
54
+ `--model` takes any LiteLLM model string, such as `openai/gpt-6-astra` with `OPENAI_API_KEY` set. Drop
55
+ `--question-ids` to run every question. A rerun with the same `--out` skips the questions already done.
56
+
57
+ Each forecast is a probability that the question resolves YES, scored by its Brier score. Lower is better, and
58
+ forecasting 50% on everything scores 0.25. A research run costs from a few cents to a few dollars a question,
59
+ depending on the model, so try a few questions before running them all.
60
+
61
+ ## Use your own agent
62
+
63
+ - `python -m futuresearch_btf serve --data btf3open --question-id <id> --out forecast.json` starts an MCP server for
64
+ one question, with the tools `get_question`, `search`, `read_page` and `submit_forecast`.
65
+ - `python -m futuresearch_btf serve-http --data btf3open` serves every question over HTTP.
66
+ - [`examples/`](https://github.com/futuresearch/futuresearch-btf/tree/main/examples) has harnesses for the OpenAI and
67
+ Anthropic SDKs.
68
+
69
+ [INTEGRATING.md](https://github.com/futuresearch/futuresearch-btf/blob/main/INTEGRATING.md) says what to show the
70
+ model, what to send back, how forecasts are scored and what to report with a result.
71
+
72
+ ## Licence
73
+
74
+ The code is under Apache-2.0 (`LICENSE-code.txt`). The questions and the pages have their own licences, given on
75
+ each dataset's page. [CHANGELOG.md](https://github.com/futuresearch/futuresearch-btf/blob/main/CHANGELOG.md) lists what
76
+ changed between versions.
@@ -0,0 +1,27 @@
1
+ """Offline research tools for Bench to the Future releases: search, read, forecast, score.
2
+
3
+ The stable API (see INTEGRATING.md): `Release` (questions, prompts, tool calls),
4
+ `schemas` (tool definitions for OpenAI, Anthropic or MCP), `ToolResult`, `ERROR_CODES`,
5
+ `UnknownQuestion`, `render` and `validate`; `futuresearch_btf.score.score` scores a run file.
6
+ """
7
+
8
+ __version__ = "0.5.4"
9
+
10
+ # the module (not the function), so futuresearch_btf.score.score works after `import futuresearch_btf`;
11
+ # re-exported by the alias, not __all__
12
+ from . import score as score
13
+ from .corpus import QuestionView, Release, UnknownQuestion
14
+ from .prompt import render, validate
15
+ from .tools import ERROR_CODES, ToolResult, schemas
16
+
17
+ __all__ = [
18
+ "ERROR_CODES",
19
+ "QuestionView",
20
+ "Release",
21
+ "ToolResult",
22
+ "UnknownQuestion",
23
+ "__version__",
24
+ "render",
25
+ "schemas",
26
+ "validate",
27
+ ]
@@ -0,0 +1,261 @@
1
+ """futuresearch_btf command line: questions, search, serve, serve-http, run, schemas, score."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import importlib
7
+ import json
8
+ import os
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ from .tools import LATEST_TOOLSET, TOOLSETS
13
+
14
+ DATA_HELP = "the release directory"
15
+ TOOLSET_HELP = (
16
+ f"tool definitions: {LATEST_TOOLSET} (default), 2 (as in 0.4.x) "
17
+ "or 1 (as in 0.2.1 to 0.3.x)"
18
+ )
19
+
20
+
21
+ def _need(module: str, extra: str) -> None:
22
+ """Exit with the install command when the optional dependency `module` is missing."""
23
+ try:
24
+ importlib.import_module(module)
25
+ except ModuleNotFoundError:
26
+ raise SystemExit(
27
+ f'this command needs {module}: pip install "futuresearch-btf[{extra}]"'
28
+ ) from None
29
+
30
+
31
+ def main() -> None:
32
+ try:
33
+ _main()
34
+ sys.stdout.flush()
35
+ except BrokenPipeError:
36
+ # the reader closed the pipe early (e.g. `| head`): exit without a traceback
37
+ os.dup2(os.open(os.devnull, os.O_WRONLY), sys.stdout.fileno())
38
+ sys.exit(1)
39
+
40
+
41
+ def _main() -> None:
42
+ ap = argparse.ArgumentParser(prog="python -m futuresearch_btf")
43
+ sub = ap.add_subparsers(dest="cmd", required=True)
44
+
45
+ qs = sub.add_parser("questions", help="list the question ids, types and questions")
46
+ qs.add_argument("--data", type=Path, required=True, help=DATA_HELP)
47
+
48
+ s = sub.add_parser(
49
+ "search",
50
+ help="run the search tool for one question, as a model would; one JSON line per result",
51
+ )
52
+ s.add_argument("--data", type=Path, required=True, help=DATA_HELP)
53
+ s.add_argument("--question-id", required=True)
54
+ s.add_argument("query")
55
+ s.add_argument(
56
+ "-k",
57
+ type=int,
58
+ default=10,
59
+ help="max_results, as a model would send it (default 10, at most 50)",
60
+ )
61
+ s.add_argument(
62
+ "--toolset",
63
+ type=int,
64
+ choices=sorted(TOOLSETS),
65
+ default=LATEST_TOOLSET,
66
+ help=TOOLSET_HELP,
67
+ )
68
+
69
+ v = sub.add_parser("serve", help="MCP server (stdio) for one question")
70
+ v.add_argument("--data", type=Path, required=True, help=DATA_HELP)
71
+ v.add_argument("--question-id", required=True)
72
+ v.add_argument(
73
+ "--out",
74
+ type=Path,
75
+ required=True,
76
+ help="where submit_forecast writes the forecast JSON",
77
+ )
78
+
79
+ r = sub.add_parser("run", help="reference agent over LiteLLM")
80
+ r.add_argument("--data", type=Path, required=True, help=DATA_HELP)
81
+ r.add_argument(
82
+ "--model",
83
+ required=True,
84
+ help="a LiteLLM model string, e.g. anthropic/claude-sonnet-5",
85
+ )
86
+ r.add_argument(
87
+ "--out",
88
+ type=Path,
89
+ required=True,
90
+ help="JSONL of forecasts; reruns skip finished questions",
91
+ )
92
+ r.add_argument(
93
+ "--question-ids", nargs="+", help="default: every question in the release"
94
+ )
95
+ r.add_argument("--max-turns", type=int, default=30)
96
+ r.add_argument(
97
+ "--llm-kwargs",
98
+ default="{}",
99
+ help="JSON passed to litellm.completion, e.g. '{\"temperature\": 0}'",
100
+ )
101
+ r.add_argument(
102
+ "--closed-book",
103
+ action="store_true",
104
+ help="no-research baseline: only submit_forecast, no search or reader",
105
+ )
106
+ r.add_argument(
107
+ "--transcripts",
108
+ type=Path,
109
+ help="directory for each question's full conversation, as <question_id>.json",
110
+ )
111
+ r.add_argument(
112
+ "--toolset",
113
+ type=int,
114
+ choices=sorted(TOOLSETS),
115
+ default=LATEST_TOOLSET,
116
+ help=TOOLSET_HELP,
117
+ )
118
+ r.add_argument(
119
+ "--model-cutoff", help="the model's training data cutoff, recorded on each line"
120
+ )
121
+
122
+ h = sub.add_parser(
123
+ "schemas", help="print the tool definitions for a function-calling API, as JSON"
124
+ )
125
+ h.add_argument(
126
+ "--format",
127
+ choices=["openai", "openai-responses", "anthropic", "mcp"],
128
+ default="openai",
129
+ )
130
+ h.add_argument(
131
+ "--toolset",
132
+ type=int,
133
+ choices=sorted(TOOLSETS),
134
+ default=LATEST_TOOLSET,
135
+ help=TOOLSET_HELP,
136
+ )
137
+ h.add_argument(
138
+ "--closed-book",
139
+ action="store_true",
140
+ help="only submit_forecast (no research tools)",
141
+ )
142
+ h.add_argument(
143
+ "--get-question",
144
+ action=argparse.BooleanOptionalAction,
145
+ default=None,
146
+ help="include get_question (default: only for --format mcp)",
147
+ )
148
+
149
+ w = sub.add_parser(
150
+ "serve-http",
151
+ help="HTTP server over the release: every question, JSON in and out",
152
+ )
153
+ w.add_argument("--data", type=Path, required=True, help=DATA_HELP)
154
+ w.add_argument(
155
+ "--host", default="127.0.0.1", help="default 127.0.0.1 (this machine only)"
156
+ )
157
+ w.add_argument(
158
+ "--port", type=int, default=8765, help="default 8765; 0 picks a free port"
159
+ )
160
+ w.add_argument(
161
+ "--token",
162
+ help="require `Authorization: Bearer <token>` (default: $FUTURESEARCH_BTF_TOKEN)",
163
+ )
164
+ w.add_argument("--quiet", action="store_true", help="no per-request log lines")
165
+ w.add_argument(
166
+ "--window-endpoints",
167
+ action="store_true",
168
+ help="also serve POST /v1/search and /v1/read for any research window (trusted callers only)",
169
+ )
170
+
171
+ c = sub.add_parser("score", help="score a run file against the resolutions")
172
+ c.add_argument("--data", type=Path, required=True, help=DATA_HELP)
173
+ c.add_argument("--runs", type=Path, required=True)
174
+ c.add_argument(
175
+ "--json",
176
+ action="store_true",
177
+ help="print the per-question table as JSON instead of the summary",
178
+ )
179
+
180
+ a = ap.parse_args()
181
+ if a.cmd in ("search", "serve") and getattr(a, "question_id", None):
182
+ from .corpus import Release, UnknownQuestion
183
+
184
+ try:
185
+ Release(a.data).question(a.question_id)
186
+ except UnknownQuestion:
187
+ raise SystemExit(
188
+ f"no question {a.question_id!r} in {a.data}; "
189
+ f"`python -m futuresearch_btf questions --data {a.data}` lists them"
190
+ ) from None
191
+ if a.cmd == "questions":
192
+ from .corpus import Release
193
+
194
+ qs = Release(a.data).questions[["question_id", "question_type", "question"]]
195
+ for qid, qtype, text in qs.itertuples(index=False):
196
+ print(f"{qid}\t{qtype}\t{text[:100]}")
197
+ elif a.cmd == "search":
198
+ from .corpus import Release
199
+
200
+ # through call_tool, so the command shows what a model gets from `search` in that toolset
201
+ # (toolset 3 reads site: as a filter); one whole result per line instead of one JSON list
202
+ res = Release(a.data).call_tool(
203
+ a.question_id,
204
+ "search",
205
+ {"query": a.query, "max_results": a.k},
206
+ toolset=a.toolset,
207
+ )
208
+ if res.is_error:
209
+ print(res.text)
210
+ raise SystemExit(1)
211
+ for hit in res.output:
212
+ print(json.dumps(hit, default=str, ensure_ascii=False))
213
+ elif a.cmd == "serve":
214
+ _need("mcp", "mcp")
215
+ from .server import serve
216
+
217
+ serve(a.data, a.question_id, a.out)
218
+ elif a.cmd == "serve-http":
219
+ from .http_server import serve_http
220
+
221
+ serve_http(a.data, a.host, a.port, a.token, a.quiet, a.window_endpoints)
222
+ elif a.cmd == "run":
223
+ _need("litellm", "agent")
224
+ from .agent import run
225
+
226
+ run(
227
+ a.data,
228
+ a.model,
229
+ a.out,
230
+ a.question_ids,
231
+ a.max_turns,
232
+ json.loads(a.llm_kwargs),
233
+ a.closed_book,
234
+ a.transcripts,
235
+ a.toolset,
236
+ a.model_cutoff,
237
+ )
238
+ elif a.cmd == "schemas":
239
+ from .tools import schemas
240
+
241
+ print(
242
+ json.dumps(
243
+ schemas(
244
+ a.format,
245
+ closed_book=a.closed_book,
246
+ get_question=a.get_question,
247
+ toolset=a.toolset,
248
+ ),
249
+ indent=2,
250
+ )
251
+ )
252
+ elif a.cmd == "score":
253
+ from .score import score
254
+
255
+ df = score(a.data, a.runs, echo=not a.json)
256
+ if a.json:
257
+ print(df.to_json(orient="records"))
258
+
259
+
260
+ if __name__ == "__main__":
261
+ main()