Skip to content

Commit b0c027e

Browse files
committed
fix(ci): ensure tests pass under mock LM by composing final from tool results in JSON loop finalize
1 parent 5237c65 commit b0c027e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

micro_agent/agent.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)