mantisdk 0.1.0__py3-none-any.whl
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.
Potentially problematic release.
This version of mantisdk might be problematic. Click here for more details.
- mantisdk/__init__.py +22 -0
- mantisdk/adapter/__init__.py +15 -0
- mantisdk/adapter/base.py +94 -0
- mantisdk/adapter/messages.py +270 -0
- mantisdk/adapter/triplet.py +1028 -0
- mantisdk/algorithm/__init__.py +39 -0
- mantisdk/algorithm/apo/__init__.py +5 -0
- mantisdk/algorithm/apo/apo.py +889 -0
- mantisdk/algorithm/apo/prompts/apply_edit_variant01.poml +22 -0
- mantisdk/algorithm/apo/prompts/apply_edit_variant02.poml +18 -0
- mantisdk/algorithm/apo/prompts/text_gradient_variant01.poml +18 -0
- mantisdk/algorithm/apo/prompts/text_gradient_variant02.poml +16 -0
- mantisdk/algorithm/apo/prompts/text_gradient_variant03.poml +107 -0
- mantisdk/algorithm/base.py +162 -0
- mantisdk/algorithm/decorator.py +264 -0
- mantisdk/algorithm/fast.py +250 -0
- mantisdk/algorithm/gepa/__init__.py +59 -0
- mantisdk/algorithm/gepa/adapter.py +459 -0
- mantisdk/algorithm/gepa/gepa.py +364 -0
- mantisdk/algorithm/gepa/lib/__init__.py +18 -0
- mantisdk/algorithm/gepa/lib/adapters/README.md +12 -0
- mantisdk/algorithm/gepa/lib/adapters/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/README.md +341 -0
- mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/__init__.py +1 -0
- mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/anymaths_adapter.py +174 -0
- mantisdk/algorithm/gepa/lib/adapters/anymaths_adapter/requirements.txt +1 -0
- mantisdk/algorithm/gepa/lib/adapters/default_adapter/README.md +0 -0
- mantisdk/algorithm/gepa/lib/adapters/default_adapter/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/adapters/default_adapter/default_adapter.py +209 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/README.md +7 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_adapter/dspy_adapter.py +307 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/README.md +99 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/dspy_program_proposal_signature.py +137 -0
- mantisdk/algorithm/gepa/lib/adapters/dspy_full_program_adapter/full_program_adapter.py +266 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/GEPA_RAG.md +621 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/__init__.py +56 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/evaluation_metrics.py +226 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/generic_rag_adapter.py +496 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/rag_pipeline.py +238 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_store_interface.py +212 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/__init__.py +2 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/chroma_store.py +196 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/lancedb_store.py +422 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/milvus_store.py +409 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/qdrant_store.py +368 -0
- mantisdk/algorithm/gepa/lib/adapters/generic_rag_adapter/vector_stores/weaviate_store.py +418 -0
- mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/README.md +552 -0
- mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/__init__.py +37 -0
- mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_adapter.py +705 -0
- mantisdk/algorithm/gepa/lib/adapters/mcp_adapter/mcp_client.py +364 -0
- mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/README.md +9 -0
- mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/adapters/terminal_bench_adapter/terminal_bench_adapter.py +217 -0
- mantisdk/algorithm/gepa/lib/api.py +375 -0
- mantisdk/algorithm/gepa/lib/core/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/core/adapter.py +180 -0
- mantisdk/algorithm/gepa/lib/core/data_loader.py +74 -0
- mantisdk/algorithm/gepa/lib/core/engine.py +356 -0
- mantisdk/algorithm/gepa/lib/core/result.py +233 -0
- mantisdk/algorithm/gepa/lib/core/state.py +636 -0
- mantisdk/algorithm/gepa/lib/examples/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/examples/aime.py +24 -0
- mantisdk/algorithm/gepa/lib/examples/anymaths-bench/eval_default.py +111 -0
- mantisdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/instruction_prompt.txt +9 -0
- mantisdk/algorithm/gepa/lib/examples/anymaths-bench/prompt-templates/optimal_prompt.txt +24 -0
- mantisdk/algorithm/gepa/lib/examples/anymaths-bench/train_anymaths.py +177 -0
- mantisdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/arc_agi.ipynb +25705 -0
- mantisdk/algorithm/gepa/lib/examples/dspy_full_program_evolution/example.ipynb +348 -0
- mantisdk/algorithm/gepa/lib/examples/mcp_adapter/__init__.py +4 -0
- mantisdk/algorithm/gepa/lib/examples/mcp_adapter/mcp_optimization_example.py +455 -0
- mantisdk/algorithm/gepa/lib/examples/rag_adapter/RAG_GUIDE.md +613 -0
- mantisdk/algorithm/gepa/lib/examples/rag_adapter/__init__.py +9 -0
- mantisdk/algorithm/gepa/lib/examples/rag_adapter/rag_optimization.py +824 -0
- mantisdk/algorithm/gepa/lib/examples/rag_adapter/requirements-rag.txt +29 -0
- mantisdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/instruction_prompt.txt +16 -0
- mantisdk/algorithm/gepa/lib/examples/terminal-bench/prompt-templates/terminus.txt +9 -0
- mantisdk/algorithm/gepa/lib/examples/terminal-bench/train_terminus.py +161 -0
- mantisdk/algorithm/gepa/lib/gepa_utils.py +117 -0
- mantisdk/algorithm/gepa/lib/logging/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/logging/experiment_tracker.py +187 -0
- mantisdk/algorithm/gepa/lib/logging/logger.py +75 -0
- mantisdk/algorithm/gepa/lib/logging/utils.py +103 -0
- mantisdk/algorithm/gepa/lib/proposer/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/proposer/base.py +31 -0
- mantisdk/algorithm/gepa/lib/proposer/merge.py +357 -0
- mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/base.py +49 -0
- mantisdk/algorithm/gepa/lib/proposer/reflective_mutation/reflective_mutation.py +176 -0
- mantisdk/algorithm/gepa/lib/py.typed +0 -0
- mantisdk/algorithm/gepa/lib/strategies/__init__.py +0 -0
- mantisdk/algorithm/gepa/lib/strategies/batch_sampler.py +77 -0
- mantisdk/algorithm/gepa/lib/strategies/candidate_selector.py +50 -0
- mantisdk/algorithm/gepa/lib/strategies/component_selector.py +36 -0
- mantisdk/algorithm/gepa/lib/strategies/eval_policy.py +64 -0
- mantisdk/algorithm/gepa/lib/strategies/instruction_proposal.py +127 -0
- mantisdk/algorithm/gepa/lib/utils/__init__.py +10 -0
- mantisdk/algorithm/gepa/lib/utils/stop_condition.py +196 -0
- mantisdk/algorithm/gepa/tracing.py +105 -0
- mantisdk/algorithm/utils.py +177 -0
- mantisdk/algorithm/verl/__init__.py +5 -0
- mantisdk/algorithm/verl/interface.py +202 -0
- mantisdk/cli/__init__.py +56 -0
- mantisdk/cli/prometheus.py +115 -0
- mantisdk/cli/store.py +131 -0
- mantisdk/cli/vllm.py +29 -0
- mantisdk/client.py +408 -0
- mantisdk/config.py +348 -0
- mantisdk/emitter/__init__.py +43 -0
- mantisdk/emitter/annotation.py +370 -0
- mantisdk/emitter/exception.py +54 -0
- mantisdk/emitter/message.py +61 -0
- mantisdk/emitter/object.py +117 -0
- mantisdk/emitter/reward.py +320 -0
- mantisdk/env_var.py +156 -0
- mantisdk/execution/__init__.py +15 -0
- mantisdk/execution/base.py +64 -0
- mantisdk/execution/client_server.py +443 -0
- mantisdk/execution/events.py +69 -0
- mantisdk/execution/inter_process.py +16 -0
- mantisdk/execution/shared_memory.py +282 -0
- mantisdk/instrumentation/__init__.py +119 -0
- mantisdk/instrumentation/agentops.py +314 -0
- mantisdk/instrumentation/agentops_langchain.py +45 -0
- mantisdk/instrumentation/litellm.py +83 -0
- mantisdk/instrumentation/vllm.py +81 -0
- mantisdk/instrumentation/weave.py +500 -0
- mantisdk/litagent/__init__.py +11 -0
- mantisdk/litagent/decorator.py +536 -0
- mantisdk/litagent/litagent.py +252 -0
- mantisdk/llm_proxy.py +1890 -0
- mantisdk/logging.py +370 -0
- mantisdk/reward.py +7 -0
- mantisdk/runner/__init__.py +11 -0
- mantisdk/runner/agent.py +845 -0
- mantisdk/runner/base.py +182 -0
- mantisdk/runner/legacy.py +309 -0
- mantisdk/semconv.py +170 -0
- mantisdk/server.py +401 -0
- mantisdk/store/__init__.py +23 -0
- mantisdk/store/base.py +897 -0
- mantisdk/store/client_server.py +2092 -0
- mantisdk/store/collection/__init__.py +30 -0
- mantisdk/store/collection/base.py +587 -0
- mantisdk/store/collection/memory.py +970 -0
- mantisdk/store/collection/mongo.py +1412 -0
- mantisdk/store/collection_based.py +1823 -0
- mantisdk/store/insight.py +648 -0
- mantisdk/store/listener.py +58 -0
- mantisdk/store/memory.py +396 -0
- mantisdk/store/mongo.py +165 -0
- mantisdk/store/sqlite.py +3 -0
- mantisdk/store/threading.py +357 -0
- mantisdk/store/utils.py +142 -0
- mantisdk/tracer/__init__.py +16 -0
- mantisdk/tracer/agentops.py +242 -0
- mantisdk/tracer/base.py +287 -0
- mantisdk/tracer/dummy.py +106 -0
- mantisdk/tracer/otel.py +555 -0
- mantisdk/tracer/weave.py +677 -0
- mantisdk/trainer/__init__.py +6 -0
- mantisdk/trainer/init_utils.py +263 -0
- mantisdk/trainer/legacy.py +367 -0
- mantisdk/trainer/registry.py +12 -0
- mantisdk/trainer/trainer.py +618 -0
- mantisdk/types/__init__.py +6 -0
- mantisdk/types/core.py +553 -0
- mantisdk/types/resources.py +204 -0
- mantisdk/types/tracer.py +515 -0
- mantisdk/types/tracing.py +218 -0
- mantisdk/utils/__init__.py +1 -0
- mantisdk/utils/id.py +18 -0
- mantisdk/utils/metrics.py +1025 -0
- mantisdk/utils/otel.py +578 -0
- mantisdk/utils/otlp.py +536 -0
- mantisdk/utils/server_launcher.py +1045 -0
- mantisdk/utils/system_snapshot.py +81 -0
- mantisdk/verl/__init__.py +8 -0
- mantisdk/verl/__main__.py +6 -0
- mantisdk/verl/async_server.py +46 -0
- mantisdk/verl/config.yaml +27 -0
- mantisdk/verl/daemon.py +1154 -0
- mantisdk/verl/dataset.py +44 -0
- mantisdk/verl/entrypoint.py +248 -0
- mantisdk/verl/trainer.py +549 -0
- mantisdk-0.1.0.dist-info/METADATA +119 -0
- mantisdk-0.1.0.dist-info/RECORD +190 -0
- mantisdk-0.1.0.dist-info/WHEEL +4 -0
- mantisdk-0.1.0.dist-info/entry_points.txt +2 -0
- mantisdk-0.1.0.dist-info/licenses/LICENSE +19 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""Base abstractions for building agents that plug into Mantisdk."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import inspect
|
|
8
|
+
import logging
|
|
9
|
+
import warnings
|
|
10
|
+
import weakref
|
|
11
|
+
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar
|
|
12
|
+
|
|
13
|
+
from mantisdk.types import NamedResources, Rollout, RolloutRawResult, Task
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from mantisdk.runner import Runner
|
|
17
|
+
from mantisdk.tracer import Tracer
|
|
18
|
+
from mantisdk.trainer import Trainer
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
T = TypeVar("T")
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"LitAgent",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_v0_1_rollout_api(func: Callable[..., Any]) -> bool:
|
|
31
|
+
"""Return `True` when the rollout function uses the deprecated v0.1 signature.
|
|
32
|
+
|
|
33
|
+
The helper inspects the callable's signature to detect whether a `rollout_id`
|
|
34
|
+
parameter is present, which indicates the legacy API.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
func: Function to analyze.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
`True` if the callable exposes a `rollout_id` parameter.
|
|
41
|
+
"""
|
|
42
|
+
return "rollout_id" in inspect.signature(func).parameters
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class LitAgent(Generic[T]):
|
|
46
|
+
"""Base class for implementing agent rollouts.
|
|
47
|
+
|
|
48
|
+
Subclasses override the rollout methods to process tasks while the trainer and
|
|
49
|
+
runner infrastructure manages orchestration, tracing, and persistence.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self, *, trained_agents: Optional[str] = None) -> None: # FIXME: str | None won't work for cli
|
|
53
|
+
"""Initialize the agent instance.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
trained_agents: Optional identifier used by legacy tooling to mark trained
|
|
57
|
+
agents.
|
|
58
|
+
|
|
59
|
+
!!! warning "Deprecated"
|
|
60
|
+
The `trained_agents` flag is deprecated. Configure `agent_match` in the adapter
|
|
61
|
+
layer instead. See [`TracerTraceToTriplet`][mantisdk.TracerTraceToTriplet]
|
|
62
|
+
for more details.
|
|
63
|
+
"""
|
|
64
|
+
if trained_agents is not None:
|
|
65
|
+
warnings.warn(
|
|
66
|
+
"`trained_agents` is deprecated. Configure `agent_match` in adapter instead.",
|
|
67
|
+
DeprecationWarning,
|
|
68
|
+
stacklevel=2,
|
|
69
|
+
)
|
|
70
|
+
self.trained_agents = trained_agents
|
|
71
|
+
|
|
72
|
+
self._trainer_ref: weakref.ReferenceType[Trainer] | None = None
|
|
73
|
+
self._runner_ref: weakref.ReferenceType[Runner[T]] | None = None
|
|
74
|
+
|
|
75
|
+
def is_async(self) -> bool:
|
|
76
|
+
"""Return `True` when the agent overrides any asynchronous rollout methods.
|
|
77
|
+
|
|
78
|
+
Override this method for customized async detection logic.
|
|
79
|
+
"""
|
|
80
|
+
return (
|
|
81
|
+
(
|
|
82
|
+
hasattr(self, "training_rollout_async")
|
|
83
|
+
and self.__class__.training_rollout_async is not LitAgent.training_rollout_async # type: ignore
|
|
84
|
+
)
|
|
85
|
+
or (
|
|
86
|
+
hasattr(self, "validation_rollout_async")
|
|
87
|
+
and self.__class__.validation_rollout_async is not LitAgent.validation_rollout_async # type: ignore
|
|
88
|
+
)
|
|
89
|
+
or (hasattr(self, "rollout_async") and self.__class__.rollout_async is not LitAgent.rollout_async) # type: ignore
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def set_trainer(self, trainer: Trainer) -> None:
|
|
93
|
+
"""Attach the trainer responsible for orchestration.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
trainer: [`Trainer`][mantisdk.Trainer] that manages the agent.
|
|
97
|
+
"""
|
|
98
|
+
self._trainer_ref = weakref.ref(trainer)
|
|
99
|
+
|
|
100
|
+
def get_trainer(self) -> Trainer:
|
|
101
|
+
"""Return the trainer associated with this agent."""
|
|
102
|
+
if self._trainer_ref is None:
|
|
103
|
+
raise ValueError("Trainer has not been set for this agent.")
|
|
104
|
+
trainer = self._trainer_ref()
|
|
105
|
+
if trainer is None:
|
|
106
|
+
raise ValueError("Trainer reference is no longer valid (object has been garbage collected).")
|
|
107
|
+
return trainer
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def trainer(self) -> Trainer:
|
|
111
|
+
"""Return the trainer associated with this agent."""
|
|
112
|
+
return self.get_trainer()
|
|
113
|
+
|
|
114
|
+
def get_tracer(self) -> Tracer:
|
|
115
|
+
"""Return the tracer configured for this agent."""
|
|
116
|
+
if hasattr(self.runner, "tracer"):
|
|
117
|
+
return self.runner.tracer # type: ignore
|
|
118
|
+
else:
|
|
119
|
+
return self.trainer.tracer
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def tracer(self) -> Tracer:
|
|
123
|
+
"""Return the tracer configured for this agent."""
|
|
124
|
+
return self.get_tracer()
|
|
125
|
+
|
|
126
|
+
def set_runner(self, runner: Runner[T]) -> None:
|
|
127
|
+
"""Attach the runner responsible for executing rollouts.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
runner: [`Runner`][mantisdk.Runner] coordinating execution.
|
|
131
|
+
"""
|
|
132
|
+
self._runner_ref = weakref.ref(runner)
|
|
133
|
+
|
|
134
|
+
def get_runner(self) -> Runner[T]:
|
|
135
|
+
"""Return the runner responsible for executing rollouts."""
|
|
136
|
+
if self._runner_ref is None:
|
|
137
|
+
raise ValueError("Runner has not been set for this agent.")
|
|
138
|
+
runner = self._runner_ref()
|
|
139
|
+
if runner is None:
|
|
140
|
+
raise ValueError("Runner reference is no longer valid (object has been garbage collected).")
|
|
141
|
+
return runner
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def runner(self) -> Runner[T]:
|
|
145
|
+
"""Return the runner responsible for executing rollouts."""
|
|
146
|
+
return self.get_runner()
|
|
147
|
+
|
|
148
|
+
def on_rollout_start(self, task: Task, runner: Runner[T], tracer: Tracer) -> None:
|
|
149
|
+
"""Hook invoked immediately before a rollout begins.
|
|
150
|
+
|
|
151
|
+
Subclasses can override this method to implement custom logic such as logging,
|
|
152
|
+
metric collection, or resource setup. The default implementation is a no-op.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
task: [`Task`][mantisdk.Task] that will be processed.
|
|
156
|
+
runner: [`Runner`][mantisdk.Runner] managing the rollout.
|
|
157
|
+
tracer: [`Tracer`][mantisdk.Tracer] associated with the runner.
|
|
158
|
+
|
|
159
|
+
!!! warning "Deprecated"
|
|
160
|
+
Override [`Hook.on_rollout_start`][mantisdk.Hook.on_rollout_start]
|
|
161
|
+
instead of this method when extending agents.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
def on_rollout_end(self, task: Task, rollout: Rollout, runner: Runner[T], tracer: Tracer) -> None:
|
|
165
|
+
"""Hook invoked after a rollout completes.
|
|
166
|
+
|
|
167
|
+
Subclasses can override this method for cleanup or additional logging. The default
|
|
168
|
+
implementation is a no-op.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
task: [`Task`][mantisdk.Task] that was processed.
|
|
172
|
+
rollout: Resulting [`Rollout`][mantisdk.Rollout].
|
|
173
|
+
runner: [`Runner`][mantisdk.Runner] managing the rollout.
|
|
174
|
+
tracer: [`Tracer`][mantisdk.Tracer] associated with the runner.
|
|
175
|
+
|
|
176
|
+
!!! warning "Deprecated"
|
|
177
|
+
Override [`Hook.on_rollout_end`][mantisdk.Hook.on_rollout_end]
|
|
178
|
+
instead of this method when extending agents.
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
def rollout(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
182
|
+
"""Execute a rollout synchronously.
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
If you don't wish to implement both training rollout and validation
|
|
186
|
+
rollout separately, you can just implement `rollout` which will work for both.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
task: Task payload provided by the scheduler.
|
|
190
|
+
resources: Mapping of named resources (for example LLMs or prompt templates).
|
|
191
|
+
rollout: Rollout metadata. Avoid mutating this object directly unless a
|
|
192
|
+
subclass needs to override defaults.
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
One of the following values:
|
|
196
|
+
|
|
197
|
+
* `None` when tracing is handled by the runner.
|
|
198
|
+
* `float` representing the final reward.
|
|
199
|
+
* `List[ReadableSpan]` with OpenTelemetry spans.
|
|
200
|
+
* `List[Span]` with Mantisdk spans.
|
|
201
|
+
* `List[SpanCoreFields]` with Mantisdk spans.
|
|
202
|
+
"""
|
|
203
|
+
raise NotImplementedError("Agents must implement the `rollout` method.")
|
|
204
|
+
|
|
205
|
+
async def rollout_async(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
206
|
+
"""Execute a rollout asynchronously.
|
|
207
|
+
|
|
208
|
+
Args:
|
|
209
|
+
task: Task payload provided by the scheduler.
|
|
210
|
+
resources: Mapping of named resources (for example LLMs or prompt templates).
|
|
211
|
+
rollout: Rollout metadata. Avoid mutating this object directly unless a
|
|
212
|
+
subclass needs to override defaults.
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
Same possible return values as
|
|
216
|
+
[`rollout`][mantisdk.LitAgent.rollout].
|
|
217
|
+
"""
|
|
218
|
+
raise NotImplementedError("Agents must implement the `rollout_async` method for async operations.")
|
|
219
|
+
|
|
220
|
+
def training_rollout(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
221
|
+
"""Process a single training task synchronously.
|
|
222
|
+
|
|
223
|
+
By default, this method delegates to
|
|
224
|
+
[`rollout`][mantisdk.LitAgent.rollout].
|
|
225
|
+
"""
|
|
226
|
+
return self.rollout(task, resources, rollout)
|
|
227
|
+
|
|
228
|
+
def validation_rollout(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
229
|
+
"""Process a single validation task synchronously.
|
|
230
|
+
|
|
231
|
+
Override this method when validation should differ from training. The default
|
|
232
|
+
implementation delegates to
|
|
233
|
+
[`training_rollout`][mantisdk.LitAgent.training_rollout].
|
|
234
|
+
"""
|
|
235
|
+
return self.rollout(task, resources, rollout)
|
|
236
|
+
|
|
237
|
+
async def training_rollout_async(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
238
|
+
"""Process a single training task asynchronously.
|
|
239
|
+
|
|
240
|
+
By default, this method delegates to
|
|
241
|
+
[`rollout_async`][mantisdk.LitAgent.rollout_async].
|
|
242
|
+
"""
|
|
243
|
+
return await self.rollout_async(task, resources, rollout)
|
|
244
|
+
|
|
245
|
+
async def validation_rollout_async(self, task: T, resources: NamedResources, rollout: Rollout) -> RolloutRawResult:
|
|
246
|
+
"""Process a single validation task asynchronously.
|
|
247
|
+
|
|
248
|
+
Override this method when validation should differ from training. The default
|
|
249
|
+
implementation delegates to
|
|
250
|
+
[`training_rollout_async`][mantisdk.LitAgent.training_rollout_async].
|
|
251
|
+
"""
|
|
252
|
+
return await self.rollout_async(task, resources, rollout)
|