File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -382,7 +382,18 @@ def _accumulate_usage(input_text: str = "", output_text: str = ""):
382382 if must_time and not used_tool (state , "now" ):
383383 state .append ({"tool" : "⛔️policy_violation" , "args" : {}, "observation" : "Finalize attempted before now." })
384384 continue
385- p = dspy .Prediction (answer = decision ["final" ]["answer" ], trace = state )
385+ # Prefer composing from tool results when available to ensure answers include key values.
386+ calculators = [s for s in state if s .get ("tool" ) == "calculator" and isinstance (s .get ("observation" ), dict )]
387+ nows = [s for s in state if s .get ("tool" ) == "now" and isinstance (s .get ("observation" ), dict )]
388+ composed_parts = []
389+ if calculators :
390+ composed_parts .append (str (calculators [0 ]["observation" ].get ("result" )))
391+ if nows :
392+ iso = nows [- 1 ]["observation" ].get ("iso" )
393+ if iso :
394+ composed_parts .append (f"UTC: { iso } " )
395+ final_text = " | " .join (composed_parts ) if composed_parts else decision ["final" ].get ("answer" , "" )
396+ p = dspy .Prediction (answer = final_text , trace = state )
386397 p .usage = {
387398 "lm_calls" : lm_calls ,
388399 "tool_calls" : tool_calls ,
You can’t perform that action at this time.
0 commit comments