Skip to main content

State Updater Agent

The State Updater Agent synchronizes local entity states with the NGSI-LD context broker (Stellio).

πŸ“‹ Overview​

PropertyValue
Modulesrc.agents.context_management.state_updater_agent
ClassStateUpdaterAgent
AuthorUIP Team
Version1.0.0

🎯 Purpose​

  • Synchronize entity states with Stellio context broker
  • Batch updates for efficiency
  • Handle conflicts and version management
  • Maintain consistency between local and remote state

πŸš€ Usage​

Update Entity State​

from src.agents.context_management.state_updater_agent import StateUpdaterAgent

updater = StateUpdaterAgent()

# Update single entity
await updater.update(
entity_id="urn:ngsi-ld:TrafficCamera:CAM_001",
attributes={
"status": {"value": "active"},
"vehicleCount": {"value": 42}
}
)

Batch Updates​

# Batch update multiple entities
updates = [
{
"id": "urn:ngsi-ld:TrafficCamera:CAM_001",
"status": {"value": "active"}
},
{
"id": "urn:ngsi-ld:TrafficCamera:CAM_002",
"status": {"value": "offline"}
}
]

result = await updater.batch_update(updates)
print(f"Updated: {result['success']}, Failed: {result['failed']}")

Upsert Pattern​

# Create or update entity
await updater.upsert(
entity={
"id": "urn:ngsi-ld:TrafficCamera:CAM_003",
"type": "TrafficCamera",
"location": {
"type": "GeoProperty",
"value": {"type": "Point", "coordinates": [106.6297, 10.8231]}
}
}
)

βš™οΈ Configuration​

# config/state_updater_config.yaml
state_updater:
enabled: true

# Stellio connection
stellio:
url: "http://localhost:8080"
tenant: "urn:ngsi-ld:tenant:hcmc"

# Batch settings
batch:
size: 100
timeout_seconds: 30
retry_failed: true

# Conflict resolution
conflict:
strategy: "last-write-wins" # last-write-wins, merge, reject
timestamp_field: "modifiedAt"

# Update mode
update:
mode: "patch" # patch, replace
include_observed_at: true

πŸ”„ Update Modes​

ModeDescriptionUse Case
patchUpdate only specified attributesIncremental updates
replaceReplace all attributesFull state sync
appendAdd to multi-valued attributesHistorical data

See the complete agents reference for all available agents.