microsoft/semantic-kernel · error · ValueError
Resource constraint is not set. Do not try to call this meth
Error message
Resource constraint is not set. Do not try to call this method without a resource constraint.
What it means
Raised by Resources.estimate_remaining_turns when resource_constraint is None. The method can only compute remaining turns if a ResourceConstraint (TIME or TURNS) is set; without one there is no basis for the estimate.
Source
Thrown at python/samples/demos/guided_conversations/guided_conversation/utils/resources.py:180
else (self.elapsed_units * 60) / elapsed_turns
)
time_per_turn /= 60
else:
time_per_turn = (
self.initial_seconds_per_turn if elapsed_turns == 0 else self.elapsed_units / elapsed_turns
)
remaining_turns = self.remaining_units / time_per_turn
# Round down, unless it's less than 1, in which case round up
remaining_turns = math.ceil(remaining_turns) if remaining_turns < 1 else math.floor(remaining_turns)
return remaining_turns
elif self.resource_constraint.unit == ResourceConstraintUnit.TURNS:
return self.resource_constraint.quantity - self.turn_number
else:
self.logger.error(
"Resource constraint is not set, so turns cannot be estimated using function estimate_remaining_turns"
)
raise ValueError(
"Resource constraint is not set. Do not try to call this method without a resource constraint."
)
def get_resource_instructions(self) -> tuple[str, str]:
"""Get the resource instructions for the conversation.
Assumes we're always using turns as the resource unit.
Returns:
str: the resource instructions
"""
if self.resource_constraint is None:
return ""
formatted_elapsed_resource = format_resource(self.elapsed_units, ResourceConstraintUnit.TURNS)
formatted_remaining_resource = format_resource(self.remaining_units, ResourceConstraintUnit.TURNS)
# if the resource quantity is anything other than 1, the resource unit should be plural (e.g. "minutes" instead of "minute")View on GitHub (pinned to c028a0c7dc)
Solutions
- Construct Resources with a non-None resource_constraint (ResourceConstraintUnit.TURNS or .TIME with a quantity).
- Guard the call: if self.resource_constraint is None, skip estimate_remaining_turns.
- Re-attach a resource_constraint before invoking budget-aware logic.
- Use get_resource_instructions to detect the unset state and inform the model.
Example fix
// before resources = Resources() resources.estimate_remaining_turns() // after from .resources import Resources, ResourceConstraint, ResourceConstraintUnit resources = Resources(resource_constraint=ResourceConstraint(unit=ResourceConstraintUnit.TURNS, quantity=10)) resources.estimate_remaining_turns()
Defensive patterns
Strategy: type-guard
Validate before calling
if resources.resource_constraint is None:
raise ValueError('Cannot estimate turns without a resource_constraint')
resources.estimate_remaining_turns() Type guard
from .resources import ResourceConstraint
def has_resource_constraint(resources) -> bool:
return isinstance(resources.resource_constraint, ResourceConstraint) Try / catch
try:
remaining = resources.estimate_remaining_turns()
except ValueError:
remaining = None # unlimited conversation Prevention
- Always construct Resources with a ResourceConstraint for budget-bound conversations.
- Guard estimate_remaining_turns with a None check.
- Document that estimate_remaining_turns requires a constraint.
When it happens
Trigger: Calling estimate_remaining_turns() on a Resources instance constructed without a resource_constraint; the constraint was cleared/reset to None mid-conversation.
Common situations: An open-ended guided conversation with no resource budget; forgetting to pass resource_constraint when building Resources; lifecycle code that nulls the constraint after exhaustion.
Related errors
- " ".join(violations)
- Resource uri is required.
- Field "{filter_one_field}" is not a valid field in the artif
- No properties found in the schema.
- Invalid choice
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/23fbecf1bc114bea.
Report an issue: GitHub.