m/market labResearch, with a record.
Source on GitHub ↗

conversation.py

1"""Keep the exact system, model and tool messages for one agent execution.23History stays inside the Agent process. A new work round appends its notification;4it does not clear the previous round. No automatic summary or truncation is applied.5"""67from __future__ import annotations89from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set1011from sim_platform.domain.json_values import copy_json, encode1213if TYPE_CHECKING:  # Annotation only.14    from .model import ToolCall15    from .task import Task1617INSTRUCTIONS = (18    'You are running inside a local trading experiment. Use only the provided platform '19    'functions to obtain market or account information and place orders. A work message '20    'announces a round; its times and notifications are not a current price quote. '21    'Registered local tools can perform computation without platform access. '22    'Use tools to read the information you need. You may use several tools or make no '23    'trade. Ordinary text does not end a round. Explicitly call control_finish or '24    'control_wait when finished; call either alone, never in a batch. Keep the original '25    'conversation across rounds. Respect tool errors and do not resend an order merely '26    'because the model or a later query failed. Tool outputs include platform request IDs '27    'and the actual data cutoff; use those values when inspecting results or waiting.'28)293031class Conversation:32    """Build model inputs while retaining every accepted response and matching tool result."""3334    def __init__(self, prompt: str, parameters: Dict[str, Any]) -> None:35        self.items: List[Dict[str, Any]] = [dict(role='system', content=prompt)]36        self.call_ids: Set[str] = set()37        # Optional role name recorded with this conversation's model usage.38        self.label: Optional[str] = None39        if parameters:40            self.items.append(dict(role='user', content='Agent parameters: ' + encode(parameters)))4142    def start_task(self, task: Task) -> None:43        self.items.append(dict(role='user', content='Task: ' + task.instruction))44        if task.notification:45            self.items.append(46                dict(role='user', content='Work started: ' + encode(task.notification))47            )4849    def accept_response(self, output: List[Dict[str, Any]]) -> None:50        """Keep every validated model item unchanged, including reasoning and call IDs."""51        self.items.extend(copy_json(output))52        self.call_ids.update(item['call_id'] for item in output if item['type'] == 'function_call')5354    def tool_result(self, call: ToolCall, result: Any) -> None:55        self.items.append(56            dict(type='function_call_output', call_id=call.call_id, output=encode(result))57        )5859    def continue_work(self) -> None:60        self.items.append(61            dict(62                role='user',63                content='This work round is still active. Use a tool, control_finish or control_wait.',64            )65        )