Benchmark Module
prediction_market_agent_tooling.benchmark
agents
AbstractBenchmarkedAgent
AbstractBenchmarkedAgent(
agent_name: str,
max_workers: Optional[int] = None,
model: str | None = None,
)
Source code in prediction_market_agent_tooling/benchmark/agents.py
15 16 17 18 19 20 21 22 23 | |
model
instance-attribute
model = model
agent_name
instance-attribute
agent_name = agent_name
max_workers
instance-attribute
max_workers = max_workers
is_predictable
is_predictable(market_question: str) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Source code in prediction_market_agent_tooling/benchmark/agents.py
25 26 27 28 29 | |
predict
predict(market_question: str) -> Prediction
Predict the outcome of the market question.
Source code in prediction_market_agent_tooling/benchmark/agents.py
31 32 33 34 35 | |
check_and_predict
check_and_predict(market_question: str) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
37 38 39 40 41 | |
is_predictable_restricted
is_predictable_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Data used for the evaluation must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
43 44 45 46 47 48 49 50 51 52 53 | |
predict_restricted
predict_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> Prediction
Predict the outcome of the market question.
Data used for the prediction must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
55 56 57 58 59 60 61 62 63 64 65 | |
check_and_predict_restricted
check_and_predict_restricted(
market: AgentMarket, time_restriction_up_to: DatetimeUTC
) -> Prediction
Data used must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
RandomAgent
RandomAgent(
agent_name: str,
max_workers: Optional[int] = None,
model: str | None = None,
)
Bases: AbstractBenchmarkedAgent
Source code in prediction_market_agent_tooling/benchmark/agents.py
15 16 17 18 19 20 21 22 23 | |
model
instance-attribute
model = model
agent_name
instance-attribute
agent_name = agent_name
max_workers
instance-attribute
max_workers = max_workers
predict
predict(market_question: str) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
88 89 90 91 92 93 94 95 | |
predict_restricted
predict_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
97 98 99 100 | |
is_predictable
is_predictable(market_question: str) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Source code in prediction_market_agent_tooling/benchmark/agents.py
25 26 27 28 29 | |
check_and_predict
check_and_predict(market_question: str) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
37 38 39 40 41 | |
is_predictable_restricted
is_predictable_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Data used for the evaluation must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
43 44 45 46 47 48 49 50 51 52 53 | |
check_and_predict_restricted
check_and_predict_restricted(
market: AgentMarket, time_restriction_up_to: DatetimeUTC
) -> Prediction
Data used must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
FixedAgent
FixedAgent(
fixed_answer: bool,
agent_name: str,
max_workers: int | None = None,
)
Bases: AbstractBenchmarkedAgent
Source code in prediction_market_agent_tooling/benchmark/agents.py
104 105 106 107 108 | |
fixed_answer
instance-attribute
fixed_answer = fixed_answer
model
instance-attribute
model = model
agent_name
instance-attribute
agent_name = agent_name
max_workers
instance-attribute
max_workers = max_workers
predict
predict(market_question: str) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
110 111 112 113 114 115 116 117 118 119 120 | |
predict_restricted
predict_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
122 123 124 125 | |
is_predictable
is_predictable(market_question: str) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Source code in prediction_market_agent_tooling/benchmark/agents.py
25 26 27 28 29 | |
check_and_predict
check_and_predict(market_question: str) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/agents.py
37 38 39 40 41 | |
is_predictable_restricted
is_predictable_restricted(
market_question: str,
time_restriction_up_to: DatetimeUTC,
) -> bool
Override if the agent can decide to not predict the question, before doing the hard work.
Data used for the evaluation must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
43 44 45 46 47 48 49 50 51 52 53 | |
check_and_predict_restricted
check_and_predict_restricted(
market: AgentMarket, time_restriction_up_to: DatetimeUTC
) -> Prediction
Data used must be restricted to the time_restriction_up_to.
Source code in prediction_market_agent_tooling/benchmark/agents.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
benchmark
Benchmarker
Benchmarker(
markets: Sequence[AgentMarket],
agents: List[AbstractBenchmarkedAgent],
metric_fns: Dict[
str,
Callable[
[list[Prediction], Sequence[AgentMarket]],
str | float | None,
],
] = {},
cache_path: Optional[str] = None,
only_cached: bool = False,
)
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
registered_agents
instance-attribute
registered_agents: List[AbstractBenchmarkedAgent] = agents
cache_path
instance-attribute
cache_path = cache_path
predictions
instance-attribute
predictions = load(path=cache_path)
only_cached
instance-attribute
only_cached = only_cached
markets
instance-attribute
markets: Sequence[AgentMarket] = (
[
m
for m in markets
if all(
has_market(
agent_name=agent_name, question=question
)
for agent in registered_agents
)
]
if only_cached
else markets
)
metric_fns
instance-attribute
metric_fns = metric_fns
add_prediction
add_prediction(
agent: AbstractBenchmarkedAgent,
prediction: Prediction,
market_question: str,
) -> None
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
110 111 112 113 114 115 116 117 118 119 120 | |
get_prediction
get_prediction(
agent_name: str, question: str
) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
122 123 | |
run_agents
run_agents(enable_timing: bool = True) -> None
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
filter_predictions_for_answered
staticmethod
filter_predictions_for_answered(
predictions: list[Prediction],
markets: Sequence[AgentMarket],
) -> t.Tuple[list[Prediction], list[AgentMarket]]
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
179 180 181 182 183 184 185 186 187 188 | |
calculate_errors_between_prediction_and_market
staticmethod
calculate_errors_between_prediction_and_market(
prediction: Prediction, market: AgentMarket
) -> list[float]
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
calculate_squared_errors
staticmethod
calculate_squared_errors(
prediction: Prediction, market: AgentMarket
) -> float
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
222 223 224 225 226 227 228 | |
compute_metrics
compute_metrics() -> t.Dict[str, t.List[t.Any]]
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
get_markets_summary
get_markets_summary() -> t.Dict[str, t.List[str | float]]
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
get_markets_results
get_markets_results() -> dict[str, list[str | float]]
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
generate_markdown_report
generate_markdown_report() -> str
Source code in prediction_market_agent_tooling/benchmark/benchmark.py
448 449 450 451 452 453 454 455 456 457 458 459 | |
utils
AgentPredictions
module-attribute
AgentPredictions = Dict[str, Prediction]
Predictions
module-attribute
Predictions = Dict[str, AgentPredictions]
Prediction
Bases: BaseModel
is_predictable
class-attribute
instance-attribute
is_predictable: bool = True
outcome_prediction
class-attribute
instance-attribute
outcome_prediction: Optional[
CategoricalProbabilisticAnswer
] = None
time
class-attribute
instance-attribute
time: Optional[float] = None
cost
class-attribute
instance-attribute
cost: Optional[float] = None
is_answered
property
is_answered: bool
PredictionsCache
Bases: BaseModel
predictions
instance-attribute
predictions: Predictions
get_prediction
get_prediction(
agent_name: str, question: str
) -> Prediction
Source code in prediction_market_agent_tooling/benchmark/utils.py
38 39 | |
has_market
has_market(agent_name: str, question: str) -> bool
Source code in prediction_market_agent_tooling/benchmark/utils.py
41 42 43 44 | |
add_prediction
add_prediction(
agent_name: str, question: str, prediction: Prediction
) -> None
Source code in prediction_market_agent_tooling/benchmark/utils.py
46 47 48 49 50 51 52 53 54 | |
save
save(path: str) -> None
Source code in prediction_market_agent_tooling/benchmark/utils.py
56 57 58 | |
load
staticmethod
load(path: str) -> PredictionsCache
Source code in prediction_market_agent_tooling/benchmark/utils.py
60 61 62 63 | |
get_most_probable_outcome
get_most_probable_outcome(
probability_map: dict[OutcomeStr, Probability],
) -> OutcomeStr
Returns most probable outcome. If tied, returns first.
Source code in prediction_market_agent_tooling/benchmark/utils.py
12 13 14 15 16 | |
get_llm_api_call_cost
get_llm_api_call_cost(
model: str, prompt_tokens: int, completion_tokens: float
) -> float
In older versions of langchain, the cost calculation doesn't work for newer models. This is a temporary workaround to get the cost.
See: https://github.com/langchain-ai/langchain/issues/12994
Costs are in USD, per 1000 tokens.
Source code in prediction_market_agent_tooling/benchmark/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |