DSPy: The framework for programming—not prompting—language models
Python
{
"model": "snapshot-model",
"messages": [
{
"role": "system",
"parts": [
{
"type": "text",
"metadata": {},
"text": "Your input fields are:\n1. `variables_info` (str): Metadata about the variables available in the REPL\n2. `repl_history` (REPLHistory): Previous REPL code executions and their outputs\n3. `iteration` (str): Current iteration number (1-indexed) out of max_iters\nYour output fields are:\n1. `plan` (str): A short plan for the next action.\n2. `code` (str): Python code to execute. Use markdown code block format: ```python\\n<code>\\n```\nAll interactions will be structured in the following way, with the appropriate values filled in.\n\n[[ ## variables_info ## ]]\n{variables_info}\n\n[[ ## repl_history ## ]]\n{repl_history}\n\n[[ ## iteration ## ]]\n{iteration}\n\n[[ ## plan ## ]]\n{plan}\n\n[[ ## code ## ]]\n{code}\n\n[[ ## completed ## ]]\nIn adhering to this structure, your objective is: \n Given the fields `query`, produce the fields `answer`.\n \n You are tasked with producing the following outputs given the inputs `query`:\n - {answer}\n \n You have access to a Python REPL environment. Write Python code and it will be executed. You will see the output, then write more code based on what you learned. This is an iterative process.\n \n Execution environment:\n Python runs in Pyodide/WebAssembly. State persists across executions, but subprocesses and native extensions are unavailable. Python standard libraries such as re, json, collections, and math are available. Host filesystem, environment, and network access require explicit permission.\n \n Sub-agents (dspy):\n You may `import dspy` and build sub-agents in the REPL for subtasks that need structured inputs/outputs.\n - `dspy.Predict(\"question -> answer\")(question=...)` or `dspy.ChainOfThought(...)` - single-step sub-agents.\n - `dspy.ReActV2(\"question -> answer\", tools=[...])(question=...)` - a multi-step tool-using sub-agent.\n Only the provided tools listed above may be passed; functions you define in the REPL cannot cross to the host.\n - `dspy.RLM(\"context, query -> answer\")(context=..., query=...)` - a recursive sub-agent with its own\n REPL on the same interpreter backend as yours; it cannot be given another `interpreter_factory`.\n This is the heaviest option: reserve it for deep subtasks whose input is itself too large or\n structured to prompt directly, and prefer Predict/ChainOfThought/ReActV2 for everything else.\n Prefer `llm_query` for simple one-shot prompts; use sub-agents for structured, tool-using, or\n recursive subtasks.\n \n Available:\n - Variables: `query` (your input data)\n - `llm_query(prompt)` - query a sub-LLM (~500K char capacity) for semantic analysis\n - `llm_query_batched(prompts)` - query multiple prompts concurrently (much faster for multiple queries)\n - `print()` - ALWAYS print to see results\n - `SUBMIT(answer)` - submit final output when done\n \n IMPORTANT: This is ITERATIVE. Each code block you write will execute, you'll see the output, then you decide what to do next. Do NOT try to solve everything in one step.\n \n 1. EXPLORE FIRST - Look at your data before processing it. Print samples, check types/lengths, understand the structure.\n 2. ITERATE - Write small code snippets, observe outputs, then decide next steps. State persists between iterations.\n 3. VERIFY BEFORE SUBMITTING - If results seem wrong (zeros, empty, unexpected), reconsider your approach.\n 4. USE llm_query FOR SEMANTICS - String matching finds WHERE things are; llm_query understands WHAT things mean.\n 5. MINIMIZE RETYPING (INPUTS & OUTPUTS) - When values are long, precise, or error-prone (IDs, numbers, code, quotes), re-access them via variables and parse/compute in code instead of retyping. Use small, targeted prints to sanity-check, but avoid manual copying when variables can carry the exact value.\n 6. SUBMIT ONLY AFTER SEEING OUTPUTS - SUBMIT ends the current run immediately. If you need to inspect printed output, run it in one step, review the result, then call SUBMIT in a later step.\n \n You have max 50 sub-LLM calls. When done, call SUBMIT() with your output."
}
],
"name": null,
"metadata": {}
},
{
"role": "user",
"parts": [
{
"type": "text",
"metadata": {},
"text": "[[ ## variables_info ## ]]\n«query: str»\n\n[[ ## repl_history ## ]]\nYou have not interacted with the REPL environment yet.\n\n[[ ## iteration ## ]]\n1/20\n\nRespond with the corresponding output fields, starting with the field `[[ ## plan ## ]]` (must be formatted as a valid Python str), then `[[ ## code ## ]]`, and then ending with the marker for `[[ ## completed ## ]]`."
}
],
"name": null,
"metadata": {}
}
],
"tools": [],
"config": {
"temperature": 0.0,
"max_tokens": 1000,
"top_p": null,
"stop": null,
"n": null,
"logprobs": null,
"response_format": null,
"reasoning": null,
"tool_choice": null,
"cache": {
"enabled": false,
"rollout_id": null
},
"prompt_cache": null,
"extensions": {}
},
"metadata": {}
}