1"""Data types and prompt templates for the Plan-and-Execute strategy.
2
3Contains the ``PlanStep`` dataclass, ``PlanStepStatus`` enum, and all
4prompt-template constants used across the planning and execution phases.
5"""
6
7from __future__ import annotations
8
9from dataclasses import dataclass
10from enum import StrEnum
11from typing import Any
12
13# ---------------------------------------------------------------------------
14# Data types
15# ---------------------------------------------------------------------------
16
17
18class PlanStepStatus(StrEnum):
19 """Status of a plan step."""
20
21 PENDING = "pending"
22 COMPLETED = "completed"
23 FAILED = "failed"
24 SKIPPED = "skipped"
25
26
27@dataclass
28class PlanStep:
29 """A single step in the agent's plan."""
30
31 number: int
32 """Step number (1-based)."""
33
34 description: str
35 """What this step should accomplish."""
36
37 tool_name: str | None = None
38 """Tool to use (None if this is an LLM reasoning step)."""
39
40 tool_args: dict[str, Any] | None = None
41 """Arguments for the tool call."""
42
43 result: str | None = None
44 """Result after execution."""
45
46 status: PlanStepStatus = PlanStepStatus.PENDING
47 """Status of this step."""
48
49
50# ---------------------------------------------------------------------------
51# Prompt templates
52# ---------------------------------------------------------------------------
53
54PLANNING_PROMPT = """
55You are a Plan-and-Execute agent. You solve complex tasks by creating a plan first,
56then executing each step.
57
58## Phase: PLANNING
59
60Create a numbered plan to accomplish the user's task. Each step should be ONE
61atomic action — either a tool call or a reasoning step.
62
63## Output Format
64
65```
66PLAN:
671. [TOOL:tool_name] Description of what to do with the tool
682. [REASON] Analyze the results from step 1
693. [TOOL:another_tool] Use another tool with the analysis
704. [REASON] Synthesize the final answer
71```
72
73## Rules
74- Prefix tool steps with [TOOL:tool_name] where tool_name matches an available tool.
75- Prefix reasoning steps with [REASON].
76- Keep the plan concise (max {max_steps} steps).
77- Each step should clearly state its purpose.
78
79## Available Tools
80{tool_descriptions}
81"""
82
83EXECUTION_PROMPT = """You are executing step {step_number} of your plan.
84
85## Current Plan
86{plan_text}
87
88## Completed Steps
89{completed_steps}
90
91## Current Step
92Step {step_number}: {step_description}
93
94Execute this step. If it's a tool call, provide:
95ACTION: tool_name
96ACTION_INPUT: {{"arg": "value"}}
97
98If it's a reasoning step, provide your analysis and conclude with:
99STEP_RESULT: <your result for this step>
100"""
101
102REPLAN_PROMPT = """Step {failed_step} failed with error: {error}
103
104## Original Plan
105{plan_text}
106
107## Completed Steps
108{completed_steps}
109
110## Remaining Steps
111{remaining_steps}
112
113Create a revised plan for the remaining steps, accounting for the failure.
114Use the same format:
115PLAN:
1161. [TOOL:tool_name] or [REASON] Description
117"""
118
119SYNTHESIS_PROMPT = """You have completed all steps. Synthesize a final answer.
120
121## Original Task
122{original_task}
123
124## Completed Steps and Results
125{all_results}
126
127Provide a clear, comprehensive final answer based on the results above.
128FINAL_ANSWER: <your synthesized answer>
129"""
130
131
132__all__ = [
133 "EXECUTION_PROMPT",
134 "PLANNING_PROMPT",
135 "REPLAN_PROMPT",
136 "SYNTHESIS_PROMPT",
137 "PlanStep",
138 "PlanStepStatus",
139]