Skip to content

Fix/schedule validation errors - #21

Open
timotheegath wants to merge 14 commits into
umass-aisec:mainfrom
timotheegath:fix/schedule_validation_errors
Open

timotheegath wants to merge 14 commits into
umass-aisec:mainfrom
timotheegath:fix/schedule_validation_errors

Conversation

@timotheegath

Copy link
Copy Markdown
Contributor

Let agents retry schedule_patient without losing a turn when a call is invalid

Current behaviour

Given a normal hospital environment setup

When an agent tries to schedule a patient and:

  1. Targets an unknown/invalid patient ID
  2. Targets a step index beyond the length of th patient's pathway
  3. Does not offer the service needed for that patient at that time step
  4. Skips a step (the patient needs the previous step to be scheduled)
  5. Tries to set a start below the minimum start time
  6. Tries to set a start beyond the time horizon
  7. Already has a fully capacity at time t

Then, the schedule patient tool call fails silently, and the agent loses its turn

Missing resources is intentionally excluded from this list: the step still commits and a −300/item penalty is recorded. It must remain a commit, not an error.


When an agent tries to schedule a patient using a negative patient ID

Then, the schedule patient tool selects the patient by indexing from the end (python-native negative indexing)

Desired behaviour

Failure

Given a normal hospital environment setup

When an agent tries to schedule a patient and:

  1. Targets an unknown/invalid patient ID
  2. Targets a step index beyond the length of th patient's pathway
  3. Does not offer the service needed for that patient at that time step
  4. Skips a step (the patient needs the previous step to be scheduled)
  5. Tries to set a start below the minimum start time
  6. Already has a fully capacity at time t

Then, the agent is notified of the failure and can retry the tool call without losing the turn.

Lack of resources

Given an agent meets all crtieria to schedule a patient, but lacks the resources

When it schedules the patient

Then the tool call does not report a failure to the agent

And a penalty is recorded

Negative indexing

When an agent tries to schedule a patient using a negative patient ID

Then, the agent is notified of the failure and can retry the tool call without losing the turn.

Root cause

HospitalEnvironment._process_schedule_request returns None instead of raising an exception. The caller HospitalTools.execute_action does not consider this a failure due to the lack of exception. The tool call is considered as executed. execute_action already maps exceptions to status: "failed" (non-committing).

Implementation

  • Where condition checks existed, replaced empty returns with verbose ScheduleRequestError exceptions
  • Where condition checks did not exist, created them as well as adding the verbose exception

timotheegath and others added 14 commits November 24, 2026 15:10
The first validation check in HospitalEnvironment._process_schedule_request
silently returned None for an unknown patient_id, so HospitalTools.execute_action
treated the call as executed and the agent lost its turn. Raise the custom
ScheduleRequestError instead; execute_action already maps exceptions to
status "failed" without action_committed, so the agent is notified and can
retry without losing the turn.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Pins the patient_id acceptance criterion of fix/schedule_validation_errors:
_process_schedule_request raises ScheduleRequestError, the tool call returns
status "failed" without action_committed (so BaseAgent keeps the turn), no
state mutates, and a subsequent valid retry commits. Runs without LLM access
via a stub protocol and the real HospitalTools.handle_tool_call entry point.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…tient

An step_index beyond the patient's pathway length silently returned None,
so the tool call looked executed and the agent lost its turn. Also guard
negative indices, which previously passed the >= check and silently indexed
the pathway from the end. Raises before any state mutation.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Pins the step-index acceptance criterion: beyond-pathway and negative
step_index raise ScheduleRequestError, surface as status "failed" without
action_committed, mutate no state, and a valid retry afterwards commits.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
If the calling department does not offer the service the patient needs at
that step, _process_schedule_request silently returned None and the agent
lost its turn. Raise ScheduleRequestError naming both services instead.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Pins the wrong-service acceptance criterion: a department that does not
offer the step's service gets ScheduleRequestError surfaced as status
"failed" without action_committed, no state mutation, and a retry with the
correct department commits.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Scheduling step N without step N-1 already booked silently returned None
and the agent lost its turn. Raise ScheduleRequestError requiring steps to
be scheduled in order.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Pins the skipped-step acceptance criterion: step N before step N-1 raises
ScheduleRequestError, surfaces as status "failed" without action_committed,
mutates no state, and scheduling step 0 first then step N commits.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
A start earlier than the patient's arrival time (or the previous step's end
plus the cross-hospital transfer penalty) silently returned None and the
agent lost its turn. Raise ScheduleRequestError reporting both times.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…ient

Pins the minimum-start acceptance criterion for both sources of the bound:
the patient's arrival time (step 0) and the previous step's end time
(later steps). The rejection surfaces as status "failed" without
action_committed, mutates no state, and a valid retry commits.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
… time t

A booking overlapping a fully-booked time slot silently returned None and
the agent lost its turn. Raise ScheduleRequestError naming the agent, the
capacity and the conflicting time. The max-time-horizon guard above it is
unchanged.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
The validation errors on this branch must not change the deliberate
lack-of-resources behavior: the step still books, the tool reports success
with action_committed, and a -300/item penalty is recorded per missing
resource type.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
A slot reaching t >= max_time_horizon silently returned None and the agent
lost its turn. Raise ScheduleRequestError reporting the horizon violation.
This was the last silent return in _process_schedule_request.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Pins the horizon acceptance criterion: a slot reaching t >= max_time_horizon
- whether by start_time alone or by duration spanning past the horizon -
raises ScheduleRequestError, surfaces as status "failed" without
action_committed, mutates no state, and a retry inside the horizon commits.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant