@@ -14,8 +14,8 @@ class CoTReasoning(Reasoning):
1414 - **agent** (LLMAgent reference)
1515
1616 Methods:
17- - **plan(prompt, obs=None , ttl=1, selected_tools=None)** → *Plan* - Generate synchronous plan with CoT reasoning
18- - **async aplan(prompt, obs=None , ttl=1, selected_tools=None)** → *Plan* - Generate asynchronous plan with CoT reasoning
17+ - **plan(obs, ttl=1, prompt=None , selected_tools=None)** → *Plan* - Generate synchronous plan with CoT reasoning
18+ - **async aplan(obs, ttl=1, prompt=None , selected_tools=None)** → *Plan* - Generate asynchronous plan with CoT reasoning
1919
2020 Reasoning Format:
2121 Thought 1: [Initial reasoning based on observation]
@@ -87,9 +87,9 @@ def get_cot_system_prompt(self, obs: Observation) -> str:
8787
8888 def plan (
8989 self ,
90- obs : Observation ,
91- ttl : int = 1 ,
9290 prompt : str | None = None ,
91+ obs : Observation | None = None ,
92+ ttl : int = 1 ,
9393 selected_tools : list [str ] | None = None ,
9494 ) -> Plan :
9595 """
@@ -102,12 +102,17 @@ def plan(
102102 else :
103103 raise ValueError ("No prompt provided and agent.step_prompt is None." )
104104
105+ if obs is None :
106+ obs = self .agent .generate_obs ()
107+
105108 step = obs .step + 1
106109 llm = self .agent .llm
107110 obs_str = str (obs )
108111
109112 # Add current observation to memory (for record)
110- self .agent .memory .add_to_memory (type = "Observation" , content = obs_str )
113+ self .agent .memory .add_to_memory (
114+ type = "Observation" , content = {"content" : obs_str }
115+ )
111116 system_prompt = self .get_cot_system_prompt (obs )
112117
113118 llm .system_prompt = system_prompt
@@ -118,7 +123,9 @@ def plan(
118123 )
119124
120125 chaining_message = rsp .choices [0 ].message .content
121- self .agent .memory .add_to_memory (type = "Plan" , content = chaining_message )
126+ self .agent .memory .add_to_memory (
127+ type = "Plan" , content = {"content" : chaining_message }
128+ )
122129
123130 # Pass plan content to agent for display
124131 if hasattr (self .agent , "_step_display_data" ):
@@ -131,25 +138,41 @@ def plan(
131138 tool_choice = "required" ,
132139 )
133140 response_message = rsp .choices [0 ].message
134- cot_plan = Plan (step = step , llm_plan = response_message , ttl = 1 )
141+ cot_plan = Plan (step = step , llm_plan = response_message , ttl = ttl )
135142
136- self .agent .memory .add_to_memory (type = "Plan-Execution" , content = str (cot_plan ))
143+ self .agent .memory .add_to_memory (
144+ type = "Plan-Execution" , content = {"content" : str (cot_plan )}
145+ )
137146
138147 return cot_plan
139148
140149 async def aplan (
141150 self ,
142- prompt : str ,
143- obs : Observation ,
151+ prompt : str | None = None ,
152+ obs : Observation | None = None ,
144153 ttl : int = 1 ,
145154 selected_tools : list [str ] | None = None ,
146155 ) -> Plan :
147156 """
148157 Asynchronous version of plan() method for parallel planning.
149158 """
159+ # If no prompt is provided, use the agent's default step prompt
160+ if prompt is None :
161+ if self .agent .step_prompt is not None :
162+ prompt = self .agent .step_prompt
163+ else :
164+ raise ValueError ("No prompt provided and agent.step_prompt is None." )
165+
166+ if obs is None :
167+ obs = await self .agent .agenerate_obs ()
168+
150169 step = obs .step + 1
151170 llm = self .agent .llm
152171
172+ obs_str = str (obs )
173+ await self .agent .memory .aadd_to_memory (
174+ type = "Observation" , content = {"content" : obs_str }
175+ )
153176 system_prompt = self .get_cot_system_prompt (obs )
154177 llm .system_prompt = system_prompt
155178
@@ -160,7 +183,9 @@ async def aplan(
160183 )
161184
162185 chaining_message = rsp .choices [0 ].message .content
163- await self .agent .memory .aadd_to_memory (type = "Plan" , content = chaining_message )
186+ await self .agent .memory .aadd_to_memory (
187+ type = "Plan" , content = {"content" : chaining_message }
188+ )
164189
165190 # Pass plan content to agent for display
166191 if hasattr (self .agent , "_step_display_data" ):
@@ -173,10 +198,10 @@ async def aplan(
173198 tool_choice = "required" ,
174199 )
175200 response_message = rsp .choices [0 ].message
176- cot_plan = Plan (step = step , llm_plan = response_message , ttl = 1 )
201+ cot_plan = Plan (step = step , llm_plan = response_message , ttl = ttl )
177202
178203 await self .agent .memory .aadd_to_memory (
179- type = "Plan-Execution" , content = str (cot_plan )
204+ type = "Plan-Execution" , content = { "content" : str (cot_plan )}
180205 )
181206
182207 return cot_plan
0 commit comments