Skip to main content
Glama

Rebalance Territories

territory_rebalance
Destructive

Rebalances an existing alignment after the account data changed, keeping it as close to the current alignment as possible. Needs source_tal_id and the Territory Solution from map_session_id or ts_handle. point_layer defaults to the alignment's build layer or the only point layer; otherwise CLARIFICATION_REQUIRED (ambiguous_point_layer, with details.point_layers). Workload balance needs dwell_time; zero_workload means no account maps to a part. The current alignment is the baseline: when nothing improves the objective the result is NO_IMPROVING_REBALANCE_FOUND and nothing changes. Writes a new derived alignment. Returns a task with retention_pct and solver_diagnostics.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "territory_rebalance"
  }
}

Input Schema

NameRequiredDescriptionDefault
objectiveNo
ts_handleNoTerritory Solution reference (tsh_...) from a build, ingest_accounts, import_geojson, import_designer_project, or get_map_visualization; Territory Solutions are not accepted inline.
dwell_timeNo
part_layerNoPart layer (e.g. us_zips). Required only when not inferable from the source TAL.
point_layerNoOptional point layer used to compute per-part workload/metric measures. When omitted, a uniform geography-only weighting is used.
new_tal_labelNoLabel for the derived TAL. Defaults to '<source label> (<operation>)'.
repair_policyNoTopology repair for dissolved territories. default fills interior holes in the dissolved geometry (no part is added or reassigned; repair_summary.changed_part_ids lists the territories' own parts). report_only detects holes and changes nothing (warning REPAIR_AVAILABLE). strict fails with REPAIR_REQUIRED when a hole is found.default
source_tal_idNoSource TAL. Optional for form-capable clients that can answer via elicitation.
map_session_idNoOpen map session (msess_...) from get_map_visualization. Its Territory Solution is the input; omit ts_handle when set.
balance_toleranceNoAccepted for compatibility. The power-diagram rebalance converges on its own internal tolerance, so this value no longer gates per-part moves.
disruption_weightNoIncumbency stickiness for the warm-started power-diagram rebalance. 0 is a pure power re-solve (max balance, more churn); higher values keep more of the source alignment by requiring a neighbor territory to inflate further before it can claim a border part.
visit_frequency_fieldNoNumeric visits-per-cycle column on the point layer. When omitted, inherits from source TAL build_provenance or point-layer metadata.

Output Schema

NameRequiredDescriptionDefault
okYes
errorNoPresent when ok is false.
resultNoPresent when ok is true. A submission returns the task reference (task_id, next_action, sleep_ms); the completed task result carries the remaining fields.
warningsNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • changedInput schema / properties / objective / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "description": "Balance objective: {metric: '<column>|__account_count__', workload_bias: 0..100, metric_bias: 0..100}. Biases sum to 100. For pure metric balance, pass {metric: '<column>', workload_bias: 0, metric_bias: 100} (or {metric: '<column>'} on restructure tools). When omitted on restructure tools, inherits the source TAL build_provenance objective or seed_build target.",
      -    "properties": {
      -      "metric": {
      -        "description": "Point metric column name to balance (e.g. 'Revenue', 'weekly_volume'), or '__account_count__' for location-count balance.",
      -        "type": "string"
      -      },
      -      "metric_bias": {
      -        "description": "Weight (0..100) on the metric or location-count dimension.",
      -        "maximum": 100,
      -        "minimum": 0,
      -        "type": "integer"
      -      },
      -      "workload_bias": {
      -        "description": "Weight (0..100) on workload (drive time + dwell).",
      -        "maximum": 100,
      -        "minimum": 0,
      -        "type": "integer"
      -      }
      -    },
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Balance objective: workload_bias + metric_bias + count_bias = 100, weighting workload (drive + dwell), one metric column, and account count. Workload: {workload_bias: 100}. Metric: {metric: '<column>', workload_bias: 0, metric_bias: 100}. Count: {workload_bias: 0, count_bias: 100}. Three-way: {metric: 'Score', workload_bias: 40, metric_bias: 40, count_bias: 20}. Only one metric column balances; combine several into one score column at ingest. Omitted on restructure tools: inherits the source TAL build_provenance objective.",
      +    "properties": {
      +      "count_bias": {
      +        "description": "Weight (0..100) on account count (locations per territory). Default 0.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "metric": {
      +        "description": "Point metric column name to balance (e.g. 'Revenue', 'Score'). Required when metric_bias > 0. Account count is count_bias, not a column.",
      +        "type": "string"
      +      },
      +      "metric_bias": {
      +        "description": "Weight (0..100) on the metric column.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "workload_bias": {
      +        "description": "Weight (0..100) on workload (drive time + dwell).",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  2. Changed14 schema fields changed
    • addedInput schema / properties / balance_tolerance / description
      Added value: +"Accepted for compatibility. The power-diagram rebalance converges on its own internal tolerance, so this value no longer gates per-part moves."
    • addedInput schema / properties / disruption_weight / description
      Added value: +"Incumbency stickiness for the warm-started power-diagram rebalance. 0 is a pure power re-solve (max balance, more churn); higher values keep more of the source alignment by requiring a neighbor territory to inflate further before it can claim a border part."
    • addedInput schema / properties / map_session_id / description
      Added value: +"Open map session (msess_...) from get_map_visualization. Its Territory Solution is the input; omit ts_handle when set."
    • addedInput schema / properties / new_tal_label / description
      Added value: +"Label for the derived TAL. Defaults to '<source label> (<operation>)'."
    • addedInput schema / properties / part_layer / description
      Added value: +"Part layer (e.g. us_zips). Required only when not inferable from the source TAL."
    • addedInput schema / properties / point_layer / description
      Added value: +"Optional point layer used to compute per-part workload/metric measures. When omitted, a uniform geography-only weighting is used."
    • addedInput schema / properties / source_tal_id / description
      Added value: +"Source TAL. Optional for form-capable clients that can answer via elicitation."
    • removedInput schema / properties / ts
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "additionalProperties": true,
      -      "type": "object"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Ts"
      -}
    • addedInput schema / properties / ts_handle / description
      Added value: +"Territory Solution reference (tsh_...) from a build, ingest_accounts, import_geojson, import_designer_project, or get_map_visualization; Territory Solutions are not accepted inline."
    • addedInput schema / properties / visit_frequency_field / description
      Added value: +"Numeric visits-per-cycle column on the point layer. When omitted, inherits from source TAL build_provenance or point-layer metadata."
    • removedOutput schema / additionalProperties
      Removed value: -true
    • addedOutput schema / properties
      Added value: +{
      +  "error": {
      +    "description": "Present when ok is false.",
      +    "properties": {
      +      "ask_user": {
      +        "items": {
      +          "type": "string"
      +        },
      +        "type": "array"
      +      },
      +      "code": {
      +        "type": "string"
      +      },
      +      "details": {
      +        "type": "object"
      +      },
      +      "do_this_next": {
      +        "type": "object"
      +      },
      +      "message": {
      +        "type": "string"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  "ok": {
      +    "type": "boolean"
      +  },
      +  "result": {
      +    "description": "Present when ok is true. A submission returns the task reference (task_id, next_action, sleep_ms); the completed task result carries the remaining fields.",
      +    "properties": {
      +      "balance_summary": {
      +        "type": "object"
      +      },
      +      "disruption_summary": {
      +        "type": "object"
      +      },
      +      "do_this_next": {
      +        "type": "object"
      +      },
      +      "expires_at": {
      +        "type": "string"
      +      },
      +      "job_id": {
      +        "type": "string"
      +      },
      +      "next_action": {
      +        "type": "string"
      +      },
      +      "operation": {
      +        "type": "string"
      +      },
      +      "repair_summary": {
      +        "type": "object"
      +      },
      +      "sleep_ms": {
      +        "type": "integer"
      +      },
      +      "solver_diagnostics": {
      +        "type": "object"
      +      },
      +      "source_tal_id": {
      +        "type": "string"
      +      },
      +      "status": {
      +        "type": "string"
      +      },
      +      "tal_id": {
      +        "type": "string"
      +      },
      +      "task_id": {
      +        "type": "string"
      +      },
      +      "terminal": {
      +        "type": "boolean"
      +      },
      +      "territory_count": {
      +        "type": "integer"
      +      },
      +      "ts_handle": {
      +        "type": "string"
      +      },
      +      "ts_identity": {
      +        "type": "object"
      +      },
      +      "ts_omitted": {
      +        "type": "object"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  "warnings": {
      +    "items": {
      +      "properties": {
      +        "code": {
      +          "type": "string"
      +        },
      +        "message": {
      +          "type": "string"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "type": "array"
      +  }
      +}
    • addedOutput schema / required
      Added value: +[
      +  "ok"
      +]
    • removedOutput schema / title
      Removed value: -"territory_rebalanceDictOutput"
  3. Changed1 schema field changed
    • changedInput schema / properties / objective / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Balance objective: {metric: '<column>|__account_count__', workload_bias: 0..100, metric_bias: 0..100}. Biases sum to 100. For pure metric balance, pass {metric: '<column>', workload_bias: 0, metric_bias: 100} (or {metric: '<column>'} on restructure tools). When omitted on restructure tools, inherits the source TAL build_provenance objective or seed_build target.",
      +    "properties": {
      +      "metric": {
      +        "description": "Point metric column name to balance (e.g. 'Revenue', 'weekly_volume'), or '__account_count__' for location-count balance.",
      +        "type": "string"
      +      },
      +      "metric_bias": {
      +        "description": "Weight (0..100) on the metric or location-count dimension.",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      },
      +      "workload_bias": {
      +        "description": "Weight (0..100) on workload (drive time + dwell).",
      +        "maximum": 100,
      +        "minimum": 0,
      +        "type": "integer"
      +      }
      +    },
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  4. Changed1 schema field changed
    • changedInput schema / properties / dwell_time / anyOf
      Previous value: -[
      -  {
      -    "additionalProperties": true,
      -    "type": "object"
      -  },
      -  {
      -    "type": "null"
      -  }
      -]New value: +[
      +  {
      +    "additionalProperties": true,
      +    "description": "Onsite (dwell) time per visit: {type: 'scalar', value: <number>, unit: 'minutes'|'hours'} or {type: 'field', field: '<column>', unit: 'minutes'|'hours'}.",
      +    "properties": {
      +      "field": {
      +        "description": "Point column name holding per-account onsite time when type='field'.",
      +        "minLength": 1,
      +        "type": "string"
      +      },
      +      "type": {
      +        "description": "Dwell source: 'scalar' for a fixed per-visit duration or 'field' for an ingested point column.",
      +        "enum": [
      +          "scalar",
      +          "field"
      +        ],
      +        "type": "string"
      +      },
      +      "unit": {
      +        "default": "minutes",
      +        "description": "Time unit for value or field ('minutes' or 'hours').",
      +        "enum": [
      +          "minutes",
      +          "hours"
      +        ],
      +        "type": "string"
      +      },
      +      "value": {
      +        "description": "Confirmed onsite duration per visit when type='scalar'.",
      +        "minimum": 0,
      +        "type": "number"
      +      }
      +    },
      +    "required": [
      +      "type"
      +    ],
      +    "type": "object"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
  5. Changed1 schema field changed
    • removedInput schema / properties / guidance_handle
      Removed value: -{
      -  "anyOf": [
      -    {
      -      "type": "string"
      -    },
      -    {
      -      "type": "null"
      -    }
      -  ],
      -  "default": null,
      -  "title": "Guidance Handle"
      -}
  6. Changed2 schema fields changed
    • addedInput schema / properties / repair_policy / description
      Added value: +"Topology repair for dissolved territories. default fills interior holes in the dissolved geometry (no part is added or reassigned; repair_summary.changed_part_ids lists the territories' own parts). report_only detects holes and changes nothing (warning REPAIR_AVAILABLE). strict fails with REPAIR_REQUIRED when a hole is found."
    • addedInput schema / properties / repair_policy / enum
      Added value: +[
      +  "default",
      +  "strict",
      +  "report_only"
      +]
  7. First observed

TDQS

A4.2/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond the destructive/readOnly annotations, the description discloses the failure modes that matter: CLARIFICATION_REQUIRED with details.point_layers on ambiguity, NO_IMPROVING_REBALANCE_FOUND with no mutation when the objective does not improve, and zero_workload when no account maps to a part. It also states that a new derived alignment is written and that the return is a task carrying retention_pct and solver_diagnostics, which is exactly the mutation-and-outcome context an agent needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The text is dense but front-loaded, opening with the purpose and then walking through prerequisites, defaults, and terminal outcomes in roughly the order an agent needs them. It is on the long side for a description, but nearly every clause carries operational information rather than restating the schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 12-parameter mutation tool with an output schema, the description covers prerequisite wiring, defaulting rules, and the main non-success codes, so an agent can plan a call without guessing. The residual gap is the point_layer conflict with the schema and the lack of guidance on how source_tal_id and ts_handle interact when both are supplied.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is already 83%, so the baseline is 3, and the description earns the bump by explaining the point_layer fallback chain and the dwell_time dependency on workload balance, neither of which is stated in the schema. One caveat worth flagging: the description says an omitted point_layer falls back to the alignment's build layer, while the schema says a uniform geography-only weighting is used, so an agent must reconcile two different stories.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence gives a specific verb and resource ("Rebalances an existing alignment") plus the governing constraint ("keeping it as close to the current alignment as possible"), which separates it from build-style tools that create an alignment from scratch. It never names a sibling such as territory_merge or territory_split to draw an explicit boundary, so it falls just short of a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states the required inputs up front ("Needs source_tal_id and the Territory Solution from map_session_id or ts_handle") and the conditional that makes dwell_time necessary for workload balance. What is missing is an explicit statement of when to prefer this over alternatives, or when not to call it, though the "after the account data changed" framing implies the trigger condition well.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources