File size: 1,739 Bytes
32030e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Chat messages for single-turn and multi-step tasks (identical for every model)."""

from __future__ import annotations

import json

SYSTEM = ("You are an experienced thermal engineer. Answer from engineering judgement and "
          "first-principles estimates; you cannot run simulations.")


def answer_instruction(output_schema: dict) -> str:
    return ("Finish your reply with a single JSON object with exactly these fields: "
            f"{json.dumps(output_schema)}. Write every interval as [low, high] numbers and every "
            "confidence as a number between 0 and 1.")


def single_turn_messages(task: dict) -> list[dict]:
    return [{"role": "system", "content": SYSTEM},
            {"role": "user", "content": task["prompt"] + "\n\n" + answer_instruction(task["output_schema"])}]


def multi_step_messages(observation: dict) -> list[dict]:
    """``observation`` is ``StoredDataEnv.reset()``: prompt, tools, budget, output_schema."""
    protocol = (
        "You work in turns. To call a tool, reply with only a JSON object "
        '{"tool": "<name>", "args": {...}}; the result comes back in the next message. '
        "Make one tool call per reply and stop there: anything after it is ignored. "
        f"Tools: {json.dumps(observation['tools'])}. Call budget: {json.dumps(observation['budget'])}. "
        'When you are ready, reply with {"tool": "submit", "args": <answer>}, where <answer> has '
        f"exactly these fields: {json.dumps(observation['output_schema'])}. "
        "Write intervals as [low, high] numbers and confidence as a number between 0 and 1.")
    return [{"role": "system", "content": SYSTEM},
            {"role": "user", "content": observation["prompt"] + "\n\n" + protocol}]