math_agent.py
1"""Use the supplied template with one additional tool that runs locally."""23from sim_platform.sdk import AgentContext, Tool, TradingAgent456class PercentageChange(Tool):7 name = 'percentage_change'8 description = 'Calculate percentage change between two positive prices.'9 parameters = {10 'before': {'type': 'number', 'exclusiveMinimum': 0},11 'after': {'type': 'number', 'minimum': 0},12 }1314 def run(self, before: float, after: float) -> float:15 if before <= 0 or after < 0:16 raise ValueError('prices must be nonnegative and before must be positive')17 return (after - before) / before * 100181920def create_agent(context: AgentContext):21 """Return a new instance for this execution; no IO happens during construction."""22 settings = context.settings23 return TradingAgent(24 model=context.model,25 tools=[*context.tools.values(), PercentageChange()],26 instructions=settings['initial_prompt'],27 parameters=settings['parameters'],28 )