Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions agents/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
retrieve_relevant_cases,
compute_memory_influence,
derive_strategy_rationale,
build_strategic_prompt,
build_memory_prompt,
)
from simulation.evaluator import evaluate_candidate_plan

Expand Down Expand Up @@ -910,7 +910,6 @@ def run(self, state: SystemState, event: Event | None = None) -> AgentProposal:
feasible_candidates.append(act)
else:
infeasible_reasons[act.action_id] = vios

if not feasible_candidates and candidate_actions:
feasible_candidates = [
Action(
Expand All @@ -923,23 +922,17 @@ def run(self, state: SystemState, event: Event | None = None) -> AgentProposal:
]
action_limit = _action_limit_for_mode(state, len(feasible_candidates))

effective_event = event or (
state.active_events[-1] if state.active_events else None
)
historical_cases = retrieve_relevant_cases(
effective_event, state.memory, top_k=3
)
effective_event = event or (state.active_events[-1] if state.active_events else None)
historical_cases = retrieve_relevant_cases(effective_event, state.memory, top_k=3)
memory_influence = compute_memory_influence(historical_cases)
strategic_prompt = build_strategic_prompt(
mode=state.mode.value,
event=effective_event,
historical_cases=historical_cases,
candidate_actions=feasible_candidates,
memory_prompt = build_memory_prompt(
mode=state.mode.value, historical_cases=historical_cases
)

before_kpis = state.kpis.model_copy(deep=True)
llm_drafts, planner_error = generate_candidate_plan_drafts(
state=state, event=event, candidate_actions=feasible_candidates
state=state, event=event, candidate_actions=feasible_candidates,
memory_prompt=memory_prompt
)
logger.info(
"planner candidate generation result llm_drafts=%s planner_error=%s feasible_candidates=%s suppress_no_op=%s action_limit=%s",
Expand Down Expand Up @@ -1149,7 +1142,7 @@ def run(self, state: SystemState, event: Event | None = None) -> AgentProposal:
referenced_cases=historical_cases,
memory_influence_score=memory_influence,
strategy_rationale=strategy_rationale,
strategic_prompt=strategic_prompt,
strategic_prompt=memory_prompt
)

winning_factors = build_winning_factors(
Expand Down Expand Up @@ -1198,7 +1191,6 @@ def run(self, state: SystemState, event: Event | None = None) -> AgentProposal:
state.latest_plan_id = final_plan.plan_id
state.pending_plan = final_plan if final_plan.approval_required else None
state.decision_logs.append(decision_log)

proposal.observations.append(
f"built {final_plan.plan_id} using {final_plan.strategy_label} with score {final_plan.score:.4f}"
)
Expand Down
47 changes: 26 additions & 21 deletions app_api/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,28 +592,29 @@ def dispatch_plan(self, plan_id: str, mode: str) -> dict[str, Any]:

if plan is None:
raise_not_found("plan", plan_id)
existing_commit_records = [
ActionExecutionRecord.model_validate(item)
for item in self.store.list_action_execution_records(limit=None)
if item.get("plan_id") == plan_id
and item.get("dispatch_mode") == "commit"
]

if mode == "commit":
existing_records = [
ActionExecutionRecord.model_validate(item)
for item in self.store.list_action_execution_records(limit=None)
if item.get("plan_id") == plan_id
and item.get("dispatch_mode", "dry_run") == mode
]
if existing_records:
existing_records.sort(key=lambda record: record.created_at)
return {
"plan_id": plan_id,
"dispatch_mode": mode,
"plan_execution_status": compute_plan_execution_status(
existing_records
).value,
"overall_progress": compute_overall_progress(existing_records),
"records": [
action_execution_record_view(r) for r in existing_records
],
"compensation_hints": [],
}
if existing_commit_records:
existing_commit_records.sort(key=lambda record: record.created_at)
reported_mode = "dry_run" if mode == "dry_run" else "commit"

return {
"plan_id": plan_id,
"dispatch_mode": reported_mode,
"plan_execution_status": compute_plan_execution_status(
existing_commit_records
).value,
"overall_progress": compute_overall_progress(existing_commit_records),
"records": [
action_execution_record_view(r) for r in existing_commit_records
],
"compensation_hints": [], # Historic records don't have active hints
}

summary = self.dispatch_service.dispatch_plan(plan, mode=mode)

Expand Down Expand Up @@ -1712,3 +1713,7 @@ def build_event_from_envelope(envelope: EventEnvelope) -> Event:
payload=envelope.payload,
dedupe_key=envelope.idempotency_key,
)




Loading
Loading