Skip to content

Urgency Analysis

Custom urgency_levels (level names), response_times (one time per level), and customer_tiers (tier names) determine the allowed categorical values in the returned schema. For example:

from openaivec.task.customer_support import urgency_analysis

task = urgency_analysis(
    urgency_levels={"urgent": "Service outage", "routine": "General inquiry"},
    response_times={"urgent": "within_15_minutes", "routine": "within_2_days"},
    customer_tiers={"vip": "Priority account", "free": "Free plan"},
)
# task.response_format accepts "urgent", "within_15_minutes", and "vip".

All three choice sets must be nonempty, and response_times must have exactly the same level keys as urgency_levels. With no custom choices, the original UrgencyAnalysis model and defaults remain unchanged.

openaivec.task.customer_support.urgency_analysis

Customer inquiry urgency-analysis task definition.

Classes

UrgencyAnalysis

Bases: BaseModel

Urgency analysis output.

Functions:

urgency_analysis

urgency_analysis(
    urgency_levels: Mapping[str, str] | None = None,
    response_times: Mapping[str, str] | None = None,
    customer_tiers: Mapping[str, str] | None = None,
    escalation_rules: Mapping[str, str] | None = None,
    urgency_keywords: Mapping[str, list[str]] | None = None,
    business_context: str = "general customer support",
    business_hours: str = "24/7 support",
    sla_rules: Mapping[str, str] | None = None,
) -> PreparedTask[UrgencyAnalysis]

Create an urgency task with schema choices matching configured prompt options.

Parameters:

Name Type Description Default
urgency_levels Mapping[str, str] | None

Level names and descriptions.

None
response_times Mapping[str, str] | None

Level-to-response-time choices.

None
customer_tiers Mapping[str, str] | None

Tier names and descriptions.

None
escalation_rules Mapping[str, str] | None

Escalation guidance.

None
urgency_keywords Mapping[str, list[str]] | None

Keywords per level.

None
business_context str

Customer-support context.

'general customer support'
business_hours str

Operating hours.

'24/7 support'
sla_rules Mapping[str, str] | None

SLA guidance by tier.

None

Returns:

Type Description
PreparedTask[UrgencyAnalysis]

PreparedTask[UrgencyAnalysis]: Configured task and response schema.

Raises:

Type Description
ValueError

If a choice set is empty or response-time levels do not match urgency levels.

Source code in src/openaivec/task/customer_support/urgency_analysis.py
def urgency_analysis(
    urgency_levels: Mapping[str, str] | None = None,
    response_times: Mapping[str, str] | None = None,
    customer_tiers: Mapping[str, str] | None = None,
    escalation_rules: Mapping[str, str] | None = None,
    urgency_keywords: Mapping[str, list[str]] | None = None,
    business_context: str = "general customer support",
    business_hours: str = "24/7 support",
    sla_rules: Mapping[str, str] | None = None,
) -> PreparedTask[UrgencyAnalysis]:
    """Create an urgency task with schema choices matching configured prompt options.

    Args:
        urgency_levels (Mapping[str, str] | None): Level names and descriptions.
        response_times (Mapping[str, str] | None): Level-to-response-time choices.
        customer_tiers (Mapping[str, str] | None): Tier names and descriptions.
        escalation_rules (Mapping[str, str] | None): Escalation guidance.
        urgency_keywords (Mapping[str, list[str]] | None): Keywords per level.
        business_context (str): Customer-support context.
        business_hours (str): Operating hours.
        sla_rules (Mapping[str, str] | None): SLA guidance by tier.

    Returns:
        PreparedTask[UrgencyAnalysis]: Configured task and response schema.

    Raises:
        ValueError: If a choice set is empty or response-time levels do not match urgency levels.
    """
    resolved_urgency_levels = dict(_default_urgency_levels() if urgency_levels is None else urgency_levels)
    resolved_response_times = dict(_default_response_times() if response_times is None else response_times)
    resolved_customer_tiers = dict(_default_customer_tiers() if customer_tiers is None else customer_tiers)
    levels = _choices("urgency_levels", resolved_urgency_levels)
    _choices("response_times", resolved_response_times)
    tiers = _choices("customer_tiers", resolved_customer_tiers)
    if set(resolved_response_times) != set(levels):
        raise ValueError("response_times must define exactly the configured urgency_levels")
    times = tuple(dict.fromkeys(resolved_response_times.values()))
    if any(not isinstance(value, str) or not value.strip() for value in times):
        raise ValueError("response_times must contain nonempty response-time values")
    default_escalation_rules = {
        key: value
        for key, value in _default_escalation_rules().items()
        if key not in _default_response_times().values() or key in times
    }
    resolved_escalation_rules = dict(default_escalation_rules if escalation_rules is None else escalation_rules)
    default_keywords = {key: value for key, value in _default_urgency_keywords().items() if key in levels}
    resolved_urgency_keywords = dict(default_keywords if urgency_keywords is None else urgency_keywords)
    default_sla_rules = {key: value for key, value in _default_sla_rules().items() if key in tiers}
    resolved_sla_rules = dict(default_sla_rules if sla_rules is None else sla_rules)
    response_format = UrgencyAnalysis
    if urgency_levels is not None or response_times is not None or customer_tiers is not None:
        response_format = create_model(
            "ConfiguredUrgencyAnalysis",
            __base__=UrgencyAnalysis,
            __module__=__name__,
            urgency_level=(getattr(Literal, "__getitem__")(levels), Field(description="Urgency level")),
            response_time=(getattr(Literal, "__getitem__")(times), Field(description="Recommended response time")),
            customer_tier=(getattr(Literal, "__getitem__")(tiers), Field(description="Inferred customer tier")),
        )
    return PreparedTask(
        instructions=_build_instructions(
            urgency_levels=resolved_urgency_levels,
            response_times=resolved_response_times,
            customer_tiers=resolved_customer_tiers,
            escalation_rules=resolved_escalation_rules,
            urgency_keywords=resolved_urgency_keywords,
            business_context=business_context,
            business_hours=business_hours,
            sla_rules=resolved_sla_rules,
        ),
        response_format=response_format,
    )